diff --git a/src/auto-launch.js b/src/auto-launch.js index c56dbd5f1..866dcc045 100644 --- a/src/auto-launch.js +++ b/src/auto-launch.js @@ -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' @@ -109,5 +108,4 @@ module.exports = async function () { createToggler(CONFIG_KEY, activate) } -module.exports.CONFIG_KEY = CONFIG_KEY module.exports.isSupported = isSupported diff --git a/src/automatic-gc.js b/src/automatic-gc.js index 6d84c5390..18e636fa1 100644 --- a/src/automatic-gc.js +++ b/src/automatic-gc.js @@ -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) @@ -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 diff --git a/src/common/config-keys.js b/src/common/config-keys.js new file mode 100644 index 000000000..ad8b93974 --- /dev/null +++ b/src/common/config-keys.js @@ -0,0 +1,15 @@ +/** + * Configuration key constants for the features in IPFS Desktop. + * + * @type {Object.} + */ +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 diff --git a/src/enable-namesys-pubsub.js b/src/enable-namesys-pubsub.js index 85a83db97..0e619e39e 100644 --- a/src/enable-namesys-pubsub.js +++ b/src/enable-namesys-pubsub.js @@ -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) @@ -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 diff --git a/src/enable-pubsub.js b/src/enable-pubsub.js index 554d70517..bc2006e68 100644 --- a/src/enable-pubsub.js +++ b/src/enable-pubsub.js @@ -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) @@ -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 diff --git a/src/take-screenshot.js b/src/take-screenshot.js index dad4e2925..e08ace398 100644 --- a/src/take-screenshot.js +++ b/src/take-screenshot.js @@ -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' @@ -123,4 +122,3 @@ module.exports = function (ctx) { module.exports.takeScreenshot = takeScreenshot module.exports.SHORTCUT = SHORTCUT -module.exports.CONFIG_KEY = CONFIG_KEY diff --git a/src/tray.js b/src/tray.js index 348efbc77..e745b64a2 100644 --- a/src/tray.js +++ b/src/tray.js @@ -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 { @@ -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') ] }, { @@ -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 @@ -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 } diff --git a/src/webui/index.js b/src/webui/index.js index 642a235c0..6ce3fd564 100644 --- a/src/webui/index.js +++ b/src/webui/index.js @@ -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') @@ -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() @@ -199,5 +198,3 @@ module.exports = async function (ctx) { window.loadURL(url.toString()) }) } - -module.exports.CONFIG_KEY = CONFIG_KEY