diff --git a/apps/torch/ChangeLog b/apps/torch/ChangeLog index 8e76b717a..de1bcd265 100644 --- a/apps/torch/ChangeLog +++ b/apps/torch/ChangeLog @@ -1,2 +1,3 @@ 0.01: New App! 0.02: Change start sequence to BTN1/3/1/3 to avoid accidental turning on (fix #342) +0.03: Add Color Changing Settings diff --git a/apps/torch/app.js b/apps/torch/app.js index 28aa00bd6..9504f3ac0 100644 --- a/apps/torch/app.js +++ b/apps/torch/app.js @@ -1,6 +1,16 @@ +const SETTINGS_FILE = "torch.json"; +let settings; + +function loadSettings() { + settings = require("Storage").readJSON(SETTINGS_FILE,1)|| {'bg': '#FFFFFF', 'color': 'White'}; +} + +loadSettings(); + Bangle.setLCDPower(1); Bangle.setLCDTimeout(0); g.reset(); +g.setColor(settings.bg); g.fillRect(0,0,g.getWidth(),g.getHeight()); // Any button turns off setWatch(()=>load(), BTN1); diff --git a/apps/torch/metadata.json b/apps/torch/metadata.json index 39655dbba..1f64e1e82 100644 --- a/apps/torch/metadata.json +++ b/apps/torch/metadata.json @@ -2,14 +2,15 @@ "id": "torch", "name": "Torch", "shortName": "Torch", - "version": "0.02", - "description": "Turns screen white to help you see in the dark. Select from the launcher or press BTN1,BTN3,BTN1,BTN3 quickly to start when in any app that shows widgets", + "version": "0.03", + "description": "Turns screen white to help you see in the dark. Select from the launcher or press BTN1,BTN3,BTN1,BTN3 quickly to start when in any app that shows widgets. You can also set the color through the apps settings menu.", "icon": "app.png", "tags": "tool,torch", "supports": ["BANGLEJS"], "storage": [ {"name":"torch.app.js","url":"app.js"}, {"name":"torch.wid.js","url":"widget.js"}, - {"name":"torch.img","url":"app-icon.js","evaluate":true} + {"name":"torch.img","url":"app-icon.js","evaluate":true}, + {"name":"torch.settings.js","url":"settings.js"} ] } diff --git a/apps/torch/settings.js b/apps/torch/settings.js new file mode 100644 index 000000000..8dd6d1854 --- /dev/null +++ b/apps/torch/settings.js @@ -0,0 +1,38 @@ +(function(back) { + const SETTINGS_FILE = "torch.json"; + + // initialize with default settings... + let s = {'bg': '#FFFFFF', 'color': 'White'} + + // ...and overwrite them with any saved values + // This way saved values are preserved if a new version adds more settings + const storage = require('Storage') + let settings = storage.readJSON(SETTINGS_FILE, 1) || s; + const saved = settings || {} + for (const key in saved) { + s[key] = saved[key] + } + + function save() { + settings = s + storage.write(SETTINGS_FILE, settings) + } + + var color_options = ['Green','Orange','Cyan','Purple','Red','Blue','Yellow','White']; + var bg_code = ['#0f0','#FFA500','#0ff','#f0f','#f00','#00f','#ffef00','#FFFFFF']; + + E.showMenu({ + '': { 'title': 'Torch' }, + '< Back': back, + 'Colour': { + value: 0 | color_options.indexOf(s.color), + min: 0, max: 7, + format: v => color_options[v], + onchange: v => { + s.color = color_options[v]; + s.bg = bg_code[v]; + save(); + }, + } + }); +})