diff --git a/README.md b/README.md index 20ae8afb2..8e186cf79 100644 --- a/README.md +++ b/README.md @@ -384,14 +384,18 @@ Example `settings.js` ```js // make sure to enclose the function in parentheses (function(back) { - function get(key, def) { return require('Settings').get('myappid', key, def); } - function set(key, value) { require('Settings').set('myappid', key, value); } + let settings = require('Storage').readJSON('myappid.json',1)||{}; + if (typeof settings.monkeys !== "number") settings.monkeys = 12; // default value + function save(key, value) { + settings[key] = value; + require('Storage').write('myappid.json', settings); + } const appMenu = { '': {'title': 'App Settings'}, '< Back': back, 'Monkeys': { - value: get('monkeys', 12), - onchange: (m) => set('monkeys', m) + value: settings.monkeys, + onchange: (m) => {save('monkeys', m)} } }; E.showMenu(appMenu) diff --git a/apps.json b/apps.json index 40cd5df65..877218135 100644 --- a/apps.json +++ b/apps.json @@ -87,7 +87,7 @@ "id": "health", "name": "Health Tracking", "version": "0.08", - "description": "Logs health data and provides an app to view it (BETA - requires firmware 2v11)", + "description": "Logs health data and provides an app to view it (requires firmware 2v10.100 or later)", "icon": "app.png", "tags": "tool,system,health", "supports": ["BANGLEJS","BANGLEJS2"], @@ -104,7 +104,7 @@ "id": "launch", "name": "Launcher", "shortName": "Launcher", - "version": "0.08", + "version": "0.09", "description": "This is needed to display a menu allowing you to choose your own applications. You can replace this with a customised launcher.", "icon": "app.png", "type": "launch", @@ -4150,7 +4150,7 @@ "id": "waveclk", "name": "Wave Clock", "version": "0.02", - "description": "A clock using a wave image by [Lillith May](https://www.instagram.com/_lilustrations_/). **Note: This requires firmware 2v11 or later Bangle.js 1**", + "description": "A clock using a wave image by [Lillith May](https://www.instagram.com/_lilustrations_/). **Note: Works on any Bangle.js 2, but requires firmware 2v11 or later on Bangle.js 1**", "icon": "app.png", "screenshots": [{"url":"screenshot.png"}], "type": "clock", @@ -4166,7 +4166,7 @@ "id": "floralclk", "name": "Floral Clock", "version": "0.01", - "description": "A clock with a flower background by [Lillith May](https://www.instagram.com/_lilustrations_/). **Note: This requires firmware 2v11 or later Bangle.js 1**", + "description": "A clock with a flower background by [Lillith May](https://www.instagram.com/_lilustrations_/). **Note: Works on any Bangle.js 2 but requires firmware 2v11 or later on Bangle.js 1**", "icon": "app.png", "screenshots": [{"url":"screenshot_floral.png"}], "type": "clock", @@ -4310,7 +4310,7 @@ "name": "Q Alarm and Timer", "shortName": "Q Alarm", "icon": "app.png", - "version": "0.02", + "version": "0.03", "description": "Alarm and timer app with days of week and 'hard' option.", "tags": "tool,alarm,widget", "supports": ["BANGLEJS", "BANGLEJS2"], @@ -4535,7 +4535,7 @@ "description": "Simple app to power off your Bangle.js", "icon": "app.png", "tags": "poweroff, shutdown", - "supports" : ["BANGLEJS", "BANGLEJS2"], + "supports" : ["BANGLEJS", "BANGLEJS2"], "readme": "README.md", "storage": [ {"name":"poweroff.app.js","url":"app.js"}, @@ -4628,7 +4628,7 @@ "id": "pebble", "name": "Pebble Clock", "shortName": "Pebble", - "version": "0.01", + "version": "0.02", "description": "A pebble style clock to keep the rebellion going", "readme": "README.md", "icon": "pebble.png", @@ -4638,6 +4638,7 @@ "supports": ["BANGLEJS2"], "storage": [ {"name":"pebble.app.js","url":"pebble.app.js"}, + {"name":"pebble.settings.js","url":"pebble.settings.js"}, {"name":"pebble.img","url":"pebble.icon.js","evaluate":true} ] } diff --git a/apps/launch/ChangeLog b/apps/launch/ChangeLog index bd8a9bd03..3b9dbc30c 100644 --- a/apps/launch/ChangeLog +++ b/apps/launch/ChangeLog @@ -6,3 +6,5 @@ 0.06: Use Bangle.setUI for buttons 0.07: Theme colours fix 0.08: Merge Bangle.js 1 and 2 launchers +0.09: Bangle.js 2 - pressing the button goes back to clock (fix #971) + After 10s of being locked, the launcher goes back to the clock screen diff --git a/apps/launch/app-bangle1.js b/apps/launch/app-bangle1.js index 3d4682e55..f779f5de4 100644 --- a/apps/launch/app-bangle1.js +++ b/apps/launch/app-bangle1.js @@ -64,3 +64,12 @@ Bangle.setUI("updown",dir=>{ }); Bangle.loadWidgets(); Bangle.drawWidgets(); +// 10s of inactivity goes back to clock +if (Bangle.setLocked) Bangle.setLocked(false); // unlock initially +var lockTimeout; +Bangle.on('lock', locked => { + if (lockTimeout) clearTimeout(lockTimeout); + lockTimeout = undefined; + if (locked) + lockTimeout = setTimeout(_=>load(), 10000); +}); diff --git a/apps/launch/app-bangle2.js b/apps/launch/app-bangle2.js index 8b66247c5..9a7aa81ed 100644 --- a/apps/launch/app-bangle2.js +++ b/apps/launch/app-bangle2.js @@ -46,3 +46,16 @@ E.showScroller({ } } }); + +// pressing button goes back +setWatch(_=>load(), BTN1, {edge:"falling"}); + +// 10s of inactivity goes back to clock +Bangle.setLocked(false); // unlock initially +var lockTimeout; +Bangle.on('lock', locked => { + if (lockTimeout) clearTimeout(lockTimeout); + lockTimeout = undefined; + if (locked) + lockTimeout = setTimeout(_=>load(), 10000); +}); diff --git a/apps/pebble/ChangeLog b/apps/pebble/ChangeLog index 9db0e26c5..d352d98b6 100644 --- a/apps/pebble/ChangeLog +++ b/apps/pebble/ChangeLog @@ -1 +1,2 @@ 0.01: first release +0.02: included deployment of pebble.settings.js in apps.json diff --git a/apps/pebble/README.md b/apps/pebble/README.md index f0de5ce73..4b0233781 100644 --- a/apps/pebble/README.md +++ b/apps/pebble/README.md @@ -3,7 +3,7 @@ *a Pebble style clock with configurable background color, to keep the revolution going* * Designed specifically for Bangle 2 -* A choice of 6 different background colous through its setting menu +* A choice of 6 different background colous through its setting menu. Goto Settings, App/Widget settings, Pebble. * Supports the Light and Dark themes * Uses pedometer widget to get latest step count * Dependant apps are installed when Pebble installs diff --git a/apps/qalarm/ChangeLog b/apps/qalarm/ChangeLog index 135e69d23..fb6c751bb 100644 --- a/apps/qalarm/ChangeLog +++ b/apps/qalarm/ChangeLog @@ -1,2 +1,5 @@ 0.01: First version! -0.02: Fixed alarms not working and localised days of week. \ No newline at end of file +0.02: Fixed alarms not working and localised days of week. +0.03: Fix unfreed memory, and clearInterval that disabled all clocks at midnight + Fix app icon + Change menu order so 'back' is at the top diff --git a/apps/qalarm/app-icon.js b/apps/qalarm/app-icon.js index 1a014b796..12d2c103f 100644 --- a/apps/qalarm/app-icon.js +++ b/apps/qalarm/app-icon.js @@ -1 +1 @@ -require("heatshrink").decompress(atob("/wA/AH4A/AH4AF0WiF1wwtF73GB53MAAgkY4wABFqIxPEhQuXGB4vUFxYwMEpBpGBwouNGAwfFF5I1KF6ZQHGAwNLFx4wHF/4v/F/4v/AoYGDF6gaFF5AwHL7QuMBJQvWEpwvxBQ4uRGBAkJT4wuWGBIuIRjKRNF8wwXFy4wWFzIwU53NFzPN5wuR5/PGK4tBDYSNQ5wVCCwIzBAAQoIAAQWGSJ5HFDYYAQIYTCRKRIeBAAYmDAAZsJMCQAbeCAybFiQ0XFTQAIzgAGFcYvz0QAGF84wGF1AwFF1QA/AH4A/ADQ=")) +require("heatshrink").decompress(atob("mEw4UA///gH+93+oH9Jf8AgfABZMP+ALRmADCitUAgUMAQP8AQMBqtVoAFBn4CBDwUFBYNQFAQLEioLBEgQLBgfwE4IKBAAI3BBYXAE4ILE/gJBAIM8HQQ8CngL/n4LFKYR3BhgLFNYSDCBYqPFBZKzBUwSoDWYTLBUwSoDZYQABBQa0DBZCoBAAY6EcojhEHgoACkoLFrALD1WVBQdW1QLDtQMDBQOpHQmqAAg8DIwQKEJAg6FMApfLDIoJFAAX//4KIBbE/aAIAIh7oBAH4A==")) diff --git a/apps/qalarm/app.js b/apps/qalarm/app.js index 64f601bf6..ad071adf0 100644 --- a/apps/qalarm/app.js +++ b/apps/qalarm/app.js @@ -41,6 +41,7 @@ function getCurrentTime() { function showMainMenu() { const menu = { "": { title: "Alarms" }, + "< Back" : () => load(), "New Alarm": () => showEditAlarmMenu(-1), "New Timer": () => showEditTimerMenu(-1), }; @@ -54,9 +55,7 @@ function showMainMenu() { else showEditAlarmMenu(idx); }; }); - menu["< Back"] = () => { - load(); - }; + menu if (WIDGETS["qalarm"]) WIDGETS["qalarm"].reload(); return E.showMenu(menu); @@ -86,6 +85,7 @@ function showEditAlarmMenu(alarmIndex, alarm) { const menu = { "": { title: alarm.msg ? alarm.msg : "Alarms" }, + "< Back" : showMainMenu, Hours: { value: hrs, onchange: function (v) { @@ -162,7 +162,6 @@ function showEditAlarmMenu(alarmIndex, alarm) { showMainMenu(); }; } - menu["< Back"] = showMainMenu; return E.showMenu(menu); } @@ -206,6 +205,7 @@ function showEditTimerMenu(timerIndex) { const menu = { "": { title: "Timer" }, + "< Back" : showMainMenu, Hours: { value: hrs, onchange: function (v) { @@ -264,7 +264,7 @@ function showEditTimerMenu(timerIndex) { showMainMenu(); }; } - menu["< Back"] = showMainMenu; + return E.showMenu(menu); } diff --git a/apps/qalarm/boot.js b/apps/qalarm/boot.js index 6713ad9e1..5e9560ee2 100644 --- a/apps/qalarm/boot.js +++ b/apps/qalarm/boot.js @@ -1 +1 @@ -eval(require("Storage").read("qalarmcheck.js")); +(function() { eval(require("Storage").read("qalarmcheck.js")); })() diff --git a/apps/qalarm/qalarmcheck.js b/apps/qalarm/qalarmcheck.js index 9a3f10d5e..8dac43800 100644 --- a/apps/qalarm/qalarmcheck.js +++ b/apps/qalarm/qalarmcheck.js @@ -4,7 +4,10 @@ print("Checking for alarms..."); -clearInterval(); +if (Bangle.QALARM) { + clearInterval(Bangle.QALARM); + Bangle.QALARM = undefined; +} function getCurrentTime() { let time = new Date(); @@ -29,13 +32,13 @@ let nextAlarms = (require("Storage").readJSON("qalarm.json", 1) || []) .sort((a, b) => a.t - b.t); if (nextAlarms[0]) { - setTimeout(() => { + Bangle.QALARM = setTimeout(() => { eval(require("Storage").read("qalarmcheck.js")); load("qalarm.js"); }, nextAlarms[0].t - t); } else { // No alarms found: will re-check at midnight - setTimeout(() => { + Bangle.QALARM = setTimeout(() => { eval(require("Storage").read("qalarmcheck.js")); }, 86400000 - t); } diff --git a/core b/core index 50aa45f13..cd3b4def8 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 50aa45f13f06cc2f40684971d4c0a68d061b1f3c +Subproject commit cd3b4def869cac4d7f18e7329e640e51b26758c8 diff --git a/modules/Settings.js b/modules/Settings.js deleted file mode 100644 index 0828b4655..000000000 --- a/modules/Settings.js +++ /dev/null @@ -1,101 +0,0 @@ -/* -- Read/write app settings, stored in .json -- Read/write global settings (stored in setting.json) - -Usage: -``` -// read a single app setting -value = require('Settings').get(appid, key, default); -// omit key to read all app settings -value = require('Settings').get(appid); -// write a single app setting -require('Settings').set(appid, key, value) -// omit key and pass an object as values to overwrite all settings -require('Settings').set(appid, values) - -// read Bangle settings by passing the Bangle object instead of an app name -value = require('Settings').get(Bangle, key, default); -// read all global settings -values = require('Settings').get(Bangle); -// write a global setting -require('Settings').set(Bangle, key, value) -``` - -For example: -``` -require('Settings').set('test', 'foo', 123); // writes to 'test.json' -require('Settings').set('test', 'bar', 456); // updates 'test.json' -// 'test.json' now contains {baz:123,bam:456} -baz = require('Settings').get('test', 'foo'); // baz = 123 -def = require('Settings').get('test', 'jkl', 789); // def = 789 -all = require('Settings').get('test'); // all = {foo: 123, bar: 456} -baz = require('Settings').get('test', 'baz'); // baz = undefined - -// read global setting -vibrate = require('Settings').get(Bangle, 'vibrate', true); - -// Hint: if your app reads multiple settings, you can create a helper function: -function s(key, def) { return require('Settings').get('myapp', key, def); } -var foo = s('foo setting', 'default value'), bar = s('bar setting'); -``` - -*/ - -/** - * Read setting value from file - * - * @param {string} file Settings file - * @param {string} key Setting to get, omit to get all settings as object - * @param {*} def Default value - * @return {*} Setting value (or default if not found) - */ -function get(file, key, def) { - var s = require("Storage").readJSON(file); - if (def===undefined && ["object", "undefined"].includes(typeof key)) { - // get(file) or get(file, def): get all settings - return (s!==undefined) ? s : key; - } - return ((typeof s==="object") && (key in s)) ? s[key] : def; -} - -/** - * Write setting value to file - * - * @param {string} file Settings file - * @param {string} key Setting to change, omit to replace all settings - * @param {*} value Value to store - */ -function set(file, key, value) { - if (value===undefined && typeof key==="object") { - // set(file, value): overwrite settings completely - require("Storage").writeJSON(file, key); - return; - } - var s = require("Storage").readJSON(file, 1); - if (typeof s!=="object") s = {}; - s[key] = value; - require("Storage").write(file, s); -} - -/** - * Read setting value - * - * @param {string|object} app App name or Bangle - * @param {string} key Setting to get, omit to get all settings as object - * @param {*} def Default value - * @return {*} Setting value (or default if not found) - */ -exports.get = function(app, key, def) { - return get((app===Bangle) ? 'setting.json' : app+".json", key, def); -}; - -/** - * Write setting value - * - * @param {string|object} app App name or Bangle - * @param {string} key Setting to change, omit to replace all settings - * @param {*} val Value to store - */ -exports.set = function(app, key, val) { - set((app===Bangle) ? 'setting.json' : app+".json", key, val); -};