-
Notifications
You must be signed in to change notification settings - Fork 510
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from th-ch/advanced-config
Refactor config, custom plugin options
- Loading branch information
Showing
15 changed files
with
282 additions
and
165 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,37 @@ | ||
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: { | ||
// Enabled plugins | ||
navigation: { | ||
enabled: true, | ||
}, | ||
shortcuts: { | ||
enabled: true, | ||
}, | ||
adblocker: { | ||
enabled: true, | ||
cache: true, | ||
additionalBlockLists: [], // Additional list of filters, e.g "https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/filters.txt" | ||
}, | ||
// Disabled plugins | ||
downloader: { | ||
enabled: false, | ||
ffmpegArgs: [], // e.g. ["-b:a", "192k"] for an audio bitrate of 192kb/s | ||
downloadFolder: undefined, // Custom download folder (absolute path) | ||
}, | ||
}, | ||
}; | ||
|
||
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,18 @@ | ||
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, | ||
edit: () => store.openInEditor(), | ||
watch: (cb) => store.onDidAnyChange(cb), | ||
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,40 @@ | ||
const Store = require("electron-store"); | ||
|
||
const defaults = require("./defaults"); | ||
|
||
const 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; | ||
} | ||
|
||
// Include custom options | ||
const plugins = { | ||
adblocker: { | ||
enabled: true, | ||
cache: true, | ||
additionalBlockLists: [], | ||
}, | ||
downloader: { | ||
enabled: false, | ||
ffmpegArgs: [], // e.g. ["-b:a", "192k"] for an audio bitrate of 192kb/s | ||
downloadFolder: undefined, // Custom download folder (absolute path) | ||
}, | ||
}; | ||
enabledPlugins.forEach((enabledPlugin) => { | ||
plugins[enabledPlugin] = { | ||
...plugins[enabledPlugin], | ||
enabled: true, | ||
}; | ||
}); | ||
store.set("plugins", plugins); | ||
}, | ||
}; | ||
|
||
module.exports = new Store({ | ||
defaults, | ||
clearInvalidConfig: false, | ||
migrations, | ||
}); |
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.