Skip to content

Commit

Permalink
chore(maintenance): move config keys to separate file (#2143)
Browse files Browse the repository at this point in the history
Co-authored-by: Russell Dempsey <[email protected]>
  • Loading branch information
hacdias and SgtPooki authored Jun 9, 2022
1 parent e77083e commit e16b1e7
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 42 deletions.
4 changes: 1 addition & 3 deletions src/auto-launch.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ const createToggler = require('./utils/create-toggler')
const logger = require('./common/logger')
const store = require('./common/store')
const { IS_MAC, IS_WIN } = require('./common/consts')
const { AUTO_LAUNCH: CONFIG_KEY } = require('./common/config-keys')
const { showDialog, recoverableErrorDialog } = require('./dialogs')

const CONFIG_KEY = 'autoLaunch'

function isSupported () {
const plat = os.platform()
return plat === 'linux' || plat === 'win32' || plat === 'darwin'
Expand Down Expand Up @@ -109,5 +108,4 @@ module.exports = async function () {
createToggler(CONFIG_KEY, activate)
}

module.exports.CONFIG_KEY = CONFIG_KEY
module.exports.isSupported = isSupported
4 changes: 1 addition & 3 deletions src/automatic-gc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const createToggler = require('./utils/create-toggler')
const logger = require('./common/logger')
const store = require('./common/store')
const { AUTO_GARBAGE_COLLECTOR: CONFIG_KEY } = require('./common/config-keys')
const { ipcMain } = require('electron')

const CONFIG_KEY = 'automaticGC'
const gcFlag = '--enable-gc'
const isEnabled = flags => flags.some(f => f === gcFlag)

Expand Down Expand Up @@ -50,5 +50,3 @@ module.exports = async function () {
createToggler(CONFIG_KEY, activate)
logger.info(`[automatic gc] ${store.get(CONFIG_KEY, true) ? 'enabled' : 'disabled'}`)
}

module.exports.CONFIG_KEY = CONFIG_KEY
15 changes: 15 additions & 0 deletions src/common/config-keys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Configuration key constants for the features in IPFS Desktop.
*
* @type {Object.<string, string>}
*/
const CONFIG_KEYS = {
AUTO_LAUNCH: 'autoLaunch',
AUTO_GARBAGE_COLLECTOR: 'automaticGC',
SCREENSHOT_SHORTCUT: 'screenshotShortcut',
OPEN_WEBUI_LAUNCH: 'openWebUIAtLaunch',
EXPERIMENT_PUBSUB: 'experiments.pubsub',
EXPERIMENT_PUBSUB_NAMESYS: 'experiments.pubsubNamesys'
}

module.exports = CONFIG_KEYS
4 changes: 1 addition & 3 deletions src/enable-namesys-pubsub.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const createToggler = require('./utils/create-toggler')
const logger = require('./common/logger')
const store = require('./common/store')
const { EXPERIMENT_PUBSUB_NAMESYS: CONFIG_KEY } = require('./common/config-keys')
const { ipcMain } = require('electron')

const CONFIG_KEY = 'experiments.pubsubNamesys'
const namesysPubsubFlag = '--enable-namesys-pubsub'
const isEnabled = flags => flags.some(f => f === namesysPubsubFlag)

Expand Down Expand Up @@ -50,5 +50,3 @@ module.exports = async function () {
createToggler(CONFIG_KEY, activate)
logger.info(`[ipns over pubsub] ${store.get(CONFIG_KEY, false) ? 'enabled' : 'disabled'}`)
}

module.exports.CONFIG_KEY = CONFIG_KEY
4 changes: 1 addition & 3 deletions src/enable-pubsub.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const createToggler = require('./utils/create-toggler')
const logger = require('./common/logger')
const store = require('./common/store')
const { EXPERIMENT_PUBSUB: CONFIG_KEY } = require('./common/config-keys')
const { ipcMain } = require('electron')

const CONFIG_KEY = 'experiments.pubsub'
const pubsubFlag = '--enable-pubsub-experiment'
const isEnabled = flags => flags.some(f => f === pubsubFlag)

Expand Down Expand Up @@ -50,5 +50,3 @@ module.exports = async function () {
createToggler(CONFIG_KEY, activate)
logger.info(`[pubsub] ${store.get(CONFIG_KEY, false) ? 'enabled' : 'disabled'}`)
}

module.exports.CONFIG_KEY = CONFIG_KEY
4 changes: 1 addition & 3 deletions src/take-screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ const { clipboard, nativeImage, ipcMain } = require('electron')
const logger = require('./common/logger')
const { IS_MAC } = require('./common/consts')
const { notify, notifyError } = require('./common/notify')
const { SCREENSHOT_SHORTCUT: CONFIG_KEY } = require('./common/config-keys')
const setupGlobalShortcut = require('./utils/setup-global-shortcut')

const CONFIG_KEY = 'screenshotShortcut'

const SHORTCUT = IS_MAC
? 'Command+Control+S'
: 'CommandOrControl+Alt+S'
Expand Down Expand Up @@ -123,4 +122,3 @@ module.exports = function (ctx) {

module.exports.takeScreenshot = takeScreenshot
module.exports.SHORTCUT = SHORTCUT
module.exports.CONFIG_KEY = CONFIG_KEY
35 changes: 12 additions & 23 deletions src/tray.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,10 @@ const { setCustomBinary, clearCustomBinary, hasCustomBinary } = require('./custo
const { STATUS } = require('./daemon')
const { IS_MAC, IS_WIN, VERSION, GO_IPFS_VERSION } = require('./common/consts')

const { CONFIG_KEY: SCREENSHOT_KEY, SHORTCUT: SCREENSHOT_SHORTCUT, takeScreenshot } = require('./take-screenshot')
const { CONFIG_KEY: AUTO_LAUNCH_KEY, isSupported: supportsLaunchAtLogin } = require('./auto-launch')
const { CONFIG_KEY: PUBSUB_KEY } = require('./enable-pubsub')
const { CONFIG_KEY: NAMESYS_PUBSUB_KEY } = require('./enable-namesys-pubsub')
const { CONFIG_KEY: AUTO_GC_KEY } = require('./automatic-gc')
const { CONFIG_KEY: AUTO_LAUNCH_WEBUI_KEY } = require('./webui')

const CONFIG_KEYS = [
AUTO_LAUNCH_KEY,
AUTO_LAUNCH_WEBUI_KEY,
AUTO_GC_KEY,
SCREENSHOT_KEY,
PUBSUB_KEY,
NAMESYS_PUBSUB_KEY
]
const CONFIG_KEYS = require('./common/config-keys')

const { SHORTCUT: SCREENSHOT_SHORTCUT, takeScreenshot } = require('./take-screenshot')
const { isSupported: supportsLaunchAtLogin } = require('./auto-launch')

function buildCheckbox (key, label) {
return {
Expand Down Expand Up @@ -114,17 +103,17 @@ function buildMenu (ctx) {
label: i18n.t('settings.appPreferences'),
enabled: false
},
buildCheckbox(AUTO_LAUNCH_KEY, 'settings.launchOnStartup'),
buildCheckbox(AUTO_LAUNCH_WEBUI_KEY, 'settings.openWebUIAtLaunch'),
buildCheckbox(AUTO_GC_KEY, 'settings.automaticGC'),
buildCheckbox(SCREENSHOT_KEY, 'settings.takeScreenshotShortcut'),
buildCheckbox(CONFIG_KEYS.AUTO_LAUNCH, 'settings.launchOnStartup'),
buildCheckbox(CONFIG_KEYS.OPEN_WEBUI_LAUNCH, 'settings.openWebUIAtLaunch'),
buildCheckbox(CONFIG_KEYS.AUTO_GARBAGE_COLLECTOR, 'settings.automaticGC'),
buildCheckbox(CONFIG_KEYS.SCREENSHOT_SHORTCUT, 'settings.takeScreenshotShortcut'),
{ type: 'separator' },
{
label: i18n.t('settings.experiments'),
enabled: false
},
buildCheckbox(PUBSUB_KEY, 'settings.pubsub'),
buildCheckbox(NAMESYS_PUBSUB_KEY, 'settings.namesysPubsub')
buildCheckbox(CONFIG_KEYS.EXPERIMENT_PUBSUB, 'settings.pubsub'),
buildCheckbox(CONFIG_KEYS.EXPERIMENT_PUBSUB_NAMESYS, 'settings.namesysPubsub')
]
},
{
Expand Down Expand Up @@ -303,7 +292,7 @@ module.exports = function (ctx) {
menu.getMenuItemById('stopIpfs').enabled = !gcRunning
menu.getMenuItemById('restartIpfs').enabled = !gcRunning

menu.getMenuItemById(AUTO_LAUNCH_KEY).enabled = supportsLaunchAtLogin()
menu.getMenuItemById(CONFIG_KEYS.AUTO_LAUNCH).enabled = supportsLaunchAtLogin()
menu.getMenuItemById('takeScreenshot').enabled = status === STATUS.STARTING_FINISHED

menu.getMenuItemById('moveRepositoryLocation').enabled = !gcRunning && status !== STATUS.STOPPING_STARTED
Expand All @@ -323,7 +312,7 @@ module.exports = function (ctx) {
}

// Update configuration checkboxes.
for (const key of CONFIG_KEYS) {
for (const key of Object.values(CONFIG_KEYS)) {
const enabled = store.get(key, false)
menu.getMenuItemById(key).checked = enabled
}
Expand Down
5 changes: 1 addition & 4 deletions src/webui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const i18n = require('i18next')
const openExternal = require('./open-external')
const logger = require('../common/logger')
const store = require('../common/store')
const { OPEN_WEBUI_LAUNCH: CONFIG_KEY } = require('../common/config-keys')
const dock = require('../utils/dock')
const { VERSION, ELECTRON_VERSION } = require('../common/consts')
const createToggler = require('../utils/create-toggler')
Expand All @@ -17,8 +18,6 @@ const { performance } = require('perf_hooks')
const Countly = require('countly-sdk-nodejs')
serve({ scheme: 'webui', directory: join(__dirname, '../../assets/webui') })

const CONFIG_KEY = 'openWebUIAtLaunch'

const createWindow = () => {
const dimensions = screen.getPrimaryDisplay()

Expand Down Expand Up @@ -199,5 +198,3 @@ module.exports = async function (ctx) {
window.loadURL(url.toString())
})
}

module.exports.CONFIG_KEY = CONFIG_KEY

0 comments on commit e16b1e7

Please sign in to comment.