diff options
author | 0neGal <mail@0negal.com> | 2024-02-03 19:15:29 +0100 |
---|---|---|
committer | 0neGal <mail@0negal.com> | 2024-02-03 19:21:23 +0100 |
commit | 159e2f981bdbfd6a0589639424155d34b7a4cc91 (patch) | |
tree | b3c1dfa3aaeb989b88abea6c9fc927c5dad3c2f9 /src/modules/settings.js | |
parent | 647bd1f6a76c834b3db9b70005f4b8365d1ded91 (diff) | |
download | Viper-159e2f981bdbfd6a0589639424155d34b7a4cc91.tar.gz Viper-159e2f981bdbfd6a0589639424155d34b7a4cc91.zip |
src/modules/settings.js now provides a function
This fixes a couple issues where the main process wouldn't actually get
changes made to the settings, this fixes that.
On top of this, changing settings is now done with `settings.set()`
There shouldn't be any breakage from this change, but I suppose it is
possible. Especially because the `settings()` function still does
contain backup options set, meaning `settings.nsargs` is technically
still valid, but dont expect it to actually be updated when that
variable is changed, its merely here to avoid any problems.
Diffstat (limited to 'src/modules/settings.js')
-rw-r--r-- | src/modules/settings.js | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/modules/settings.js b/src/modules/settings.js index 9d036cf..db6c68c 100644 --- a/src/modules/settings.js +++ b/src/modules/settings.js @@ -58,7 +58,7 @@ if (fs.existsSync("viper.json")) { // // you can also pass a settings object to the function and it'll try and // merge it together with the already existing settings -settings.save = (obj = {}, notify_renderer = true) => { +let save = (obj = {}, notify_renderer = true) => { // refuse to save if settings aren't valid if (invalid_settings) { settings = {}; @@ -68,8 +68,6 @@ settings.save = (obj = {}, notify_renderer = true) => { ...settings, ...obj } - delete settings_content.save; - let stringified_settings = JSON.stringify({ ...settings, ...obj }) @@ -87,4 +85,26 @@ settings.save = (obj = {}, notify_renderer = true) => { } } -module.exports = settings; +// sets `key` in `settings` to `value` +let set = (key, value) => { + settings[key] = value; +} + +// returns up-to-date `settings`, along with `set()` and `save()` +let export_func = () => { + return { + ...settings, + + set, + save + } +} + +// add properties from `settings` to `export_func`, this is just for +// backwards compatibility, and they really shouldn't be relied on, +// this'll likely be removed at some point +for (let i in settings) { + export_func[i] = settings[i]; +} + +module.exports = export_func; |