From 002081bcb91d1756684ed228cd8fa7241710ba70 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Wed, 12 May 2021 00:47:41 +0300 Subject: [PATCH] use store migration --- config/store.js | 22 ++++++++++++++++++++++ plugins/shortcuts/back.js | 25 ------------------------- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/config/store.js b/config/store.js index 9c0de1e48c..c91174b798 100644 --- a/config/store.js +++ b/config/store.js @@ -3,6 +3,28 @@ const Store = require("electron-store"); const defaults = require("./defaults"); const migrations = { + /** Update shortcuts format from array to object */ + ">=1.12.0": (store) => { + const options = store.get("plugins.shortcuts") + let updated = false; + for (const optionType of ["global", "local"]) { + if (Array.isArray(options[optionType])) { + const updatedOptions = {}; + for (const optionObject of options[optionType]) { + if (optionObject.action && optionObject.shortcut) { + updatedOptions[optionObject.action] = optionObject.shortcut; + } + } + + options[optionType] = updatedOptions; + updated = true; + } + } + + if (updated) { + store.set("plugins.shortcuts", options); + } + }, ">=1.11.0": (store) => { if (store.get("options.resumeOnStart") === undefined) { store.set("options.resumeOnStart", true); diff --git a/plugins/shortcuts/back.js b/plugins/shortcuts/back.js index 688dc5a44b..075aefe580 100644 --- a/plugins/shortcuts/back.js +++ b/plugins/shortcuts/back.js @@ -1,6 +1,5 @@ const { globalShortcut } = require("electron"); const electronLocalshortcut = require("electron-localshortcut"); -const { setOptions } = require("../../config/plugins"); const getSongControls = require("../../providers/song-controls"); @@ -20,8 +19,6 @@ function registerShortcuts(win, options) { const songControls = getSongControls(win); const { playPause, next, previous, search } = songControls; - updateOptions(options); - if (options.overrideMediaKeys) { _registerGlobalShortcut(win.webContents, "MediaPlayPause", playPause); _registerGlobalShortcut(win.webContents, "MediaNextTrack", next); @@ -59,26 +56,4 @@ function registerShortcuts(win, options) { } } -/** Update options to new format if they are still an array (old format) */ -function updateOptions(options) { - let updated = false; - for (const optionType of ["global", "local"]) { - if (Array.isArray(options[optionType])) { - const updatedOptions = {}; - for (const optionObject of options[optionType]) { - if (optionObject.action && optionObject.shortcut) { - updatedOptions[optionObject.action] = optionObject.shortcut; - } - } - - options[optionType] = updatedOptions; - updated = true; - } - } - - if (updated) { - setOptions("shortcuts", options); - } -} - module.exports = registerShortcuts;