Skip to content

Commit

Permalink
feature: add global shortcut: 'openGlobalSearch'
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksey-hoffman committed Sep 18, 2021
1 parent 057bb3c commit e934410
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export default {
this.checkForAppUpdateInstalled()
this.initDirWatcherWorker()
this.initEventHubListeners()
electron.ipcRenderer.invoke('main-window-loaded')
}
catch (error) {
electron.ipcRenderer.send('show:errorWindow', {
Expand Down Expand Up @@ -219,6 +220,10 @@ export default {
})
},
initIPCListeners () {
electron.ipcRenderer.on('open-global-search', (event, data) => {
this.$store.dispatch('TOGGLE_GLOBAL_SEARCH')
})
electron.ipcRenderer.on('store:action', (event, data) => {
this.$store.dispatch(data.action, data.params)
})
Expand Down
41 changes: 38 additions & 3 deletions src/electronMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ const windows = {
trashManager: null,
quickViewWindow: null
}
const windowLoadedCallbacks = {
mainWindow: []
}
const globalShortcuts = {}
let storageData
let tray
Expand Down Expand Up @@ -296,7 +299,20 @@ function createUtilWindow (fileName) {
})
}

function runWindowLoadedCallbacks () {
for (const window in windowLoadedCallbacks) {
windowLoadedCallbacks[window].forEach(callback => {
callback()
})
}
}

function initIPCListeners () {
electron.ipcMain.handle('main-window-loaded', async (event) => {
runWindowLoadedCallbacks()
})

electron.ipcMain.handle('get-app-storage-data', async (event) => {
electron.ipcMain.on('compute-request:trashDirItems', (event, payload) => {
if (payload.items.length === 0) {
throw Error(`
Expand Down Expand Up @@ -563,9 +579,12 @@ function getTrayMenu () {
{
label: 'Toggle window visibility',
accelerator: globalShortcuts?.toggleApp?.shortcut || '',
click: () => {
global.toggleApp({type: 'tray'})
}
click: () => global.toggleApp({type: 'tray'})
},
{
label: 'Open global search',
accelerator: globalShortcuts?.openGlobalSearch?.shortcut || '',
click: () => global.openGlobalSearch()
},
{
label: 'Create new note',
Expand Down Expand Up @@ -660,6 +679,22 @@ global.toggleApp = (options = {}) => {
}
}

global.openGlobalSearch = () => {
if (windows.main) {
if (!windows.main.isFocused()) {
global.focusApp()
}
windows.main.webContents.send('open-global-search')
}
else {
global.focusApp()
windowLoadedCallbacks.mainWindow.push(() => {
global.focusApp()
windows.main.webContents.send('open-global-search')
})
}
}

function getCustomizedAppProperties (storageData) {
return {
openAtLogin: storageData['storageData.settings.appProperties.openAtLogin'] ?? true
Expand Down
10 changes: 10 additions & 0 deletions src/shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ export default {
shortcut: 'Ctrl + Shift + Space',
description: 'Open / close the app window'
},
openGlobalSearch: {
isGlobal: true,
isReadOnly: false,
conditions: {},
routes: ['all'],
icon: 'mdi-magnify',
action: {name: 'openGlobalSearch'},
shortcut: 'Alt + Ctrl + Shift + F',
description: 'Open global search'
},
newNote: {
isGlobal: true,
isReadOnly: false,
Expand Down

0 comments on commit e934410

Please sign in to comment.