mirror of https://github.com/espruino/BangleApps
First test with display name and json file
parent
d5557ee508
commit
e87d6aa26c
|
@ -10,14 +10,15 @@ var icon = {
|
|||
};
|
||||
|
||||
// Try to read custom actions, otherwise use default
|
||||
var actions = [
|
||||
"No Actions",
|
||||
var triggers = [
|
||||
{display: "Not found.", trigger: "NOP", icon: null},
|
||||
];
|
||||
|
||||
try{
|
||||
actions = storage.read("ha.trigger.txt").split(",");
|
||||
triggers = storage.read("ha.trigger.json");
|
||||
triggers = JSON.parse(triggers);
|
||||
} 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;
|
||||
g.setFont("Vector", h);
|
||||
var action = actions[position];
|
||||
var w = g.stringWidth(action);
|
||||
var trigger = triggers[position];
|
||||
var w = g.stringWidth(trigger.display);
|
||||
|
||||
g.setFontAlign(-1,-1);
|
||||
g.setColor(g.theme.fg).drawImage(icon, 12, H/5-2);
|
||||
|
@ -38,7 +39,7 @@ function draw() {
|
|||
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.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){
|
||||
Bangle.buzz(40, 0.6);
|
||||
position += 1;
|
||||
position = position >= actions.length ? 0 : position;
|
||||
position = position >= triggers.length ? 0 : position;
|
||||
}
|
||||
|
||||
if(isLeft){
|
||||
Bangle.buzz(40, 0.6);
|
||||
position -= 1;
|
||||
position = position < 0 ? actions.length-1 : position;
|
||||
position = position < 0 ? triggers.length-1 : position;
|
||||
}
|
||||
|
||||
if(!isRight && !isLeft){
|
||||
|
@ -66,7 +67,7 @@ Bangle.on('touch', function(btn, e){
|
|||
t:"intent",
|
||||
action:"com.espruino.gadgetbridge.banglejs.HA",
|
||||
extra:{
|
||||
trigger: actions[position]
|
||||
trigger: triggers[position].trigger
|
||||
}})
|
||||
);
|
||||
setTimeout(()=>{
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
<link rel="stylesheet" href="../../css/spectre.min.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Trigger - seperate list with ',': <input type="text" id="subjects" class="form-input" value=""></p>
|
||||
triggers
|
||||
<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>
|
||||
|
||||
<script src="../../core/lib/customize.js"></script>
|
||||
|
@ -13,17 +14,17 @@
|
|||
// When the 'upload' button is clicked...
|
||||
document.getElementById("upload").addEventListener("click", function() {
|
||||
// get the text to add
|
||||
var text = document.getElementById("subjects").value;
|
||||
var text = document.getElementById("triggers").value;
|
||||
console.log(text);
|
||||
// build the app's text using a templated String
|
||||
var app = text;
|
||||
// send finished app (in addition to contents of app.json)
|
||||
sendCustomizedApp({
|
||||
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>
|
||||
|
|
Loading…
Reference in New Issue