added optional cycling fo themes

master
kkayam 2025-02-16 17:36:47 +00:00
parent 6349ce1f1c
commit 9edf0dea83
3 changed files with 88 additions and 1 deletions

49
apps/themes/boot.js Normal file
View File

@ -0,0 +1,49 @@
{
let s = require('Storage');
let settings = Object.assign(
{
cycleInterval: 0
},
s.readJSON('themes.settings.json', true) || {}
);
if (settings.cycleInterval != 0) {
let cl = (x) => { return g.setColor(x).getColor(); };
const THEMES_DATA = s.readJSON("themes.json");
// Convert hex colors to graphics context colors
const THEMES = {};
Object.keys(THEMES_DATA).forEach(themeName => {
const theme = THEMES_DATA[themeName];
THEMES[themeName] = {
fg: cl(theme.fg),
bg: cl(theme.bg),
fg2: cl(theme.fg2),
bg2: cl(theme.bg2),
fgH: cl(theme.fgH),
bgH: cl(theme.bgH),
dark: theme.dark
};
});
// Function to apply the selected theme
let setTheme = (themeNameOrObject) => {
const theme = typeof themeNameOrObject === 'string' ? THEMES[themeNameOrObject] : themeNameOrObject;
if (!theme) return;
g.setTheme(theme);
let settings = s.readJSON("setting.json", 1) || {};
settings.theme = theme;
s.write("setting.json", settings);
};
// Set up theme cycling
let themeNames = Object.keys(THEMES);
let currentThemeIndex = 0;
// Set up interval to change theme
setInterval(() => {
currentThemeIndex = (currentThemeIndex + 1) % themeNames.length;
setTheme(themeNames[currentThemeIndex]);
}, settings.cycleInterval * 60000); // Convert minutes to milliseconds
}
}

View File

@ -2,7 +2,7 @@
"id": "themes",
"name": "Themes",
"shortName": "Themes",
"version": "0.11",
"version": "0.12",
"description": "Color palettes at your disposal",
"type": "app",
"tags": "tool",
@ -24,6 +24,14 @@
{
"name": "themes.json",
"url": "themes.json"
},
{
"name": "themes.settings.js",
"url": "settings.js"
},
{
"name": "themes.boot.js",
"url": "boot.js"
}
]
}

30
apps/themes/settings.js Normal file
View File

@ -0,0 +1,30 @@
(function (back) {
const SETTINGS_FILE = "themes.settings.json";
// initialize with default settings...
const storage = require('Storage');
let settings = {
cycleInterval: 0
};
let saved_settings = storage.readJSON(SETTINGS_FILE, 1) || settings;
for (const key in saved_settings) {
settings[key] = saved_settings[key];
}
function save() {
storage.write(SETTINGS_FILE, settings);
}
E.showMenu({
'': { 'title': 'Themes' },
'< Back': back,
'Cycle Themes Interval': {
value: settings.cycleInterval,
min: 0, max: 1440, step: 5,
onchange: v => {
settings.cycleInterval = v;
save();
},
},
});
});