-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[qmsched] Add day-specific scheduling #4201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
40c9532
a19c1d7
10ed589
e2ae66c
22cc6fe
ecfefb1
ee1d136
30ee7cc
cc0c68c
7cc4692
c0ac522
ded2299
9b9fe52
0295fff
3b1b352
dc694fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,15 @@ let bSettings = STORAGE.readJSON('setting.json',true)||{}; | |||||||||
| let current = 0|bSettings.quiet; | ||||||||||
| delete bSettings; // we don't need any other global settings | ||||||||||
|
|
||||||||||
| const allDays = 0b1111111; // bits 0–6 = Sun, Mon, Tue, Wed, Thu, Fri, Sat | ||||||||||
| const dayNames = ["Su","Mo","Tu","We","Th","Fr","Sa"]; | ||||||||||
|
|
||||||||||
| function formatDays(mask) { | ||||||||||
| if (!mask || mask === allDays) return "Every day"; | ||||||||||
| if (mask === 0b0111110) return "Mon-Fri"; | ||||||||||
| if (mask === 0b1000001) return "Weekends"; | ||||||||||
| return dayNames.filter((_, i) => mask & (1 << i)).join(","); | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
||||||||||
|
|
||||||||||
|
|
@@ -49,6 +58,7 @@ function loadSettings() { | |||||||||
| scheds: settings, | ||||||||||
| }; | ||||||||||
| // store new format | ||||||||||
|
|
||||||||||
| save(); | ||||||||||
| // and clean up qmOptions from global settings file | ||||||||||
| delete bOptions.qmOptions; | ||||||||||
|
|
@@ -101,7 +111,6 @@ function applyTheme() { | |||||||||
| */ | ||||||||||
| function showThemeMenu(back, quiet){ | ||||||||||
| const option = quiet ? "quietTheme" : "normalTheme"; | ||||||||||
| function cl(x) { return g.setColor(x).getColor(); } | ||||||||||
| var themesMenu = { | ||||||||||
| '':{title:/*LANG*/'Theme', back: back}, | ||||||||||
| /*LANG*/'Default': ()=>{ | ||||||||||
|
|
@@ -126,6 +135,7 @@ function showThemeMenu(back, quiet){ | |||||||||
| * Library uses this to make the app update itself | ||||||||||
| * @param {int} mode New Quite Mode | ||||||||||
| */ | ||||||||||
| //eslint-disable-next-line no-unused-vars | ||||||||||
| function setAppQuietMode(mode) { | ||||||||||
| if (mode === current) return; | ||||||||||
| current = mode; | ||||||||||
|
|
@@ -146,69 +156,80 @@ function showMainMenu() { | |||||||||
| }; | ||||||||||
| scheds.sort((a, b) => (a.hr-b.hr)); | ||||||||||
| scheds.forEach((sched, idx) => { | ||||||||||
| menu[formatTime(sched.hr)] = () => { showEditMenu(idx); }; | ||||||||||
| menu[formatTime(sched.hr)].format = () => modeNames[sched.mode]+' >'; // this does nothing :-( | ||||||||||
| const label = formatTime(sched.hr) + " " + formatDays(sched.days ?? allDays); | ||||||||||
| menu[label] = () => { showEditMenu(idx); }; | ||||||||||
| }); | ||||||||||
| menu[/*LANG*/"Add Schedule"] = () => showEditMenu(-1); | ||||||||||
| menu[/*LANG*/"Switch Theme"] = { | ||||||||||
| value: !!get("switchTheme"), | ||||||||||
| onchange: v => v ? set("switchTheme", v) : unset("switchTheme"), | ||||||||||
| }; | ||||||||||
| menu[/*LANG*/"Options"] = () => showOptionsMenu(); | ||||||||||
|
|
||||||||||
| m = E.showMenu(menu); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| } | ||||||||||
| function showDaysMenu(mask, onDone) { | ||||||||||
| let cur = mask; | ||||||||||
| let menu = {"": {title: "Active Days"}}; | ||||||||||
| menu["< Back"] = () => onDone(cur); | ||||||||||
|
RKBoss6 marked this conversation as resolved.
|
||||||||||
| dayNames.forEach((name, i) => { | ||||||||||
| menu[name] = { | ||||||||||
| value: !!(cur & (1 << i)), | ||||||||||
| onchange: v => { | ||||||||||
| if (v) cur |= (1 << i); | ||||||||||
| else cur &= ~(1 << i); | ||||||||||
| }, | ||||||||||
| }; | ||||||||||
| }); | ||||||||||
| E.showMenu(menu); | ||||||||||
| } | ||||||||||
| function showEditMenu(index) { | ||||||||||
| const isNew = index<0; | ||||||||||
| let hrs = 12, mins = 0; | ||||||||||
| let mode = 1; | ||||||||||
| let days = allDays; | ||||||||||
| if (!isNew) { | ||||||||||
| const s = scheds[index]; | ||||||||||
| hrs = 0|s.hr; | ||||||||||
| mins = Math.round((s.hr-hrs)*60); | ||||||||||
| mode = s.mode; | ||||||||||
| days = ("days" in s) ? s.days : allDays; | ||||||||||
|
||||||||||
| days = ("days" in s) ? s.days : allDays; | |
| let loadedDays = ("days" in s) ? s.days : allDays; | |
| days = loadedDays || allDays; |
Copilot
AI
Mar 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In showEditMenu, the new title/back strings ("Add Schedule", "Edit Schedule", "< Cancel") are user-facing but no longer have /*LANG*/ markers. Please restore translation markers for these labels.
| let menu = {"": {"title": (isNew ? "Add Schedule" : "Edit Schedule")}}; | |
| menu[B2 ? "< Back" : "< Cancel"] = () => showMainMenu(); | |
| let menu = {"": {"title": (isNew ? /*LANG*/"Add Schedule" : /*LANG*/"Edit Schedule")}}; | |
| menu[B2 ? "< Back" : /*LANG*/"< Cancel"] = () => showMainMenu(); |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,27 +1,33 @@ | ||||||||||
| // apply Quiet Mode schedules | ||||||||||
| (function qm() { | ||||||||||
| if (Bangle.qmTimeout) clearTimeout(Bangle.qmTimeout); // so the app can eval() this file to apply changes right away | ||||||||||
| if (Bangle.qmTimeout) clearTimeout(Bangle.qmTimeout); | ||||||||||
| delete Bangle.qmTimeout; | ||||||||||
| let bSettings = require('Storage').readJSON('setting.json',true)||{}; | ||||||||||
| const curr = 0|bSettings.quiet; | ||||||||||
| delete bSettings; | ||||||||||
| if (curr) require("qmsched").applyOptions(curr); // no need to re-apply default options | ||||||||||
|
|
||||||||||
| if (curr) require("qmsched").applyOptions(curr); | ||||||||||
| let settings = require('Storage').readJSON('qmsched.json',true)||{}; | ||||||||||
| let scheds = settings.scheds||[]; | ||||||||||
| if (!scheds.length) {return;} | ||||||||||
|
Comment on lines
9
to
10
|
||||||||||
| let scheds = settings.scheds||[]; | |
| if (!scheds.length) {return;} | |
| let scheds = Array.isArray(settings) ? settings : (settings.scheds || []); | |
| if (!scheds || !scheds.length) {return;} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| (function() { | ||
| return { | ||
| name: "qmsched", | ||
| items: [ | ||
| { name : "Quiet Mode Toggle", | ||
| get : function() { | ||
| const mode = require("qmsched").getMode() | ||
| let txt="Off"; | ||
| let img=atob("GBgBAAAAAAAAAAAAABwAABwAAH8AAP+AAf/AA//gA//gA//gB//wA//gA//gA//gA//gA//gA//gABwAAD4AABwAAAgAAAAAAAAA"); | ||
| if(mode==1){ | ||
| txt="Alarms"; | ||
| img=atob("GBgBAAAAAAAAAAgAAP+AA//gB//wD//4D//4H//8H//8AAAAAAAAIADiAADgAADgH/nwH/nwD/P4D/P4B/hAA/zgAPnwAAjgAABA") | ||
|
Comment on lines
+8
to
+12
|
||
| } | ||
| if(mode==2){ | ||
| txt="Silent" | ||
| img=atob("GBgBAAAAAAAAAAgAAP+AA//gB//wD//4D//4H//8H//8GAAMGAAMOAAOGAAMH//8H//8H//8D//4D//4B//wA//gAP+AAAgAAAAA"); | ||
| } | ||
|
|
||
| return { | ||
| text : txt, | ||
| img : img}}, | ||
| show : function() {}, | ||
| hide : function() {}, | ||
| run : function() { | ||
| let mode=require("qmsched").getMode(); | ||
| mode = (mode + 1) % 3; | ||
| require("qmsched").setMode(mode); | ||
| this.emit("redraw"); | ||
| } | ||
|
|
||
| } | ||
| ] | ||
| }; | ||
| }) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatDaystreats a 0 bitmask as "Every day" because of the!maskcheck. However the scheduler logic treats a 0 mask as "no active days" (won’t ever trigger). Consider distinguishingundefined/missing from0, and either prevent persistingdays:0or display it as "No days".