From 26114d976796236761db63a682051b98d683147c Mon Sep 17 00:00:00 2001 From: Tom Wallroth Date: Mon, 30 Dec 2024 16:07:23 +0100 Subject: [PATCH 1/4] 0.11: Add options for natural scroll and disabling wrap-around --- apps/promenu/ChangeLog | 1 + apps/promenu/bootb2.js | 13 +++++++++++-- apps/promenu/bootb2.ts | 18 ++++++++++++++++-- apps/promenu/metadata.json | 5 +++-- apps/promenu/settings.js | 30 ++++++++++++++++++++++++++++++ apps/promenu/settings.ts | 33 +++++++++++++++++++++++++++++++++ 6 files changed, 94 insertions(+), 6 deletions(-) create mode 100644 apps/promenu/settings.js create mode 100644 apps/promenu/settings.ts diff --git a/apps/promenu/ChangeLog b/apps/promenu/ChangeLog index 83140c994e..bbcab00f68 100644 --- a/apps/promenu/ChangeLog +++ b/apps/promenu/ChangeLog @@ -12,3 +12,4 @@ 0.08: Fix bug with modifying menu - allows hadash to save scroll positions 0.09: Don't show "..." if a string isn't truncated (i.e. scrolled) 0.10: Trigger `remove` callbacks when ending the menu +0.11: Add options for natural scroll and disabling wrap-around diff --git a/apps/promenu/bootb2.js b/apps/promenu/bootb2.js index 1090229d20..71692dd33f 100644 --- a/apps/promenu/bootb2.js +++ b/apps/promenu/bootb2.js @@ -1,3 +1,7 @@ +var _a, _b; +var settings = (require("Storage").readJSON("promenu.settings.json", true) || {}); +(_a = settings.naturalScroll) !== null && _a !== void 0 ? _a : (settings.naturalScroll = false); +(_b = settings.wrapAround) !== null && _b !== void 0 ? _b : (settings.wrapAround = true); E.showMenu = function (items) { var RectRnd = function (x1, y1, x2, y2, r) { var pp = []; @@ -164,7 +168,12 @@ E.showMenu = function (items) { } else { var lastSelected = selected; - selected = (selected + dir + menuItems.length) % menuItems.length; + if (settings.wrapAround) { + selected = (selected + dir + menuItems.length) % menuItems.length; + } + else { + selected = E.clip(selected + dir, 0, menuItems.length - 1); + } scroller.scroll = selected; l.draw(Math.min(lastSelected, selected), Math.max(lastSelected, selected)); } @@ -201,7 +210,7 @@ E.showMenu = function (items) { }, }, function (dir) { if (dir) - l.move(dir); + l.move(settings.naturalScroll ? -dir : dir); else l.select(); }); diff --git a/apps/promenu/bootb2.ts b/apps/promenu/bootb2.ts index c284ad88b9..c448397d30 100644 --- a/apps/promenu/bootb2.ts +++ b/apps/promenu/bootb2.ts @@ -1,9 +1,19 @@ type ActualMenuItem = Exclude; +type PromenuSettings = { + naturalScroll: boolean, + wrapAround: boolean, +}; + const enum Consts { NAME_SCROLL_PAD = 5, } +const settings = (require("Storage").readJSON("promenu.settings.json", true) || {}) as PromenuSettings; +settings.naturalScroll ??= false; +settings.wrapAround ??= true; + + E.showMenu = (items?: Menu): MenuInstance => { const RectRnd = (x1: number, y1: number, x2: number, y2: number, r: number) => { const pp = []; @@ -207,7 +217,11 @@ E.showMenu = (items?: Menu): MenuInstance => { } else { const lastSelected = selected; - selected = (selected + dir + /*keep +ve*/menuItems.length) % menuItems.length; + if (settings.wrapAround) { + selected = (selected + dir + /*keep +ve*/menuItems.length) % menuItems.length; + } else { + selected = E.clip(selected + dir, 0, menuItems.length - 1); + } scroller.scroll = selected; l.draw(Math.min(lastSelected, selected), Math.max(lastSelected, selected)); } @@ -244,7 +258,7 @@ E.showMenu = (items?: Menu): MenuInstance => { }, } as SetUIArg<"updown">, dir => { - if (dir) l.move(dir); + if (dir) l.move(settings.naturalScroll ? -dir : dir); else l.select(); }); diff --git a/apps/promenu/metadata.json b/apps/promenu/metadata.json index 87d9610456..b3a68d792e 100644 --- a/apps/promenu/metadata.json +++ b/apps/promenu/metadata.json @@ -1,7 +1,7 @@ { "id": "promenu", "name": "Pro Menu", - "version": "0.10", + "version": "0.11", "description": "Replace the built in menu function. Supports Bangle.js 1 and Bangle.js 2.", "icon": "icon.png", "type": "bootloader", @@ -12,6 +12,7 @@ "storage": [ {"name":"promenu.boot.js","url":"boot.js","supports": ["BANGLEJS"]}, {"name":"promenu.boot.js","url":"bootb2.js","supports": ["BANGLEJS2"]}, - {"name":"promenu.img","url":"promenuIcon.js","evaluate":true} + {"name":"promenu.img","url":"promenuIcon.js","evaluate":true}, + {"name":"promenu.settings.js","url":"settings.js"} ] } diff --git a/apps/promenu/settings.js b/apps/promenu/settings.js new file mode 100644 index 0000000000..cba4928f87 --- /dev/null +++ b/apps/promenu/settings.js @@ -0,0 +1,30 @@ +(function (back) { + var _a, _b; + var SETTINGS_FILE = "promenu.settings.json"; + var storage = require("Storage"); + var settings = (storage.readJSON(SETTINGS_FILE, true) || {}); + (_a = settings.naturalScroll) !== null && _a !== void 0 ? _a : (settings.naturalScroll = false); + (_b = settings.wrapAround) !== null && _b !== void 0 ? _b : (settings.wrapAround = true); + var save = function () { + storage.writeJSON(SETTINGS_FILE, settings); + }; + var menu = { + "": { "title": "Promenu" }, + "< Back": back, + "Natural Scroll": { + value: !!settings.naturalScroll, + onchange: function (v) { + settings.naturalScroll = v; + save(); + } + }, + "Wrap Around": { + value: !!settings.wrapAround, + onchange: function (v) { + settings.wrapAround = v; + save(); + } + } + }; + E.showMenu(menu); +}); diff --git a/apps/promenu/settings.ts b/apps/promenu/settings.ts new file mode 100644 index 0000000000..b4a7df0a6d --- /dev/null +++ b/apps/promenu/settings.ts @@ -0,0 +1,33 @@ +(back => { + const SETTINGS_FILE = "promenu.settings.json"; + + const storage = require("Storage") + const settings = (storage.readJSON(SETTINGS_FILE, true) || {}) as PromenuSettings; + settings.naturalScroll ??= false; + settings.wrapAround ??= true; + + const save = () => { + storage.writeJSON(SETTINGS_FILE, settings); + }; + + const menu: Menu = { + "": { "title": "Promenu" }, + "< Back": back, + /*LANG*/"Natural Scroll": { + value: !!settings.naturalScroll, + onchange: (v: boolean) => { + settings.naturalScroll = v; + save(); + } + }, + /*LANG*/"Wrap Around": { + value: !!settings.wrapAround, + onchange: (v: boolean) => { + settings.wrapAround = v; + save(); + } + } + }; + + E.showMenu(menu); +}) satisfies SettingsFunc From 8e5453bc5689558fdfd2020c6482b3fbb951d25a Mon Sep 17 00:00:00 2001 From: Tom Wallroth Date: Mon, 30 Dec 2024 16:23:41 +0100 Subject: [PATCH 2/4] fixed promenu-0.11 metadata.json --- apps/promenu/metadata.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/promenu/metadata.json b/apps/promenu/metadata.json index b3a68d792e..efa33f0a23 100644 --- a/apps/promenu/metadata.json +++ b/apps/promenu/metadata.json @@ -14,5 +14,6 @@ {"name":"promenu.boot.js","url":"bootb2.js","supports": ["BANGLEJS2"]}, {"name":"promenu.img","url":"promenuIcon.js","evaluate":true}, {"name":"promenu.settings.js","url":"settings.js"} - ] + ], + "data": [{"name":"promenu.settings.json"}] } From 15ece50d53b7b0d5dada94643dc2dac45242cc59 Mon Sep 17 00:00:00 2001 From: Tom Wallroth Date: Mon, 30 Dec 2024 16:28:56 +0100 Subject: [PATCH 3/4] add exception for sanity check of promenu.settings.{js,ts} --- bin/sanitycheck.js | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/sanitycheck.js b/bin/sanitycheck.js index afca569a03..27a0a2bdd2 100755 --- a/bin/sanitycheck.js +++ b/bin/sanitycheck.js @@ -184,6 +184,7 @@ var KNOWN_WARNINGS = [ "App pongclock file pongclock.settings.js should be evaluated as a function but doesn't end in ')'", "App popconlaunch file popcon.settings.js should be evaluated as a function but doesn't end in ')'", "App poweroff file poweroff.settings.js should be evaluated as a function but doesn't end in ')'", + "App promenu file promenu.settings.js should be evaluated as a function but doesn't end in ')'", "App puzzle15 file puzzle15.settings.js should be evaluated as a function but doesn't end in ')'", "App qcenter file qcenter.settings.js should be evaluated as a function but doesn't end in ')'", "App rebbleagenda file rebbleagenda.settings.js should be evaluated as a function but doesn't end in ')'", From d166c4224a64d39e4d35f0606ad39ce9f6d0cce2 Mon Sep 17 00:00:00 2001 From: Tom Wallroth Date: Thu, 2 Jan 2025 10:22:06 +0100 Subject: [PATCH 4/4] remove sanitycheck exception, by builing using `typescript/build.sh` --- apps/promenu/settings.js | 2 +- bin/sanitycheck.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/promenu/settings.js b/apps/promenu/settings.js index cba4928f87..4d25e1335b 100644 --- a/apps/promenu/settings.js +++ b/apps/promenu/settings.js @@ -27,4 +27,4 @@ } }; E.showMenu(menu); -}); +}) diff --git a/bin/sanitycheck.js b/bin/sanitycheck.js index 27a0a2bdd2..afca569a03 100755 --- a/bin/sanitycheck.js +++ b/bin/sanitycheck.js @@ -184,7 +184,6 @@ var KNOWN_WARNINGS = [ "App pongclock file pongclock.settings.js should be evaluated as a function but doesn't end in ')'", "App popconlaunch file popcon.settings.js should be evaluated as a function but doesn't end in ')'", "App poweroff file poweroff.settings.js should be evaluated as a function but doesn't end in ')'", - "App promenu file promenu.settings.js should be evaluated as a function but doesn't end in ')'", "App puzzle15 file puzzle15.settings.js should be evaluated as a function but doesn't end in ')'", "App qcenter file qcenter.settings.js should be evaluated as a function but doesn't end in ')'", "App rebbleagenda file rebbleagenda.settings.js should be evaluated as a function but doesn't end in ')'",