Skip to content

Commit

Permalink
Refactored FF code to align more w/ Chromium code for easier maintena…
Browse files Browse the repository at this point in the history
  • Loading branch information
kudo-sync-bot committed Nov 30, 2024
1 parent b84a1a8 commit 9ced016
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions firefox/extension/lib/settings.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
window.config = {}
window.settings = {

controls: {
notifDisabled: { type: 'toggle',
label: chrome.i18n.getMessage('menuLabel_modeNotifs'),
helptip: chrome.i18n.getMessage('helptip_modeNotifs') }
controls: { // displays top-to-bottom in toolbar menu
get notifDisabled() { return { type: 'toggle',
label: window.settings.getMsg('menuLabel_modeNotifs'),
helptip: window.settings.getMsg('helptip_modeNotifs') }}
},

getMsg(key) {
return typeof chrome != 'undefined' && chrome.runtime ? chrome.i18n.getMessage(key)
: this.appProps.msgs[key] // assigned from app.msgs in userscript
},

load() {
const keys = ( // original array if array, else new array from multiple args
Array.isArray(arguments[0]) ? arguments[0] : Array.from(arguments))
return Promise.all(keys.map(key => // resolve promise when all keys load
new Promise(resolve => // resolve promise when single key value loads
chrome.storage.sync.get(key, result => { // load from browser extension storage
window.config[key] = result[key] || false ; resolve()
}))))},
if (typeof chrome != 'undefined' && chrome.runtime) // asynchronously load from browser extension storage
return Promise.all(keys.map(key => // resolve promise when all keys load
new Promise(resolve => // resolve promise when single key value loads
chrome.storage.sync.get(key, result => {
window.config[key] = result[key] || false ; resolve()
})))) ; else // synchronously load from userscript manager storage
keys.forEach(key => window.config[key] = GM_getValue(this.appProps.configKeyPrefix + '_' + key, false))
},

save(key, val) {
chrome.storage.sync.set({ [key]: val }) // save to browser extension storage
if (typeof chrome != 'undefined' && chrome.runtime) // save to browser extension storage
chrome.storage.sync.set({ [key]: val })
else // save to userscript manager storage
GM_setValue(this.appProps.configKeyPrefix + '_' + key, val)
window.config[key] = val // save to memory
}
};

0 comments on commit 9ced016

Please sign in to comment.