First test with display name and json file

pull/1995/head
David Peer 2022-06-24 08:59:51 +02:00
parent d5557ee508
commit e87d6aa26c
2 changed files with 17 additions and 15 deletions

View File

@ -10,14 +10,15 @@ var icon = {
}; };
// Try to read custom actions, otherwise use default // Try to read custom actions, otherwise use default
var actions = [ var triggers = [
"No Actions", {display: "Not found.", trigger: "NOP", icon: null},
]; ];
try{ try{
actions = storage.read("ha.trigger.txt").split(","); triggers = storage.read("ha.trigger.json");
triggers = JSON.parse(triggers);
} catch(e) { } catch(e) {
// In case there are no user actions yet, we show the default... // In case there are no user triggers yet, we show the default...
} }
@ -26,8 +27,8 @@ function draw() {
var h = 22; var h = 22;
g.setFont("Vector", h); g.setFont("Vector", h);
var action = actions[position]; var trigger = triggers[position];
var w = g.stringWidth(action); var w = g.stringWidth(trigger.display);
g.setFontAlign(-1,-1); g.setFontAlign(-1,-1);
g.setColor(g.theme.fg).drawImage(icon, 12, H/5-2); g.setColor(g.theme.fg).drawImage(icon, 12, H/5-2);
@ -38,7 +39,7 @@ function draw() {
var ypos = H/5*3+20; var ypos = H/5*3+20;
g.drawRect(W/2-w/2-8, ypos-h/2-8, W/2+w/2+5, ypos+h/2+5); g.drawRect(W/2-w/2-8, ypos-h/2-8, W/2+w/2+5, ypos+h/2+5);
g.fillRect(W/2-w/2-6, ypos-h/2-6, W/2+w/2+3, ypos+h/2+3); g.fillRect(W/2-w/2-6, ypos-h/2-6, W/2+w/2+3, ypos+h/2+3);
g.setColor(g.theme.bg).drawString(action, W/2, ypos); g.setColor(g.theme.bg).drawString(trigger.display, W/2, ypos);
} }
@ -51,13 +52,13 @@ Bangle.on('touch', function(btn, e){
if(isRight){ if(isRight){
Bangle.buzz(40, 0.6); Bangle.buzz(40, 0.6);
position += 1; position += 1;
position = position >= actions.length ? 0 : position; position = position >= triggers.length ? 0 : position;
} }
if(isLeft){ if(isLeft){
Bangle.buzz(40, 0.6); Bangle.buzz(40, 0.6);
position -= 1; position -= 1;
position = position < 0 ? actions.length-1 : position; position = position < 0 ? triggers.length-1 : position;
} }
if(!isRight && !isLeft){ if(!isRight && !isLeft){
@ -66,7 +67,7 @@ Bangle.on('touch', function(btn, e){
t:"intent", t:"intent",
action:"com.espruino.gadgetbridge.banglejs.HA", action:"com.espruino.gadgetbridge.banglejs.HA",
extra:{ extra:{
trigger: actions[position] trigger: triggers[position].trigger
}}) }})
); );
setTimeout(()=>{ setTimeout(()=>{

View File

@ -3,8 +3,9 @@
<link rel="stylesheet" href="../../css/spectre.min.css"> <link rel="stylesheet" href="../../css/spectre.min.css">
</head> </head>
<body> <body>
triggers
<p>Trigger - seperate list with ',': <input type="text" id="subjects" class="form-input" value=""></p> <p>Json file [{display: "Text", trigger: "TRIGGER_1", icon: null}, ...]</p>
<p><textarea id="triggers"></textarea></p>
<p><button id="upload" class="btn btn-primary">Upload</button></p> <p><button id="upload" class="btn btn-primary">Upload</button></p>
<script src="../../core/lib/customize.js"></script> <script src="../../core/lib/customize.js"></script>
@ -13,17 +14,17 @@
// When the 'upload' button is clicked... // When the 'upload' button is clicked...
document.getElementById("upload").addEventListener("click", function() { document.getElementById("upload").addEventListener("click", function() {
// get the text to add // get the text to add
var text = document.getElementById("subjects").value; var text = document.getElementById("triggers").value;
console.log(text); console.log(text);
// build the app's text using a templated String // build the app's text using a templated String
var app = text; var app = text;
// send finished app (in addition to contents of app.json) // send finished app (in addition to contents of app.json)
sendCustomizedApp({ sendCustomizedApp({
storage:[ storage:[
{name:"ha.trigger.txt", url:"ha.trigger.txt", content:app}, {name:"ha.trigger.json", url:"ha.trigger.json", content:app},
] ]
}); });
console.log("Sent ha.trigger.txt!"); console.log("Sent ha.trigger.json!");
}); });
</script> </script>