2019-06-08 08:35:43 +02:00
|
|
|
import {Config} from "data";
|
2019-05-29 05:48:41 +02:00
|
|
|
import ContentManager from "./contentmanager";
|
2019-06-08 08:35:43 +02:00
|
|
|
import {Modals} from "ui";
|
2019-06-09 04:24:05 +02:00
|
|
|
import Settings from "./settingsmanager";
|
2019-06-19 05:09:49 +02:00
|
|
|
import DOMManager from "./dommanager";
|
2019-06-09 04:24:05 +02:00
|
|
|
import {SettingsPanel as SettingsRenderer} from "ui";
|
2019-05-28 20:19:48 +02:00
|
|
|
|
2019-06-08 08:35:43 +02:00
|
|
|
const path = require("path");
|
2019-05-28 20:19:48 +02:00
|
|
|
|
2019-06-08 08:35:43 +02:00
|
|
|
export default new class ThemeManager extends ContentManager {
|
|
|
|
get name() {return "ThemeManager";}
|
|
|
|
get moduleExtension() {return ".css";}
|
|
|
|
get extension() {return ".theme.css";}
|
|
|
|
get contentFolder() {return path.resolve(Config.dataPath, "themes");}
|
|
|
|
get prefix() {return "theme";}
|
2019-05-28 20:19:48 +02:00
|
|
|
|
2019-06-08 08:35:43 +02:00
|
|
|
/* Aliases */
|
|
|
|
updateThemeList() {return this.updateList();}
|
2019-06-09 04:24:05 +02:00
|
|
|
loadAllThemes() {
|
2019-06-10 05:40:35 +02:00
|
|
|
Settings.registerPanel("themes", "Themes", {element: () => SettingsRenderer.getContentPanel("Themes", this.contentList, this.state, {
|
2019-06-10 00:37:46 +02:00
|
|
|
folder: this.contentFolder,
|
|
|
|
onChange: this.toggleTheme.bind(this),
|
|
|
|
reload: this.reloadTheme.bind(this),
|
|
|
|
refreshList: this.updateThemeList.bind(this)
|
|
|
|
})});
|
2019-06-09 04:24:05 +02:00
|
|
|
return this.loadAllContent();
|
|
|
|
}
|
2019-05-28 20:19:48 +02:00
|
|
|
|
2019-06-08 08:35:43 +02:00
|
|
|
enableTheme(idOrContent) {return this.enableContent(idOrContent);}
|
|
|
|
disableTheme(idOrContent) {return this.disableContent(idOrContent);}
|
|
|
|
toggleTheme(id) {return this.toggleContent(id);}
|
2019-05-28 20:19:48 +02:00
|
|
|
|
2019-06-08 08:35:43 +02:00
|
|
|
unloadTheme(idOrFileOrContent) {return this.unloadContent(idOrFileOrContent);}
|
2019-05-28 20:19:48 +02:00
|
|
|
|
2019-06-08 08:35:43 +02:00
|
|
|
loadTheme(filename) {
|
|
|
|
const error = this.loadContent(filename);
|
|
|
|
if (error) Modals.showContentErrors({themes: [error]});
|
2019-05-28 20:19:48 +02:00
|
|
|
}
|
|
|
|
|
2019-06-10 00:37:46 +02:00
|
|
|
reloadTheme(idOrFileOrContent) {
|
|
|
|
const error = this.reloadContent(idOrFileOrContent);
|
2019-06-08 08:35:43 +02:00
|
|
|
if (error) Modals.showContentErrors({themes: [error]});
|
2019-05-28 20:19:48 +02:00
|
|
|
}
|
|
|
|
|
2019-06-08 08:35:43 +02:00
|
|
|
/* Overrides */
|
|
|
|
getContentModification(module, content, meta) {
|
2019-06-19 21:24:05 +02:00
|
|
|
meta.css = content;
|
2019-06-08 08:35:43 +02:00
|
|
|
return `module.exports = ${JSON.stringify(meta)};`;
|
2019-06-19 21:24:05 +02:00
|
|
|
}
|
2019-06-08 08:35:43 +02:00
|
|
|
|
|
|
|
startContent(id) {return this.addTheme(id);}
|
|
|
|
stopContent(id) {return this.removeTheme(id);}
|
|
|
|
|
|
|
|
addTheme(idOrContent) {
|
|
|
|
const content = typeof(idOrContent) == "string" ? this.contentList.find(p => p.id == idOrContent) : idOrContent;
|
|
|
|
if (!content) return;
|
2019-06-20 04:19:34 +02:00
|
|
|
DOMManager.injectTheme(content.id, content.css);
|
2019-05-28 20:19:48 +02:00
|
|
|
}
|
|
|
|
|
2019-06-08 08:35:43 +02:00
|
|
|
removeTheme(idOrContent) {
|
|
|
|
const content = typeof(idOrContent) == "string" ? this.contentList.find(p => p.id == idOrContent) : idOrContent;
|
|
|
|
if (!content) return;
|
2019-06-20 04:19:34 +02:00
|
|
|
DOMManager.removeTheme(content.id);
|
2019-06-08 08:35:43 +02:00
|
|
|
}
|
|
|
|
};
|