mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
Refactor config for simpler use and advanced options in plugins
This commit is contained in:
28
config/defaults.js
Normal file
28
config/defaults.js
Normal file
@ -0,0 +1,28 @@
|
||||
const defaultConfig = {
|
||||
"window-size": {
|
||||
width: 1100,
|
||||
height: 550,
|
||||
},
|
||||
url: "https://music.youtube.com",
|
||||
options: {
|
||||
tray: false,
|
||||
appVisible: true,
|
||||
autoUpdates: true,
|
||||
hideMenu: false,
|
||||
startAtLogin: false,
|
||||
disableHardwareAcceleration: false,
|
||||
},
|
||||
plugins: {
|
||||
navigation: {
|
||||
enabled: true,
|
||||
},
|
||||
shortcuts: {
|
||||
enabled: true,
|
||||
},
|
||||
adblocker: {
|
||||
enabled: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = defaultConfig;
|
||||
16
config/index.js
Normal file
16
config/index.js
Normal file
@ -0,0 +1,16 @@
|
||||
const plugins = require("./plugins");
|
||||
const store = require("./store");
|
||||
|
||||
const set = (key, value) => {
|
||||
store.set(key, value);
|
||||
};
|
||||
|
||||
const get = (key) => {
|
||||
return store.get(key);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
get,
|
||||
set,
|
||||
plugins,
|
||||
};
|
||||
41
config/plugins.js
Normal file
41
config/plugins.js
Normal file
@ -0,0 +1,41 @@
|
||||
const store = require("./store");
|
||||
|
||||
function getEnabled() {
|
||||
const plugins = store.get("plugins");
|
||||
const enabledPlugins = Object.entries(plugins).filter(([plugin, options]) =>
|
||||
isEnabled(plugin)
|
||||
);
|
||||
return enabledPlugins;
|
||||
}
|
||||
|
||||
function isEnabled(plugin) {
|
||||
const pluginConfig = store.get("plugins")[plugin];
|
||||
return pluginConfig !== undefined && pluginConfig.enabled;
|
||||
}
|
||||
|
||||
function setOptions(plugin, options) {
|
||||
const plugins = store.get("plugins");
|
||||
store.set("plugins", {
|
||||
...plugins,
|
||||
[plugin]: {
|
||||
...plugins[plugin],
|
||||
...options,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function enable(plugin) {
|
||||
setOptions(plugin, { enabled: true });
|
||||
}
|
||||
|
||||
function disable(plugin) {
|
||||
setOptions(plugin, { enabled: false });
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
isEnabled,
|
||||
getEnabled,
|
||||
enable,
|
||||
disable,
|
||||
setOptions,
|
||||
};
|
||||
26
config/store.js
Normal file
26
config/store.js
Normal file
@ -0,0 +1,26 @@
|
||||
const { dialog } = require("electron");
|
||||
const Store = require("electron-store");
|
||||
|
||||
const defaults = require("./defaults");
|
||||
|
||||
module.exports = new Store({
|
||||
defaults,
|
||||
clearInvalidConfig: false,
|
||||
migrations: {
|
||||
">=1.7.0": (store) => {
|
||||
const enabledPlugins = store.get("plugins");
|
||||
if (!Array.isArray(enabledPlugins)) {
|
||||
console.warn("Plugins are not in array format, cannot migrate");
|
||||
return;
|
||||
}
|
||||
|
||||
const plugins = {};
|
||||
enabledPlugins.forEach((enabledPlugin) => {
|
||||
plugins[enabledPlugin] = {
|
||||
enabled: true,
|
||||
};
|
||||
});
|
||||
store.set("plugins", plugins);
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user