added optional cycling fo themes
parent
6349ce1f1c
commit
9edf0dea83
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -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();
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue