From a94e6c69b5d409e219a0e5e62b045716f0f9c577 Mon Sep 17 00:00:00 2001 From: Vijay A Date: Thu, 7 Oct 2021 09:02:32 +0530 Subject: fix: Control the global shortcut (for hiding Ferdi) via a preference (default: off) --- .../settings/settings/EditSettingsForm.js | 1 + src/config.ts | 1 + src/containers/settings/EditSettingsScreen.js | 10 ++++++++ src/i18n/locales/en-US.json | 1 + src/index.js | 30 ++++++++++++---------- 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/components/settings/settings/EditSettingsForm.js b/src/components/settings/settings/EditSettingsForm.js index 063bf7b15..c04835a5f 100644 --- a/src/components/settings/settings/EditSettingsForm.js +++ b/src/components/settings/settings/EditSettingsForm.js @@ -673,6 +673,7 @@ class EditSettingsForm extends Component { {this.state.activeSetttingsTab === 'advanced' && (
+

{intl.formatMessage(messages.appRestartRequired)}

diff --git a/src/config.ts b/src/config.ts index 82ce131f9..9aca70ba3 100644 --- a/src/config.ts +++ b/src/config.ts @@ -202,6 +202,7 @@ export const DEFAULT_APP_SETTINGS = { beta: false, isAppMuted: false, enableGPUAcceleration: true, + enableGlobalHideShortcut: false, // Ferdi specific options server: LIVE_FERDI_API, diff --git a/src/containers/settings/EditSettingsScreen.js b/src/containers/settings/EditSettingsScreen.js index 4b59442cb..8c37d2692 100644 --- a/src/containers/settings/EditSettingsScreen.js +++ b/src/containers/settings/EditSettingsScreen.js @@ -209,6 +209,10 @@ const messages = defineMessages({ id: 'settings.app.form.enableGPUAcceleration', defaultMessage: 'Enable GPU Acceleration', }, + enableGlobalHideShortcut: { + id: 'settings.app.form.enableGlobalHideShortcut', + defaultMessage: 'Enable Global shortcut to hide Ferdi', + }, beta: { id: 'settings.app.form.beta', defaultMessage: 'Include beta versions', @@ -289,6 +293,7 @@ class EditSettingsScreen extends Component { scheduledDNDStart: settingsData.scheduledDNDStart, scheduledDNDEnd: settingsData.scheduledDNDEnd, enableGPUAcceleration: Boolean(settingsData.enableGPUAcceleration), + enableGlobalHideShortcut: Boolean(settingsData.enableGlobalHideShortcut), showDisabledServices: Boolean(settingsData.showDisabledServices), darkMode: Boolean(settingsData.darkMode), adaptableDarkMode: Boolean(settingsData.adaptableDarkMode), @@ -623,6 +628,11 @@ class EditSettingsScreen extends Component { value: settings.all.app.enableGPUAcceleration, default: DEFAULT_APP_SETTINGS.enableGPUAcceleration, }, + enableGlobalHideShortcut: { + label: intl.formatMessage(messages.enableGlobalHideShortcut), + value: settings.all.app.enableGlobalHideShortcut, + default: DEFAULT_APP_SETTINGS.enableGlobalHideShortcut, + }, locale: { label: intl.formatMessage(messages.language), value: app.locale, diff --git a/src/i18n/locales/en-US.json b/src/i18n/locales/en-US.json index 812ec8c4c..301a71818 100644 --- a/src/i18n/locales/en-US.json +++ b/src/i18n/locales/en-US.json @@ -210,6 +210,7 @@ "settings.app.form.customTodoServer": "Custom Todo Server", "settings.app.form.darkMode": "Enable Dark Mode", "settings.app.form.enableGPUAcceleration": "Enable GPU Acceleration", + "settings.app.form.enableGlobalHideShortcut": "Enable Global shortcut to hide Ferdi", "settings.app.form.enableLock": "Enable Password Lock", "settings.app.form.enableMenuBar": "Always show Ferdi in Menu Bar", "settings.app.form.enableSpellchecking": "Enable spell checking", diff --git a/src/index.js b/src/index.js index 9f384f5fa..933637688 100644 --- a/src/index.js +++ b/src/index.js @@ -76,10 +76,10 @@ if (isWindows) { const settings = new Settings('app', DEFAULT_APP_SETTINGS); const proxySettings = new Settings('proxy'); -const retrieveSettingValue = (key, defaultValue = true) => +const retrieveSettingValue = (key, defaultValue) => ifUndefinedBoolean(settings.get(key), defaultValue); -if (retrieveSettingValue('sentry')) { +if (retrieveSettingValue('sentry', DEFAULT_APP_SETTINGS.sentry)) { // eslint-disable-next-line global-require require('./sentry'); } @@ -196,7 +196,7 @@ const createWindow = () => { frame: isLinux, backgroundColor, webPreferences: { - spellcheck: retrieveSettingValue('enableSpellchecking'), + spellcheck: retrieveSettingValue('enableSpellchecking', DEFAULT_APP_SETTINGS.enableSpellchecking), nodeIntegration: true, contextIsolation: false, webviewTag: true, @@ -270,13 +270,13 @@ const createWindow = () => { // Dereference the window object, usually you would store windows // in an array if your app supports multi windows, this is the time // when you should delete the corresponding element. - if (!willQuitApp && retrieveSettingValue('runInBackground')) { + if (!willQuitApp && retrieveSettingValue('runInBackground', DEFAULT_APP_SETTINGS.runInBackground)) { e.preventDefault(); if (isWindows) { debug('Window: minimize'); mainWindow.minimize(); - if (retrieveSettingValue('closeToSystemTray')) { + if (retrieveSettingValue('closeToSystemTray', DEFAULT_APP_SETTINGS.closeToSystemTray)) { debug('Skip taskbar: true'); mainWindow.setSkipTaskbar(true); } @@ -300,7 +300,7 @@ const createWindow = () => { mainWindow.on('minimize', () => { app.wasMaximized = app.isMaximized; - if (retrieveSettingValue('minimizeToSystemTray')) { + if (retrieveSettingValue('minimizeToSystemTray', DEFAULT_APP_SETTINGS.minimizeToSystemTray)) { debug('Skip taskbar: true'); mainWindow.setSkipTaskbar(true); trayIcon.show(); @@ -326,7 +326,7 @@ const createWindow = () => { mainWindow.maximize(); } - if (!retrieveSettingValue('enableSystemTray')) { + if (!retrieveSettingValue('enableSystemTray', DEFAULT_APP_SETTINGS.enableSystemTray)) { debug('Tray: hiding tray icon'); trayIcon.hide(); } @@ -351,17 +351,19 @@ const createWindow = () => { openExternalUrl(url); }); - if (retrieveSettingValue('startMinimized', false)) { + if (retrieveSettingValue('startMinimized', DEFAULT_APP_SETTINGS.startMinimized)) { mainWindow.hide(); } else { mainWindow.show(); } app.whenReady().then(() => { - // Toggle the window on 'Alt+X' - globalShortcut.register(`${altKey()}+X`, () => { - trayIcon.trayMenuTemplate[0].click(); - }); + if (retrieveSettingValue('enableGlobalHideShortcut', DEFAULT_APP_SETTINGS.enableGlobalHideShortcut)) { + // Toggle the window on 'Alt+X' + globalShortcut.register(`${altKey()}+X`, () => { + trayIcon.trayMenuTemplate[0].click(); + }); + } }); }; @@ -578,7 +580,7 @@ ipcMain.on('set-spellchecker-locales', (e, { locale, serviceId }) => { app.on('window-all-closed', () => { // On OS X it is common for applications and their menu bar // to stay active until the user quits explicitly with Cmd + Q - if (retrieveSettingValue('runInBackground')) { + if (retrieveSettingValue('runInBackground', DEFAULT_APP_SETTINGS.runInBackground)) { debug('Window: all windows closed, quit app'); app.quit(); } else { @@ -589,7 +591,7 @@ app.on('window-all-closed', () => { app.on('before-quit', event => { const yesButtonIndex = 0; let selection = yesButtonIndex; - if (retrieveSettingValue('confirmOnQuit')) { + if (retrieveSettingValue('confirmOnQuit', DEFAULT_APP_SETTINGS.confirmOnQuit)) { selection = dialog.showMessageBoxSync(app.mainWindow, { type: 'question', message: 'Quit', -- cgit v1.2.3-70-g09d2