TagSpaces is an offline, open source, document manager with tagging support
making global shortcut keys switchable without restart
Ilian Sapundshieva30f740e7ece
diff --git a/app/components/settings/SettingsKeyBindings.js b/app/components/settings/SettingsKeyBindings.jsindex c42650def..3e272127d 100644--- a/app/components/settings/SettingsKeyBindings.js+++ b/app/components/settings/SettingsKeyBindings.js@@ -27,6 +27,7 @@ import FormControl from '@material-ui/core/FormControl';import ListItem from '@material-ui/core/ListItem';import ListItemSecondaryAction from '@material-ui/core/ListItemSecondaryAction';import ListItemText from '@material-ui/core/ListItemText';+import PlatformIO from '../../services/platform-io';import i18n from '../../services/i18n';import {actions as SettingsActions,@@ -74,7 +75,10 @@ class SettingsKeyBindings extends React.Component<Props> {<ListItemText primary={i18n.t('core:enableGlobalKeyboardShortcuts')} /><ListItemSecondaryAction><Switch- onClick={() => setGlobalKeyBinding(!globalKeyBindingEnabled)}+ onClick={() => {+ setGlobalKeyBinding(!globalKeyBindingEnabled);+ PlatformIO.setGlobalShortcuts(!globalKeyBindingEnabled);+ }}checked={globalKeyBindingEnabled}/></ListItemSecondaryAction>diff --git a/app/containers/MainPage.js b/app/containers/MainPage.jsindex 7debb4fd3..37567db0e 100644--- a/app/containers/MainPage.js+++ b/app/containers/MainPage.js@@ -44,7 +44,6 @@ import {getLeftVerticalSplitSize,getMainVerticalSplitSize,getLastPublishedVersion,- isGlobalKeyBindingEnabled,actions as SettingsActions} from '../reducers/settings';import {@@ -474,7 +473,6 @@ function mapStateToProps(state) {mainSplitSize: getMainVerticalSplitSize(state),isUpdateAvailable: isUpdateAvailable(state),lastPublishedVersion: getLastPublishedVersion(state),- isGlobalKeyBindingEnabled: isGlobalKeyBindingEnabled(state),notificationStatus: getNotificationStatus(state)};}diff --git a/app/index.js b/app/index.jsindex aa04b96f4..23de067aa 100644--- a/app/index.js+++ b/app/index.js@@ -26,7 +26,8 @@ import { configureStore, history } from './store/configureStore';import './app.global.css';import { actions as AppActions } from './reducers/app';import { getDefaultLocationId } from './reducers/locations';-import { actions as SettingsActions, getCheckForUpdateOnStartup } from './reducers/settings';+import { actions as SettingsActions, getCheckForUpdateOnStartup, isGlobalKeyBindingEnabled } from './reducers/settings';+import PlatformIO from './services/platform-io';const store = configureStore();@@ -74,6 +75,7 @@ document.addEventListener('storeLoaded', () => {if (getCheckForUpdateOnStartup(state)) {store.dispatch(SettingsActions.checkForUpdate());}+ PlatformIO.setGlobalShortcuts(isGlobalKeyBindingEnabled(state));});function checkIsFirstRun() {diff --git a/app/main.dev.js b/app/main.dev.jsindex 6cb663bb9..9569c54c2 100644--- a/app/main.dev.js+++ b/app/main.dev.js@@ -188,8 +188,8 @@ app.on('ready', async () => {event.returnValue = path.join(__dirname, '');});- ipcMain.on('global-shortcuts-enabled', (e, arg) => {- if (arg) {+ ipcMain.on('global-shortcuts-enabled', (e, globalShortcutsEnabled) => {+ if (globalShortcutsEnabled) {globalShortcut.register('CommandOrControl+Shift+P', resumePlayback);globalShortcut.register('MediaPlayPause', resumePlayback);globalShortcut.register('CommandOrControl+Shift+N', newTextFile);diff --git a/app/services/electron-io.js b/app/services/electron-io.jsindex 1e19368b8..191db7c8b 100644--- a/app/services/electron-io.js+++ b/app/services/electron-io.js@@ -141,6 +141,10 @@ export default class ElectronIO {setZoomFactorElectron = (zoomLevel: number) => this.webFrame.setZoomFactor(zoomLevel);+ setGlobalShortcuts = (globalShortcutsEnabled: boolean) => {+ this.ipcRenderer.send('global-shortcuts-enabled', globalShortcutsEnabled);+ }+getAppPath = (): string => this.ipcRenderer.sendSync('app-dir-path-request','notNeededArgument'diff --git a/app/services/electron-menus.js b/app/services/electron-menus.jsindex 2dd20028d..fde0c0205 100644--- a/app/services/electron-menus.js+++ b/app/services/electron-menus.js@@ -65,12 +65,6 @@ export default function buildDesktopMenu(mainPageProps: Object) {window.dispatchEvent(audioEvent);});- document.addEventListener('storeLoaded', () => {- if (mainPageProps.isGlobalKeyBindingEnabled) {- ipcRenderer.send('global-shortcuts-enabled', true);- }- });-const templateDefault = [{label: i18n.t('core:file'),diff --git a/app/services/platform-io.js b/app/services/platform-io.jsindex 8e52a5680..855e81ad0 100644--- a/app/services/platform-io.js+++ b/app/services/platform-io.js@@ -74,6 +74,14 @@ export default class PlatformIO {}}+ static setGlobalShortcuts = globalShortcutsEnabled => {+ if (nativeAPI.setGlobalShortcuts) {+ nativeAPI.setGlobalShortcuts(globalShortcutsEnabled);+ } else {+ console.log('setGlobalShortcuts not supported');+ }+ }+static showMainWindow = (): void => nativeAPI.showMainWindow();static quitApp = (): void => nativeAPI.quitApp();