-
Notifications
You must be signed in to change notification settings - Fork 557
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor config for simpler use and advanced options in plugins
- Loading branch information
Showing
11 changed files
with
172 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.