fix: quick ask could not register global shortcuts (#2642)
This commit is contained in:
parent
815a7aef96
commit
c5c3156b28
@ -26,9 +26,9 @@ import { setupCore } from './utils/setup'
|
|||||||
import { setupReactDevTool } from './utils/dev'
|
import { setupReactDevTool } from './utils/dev'
|
||||||
import { cleanLogs } from './utils/log'
|
import { cleanLogs } from './utils/log'
|
||||||
|
|
||||||
import { registerShortcut } from './utils/selectedText'
|
|
||||||
import { trayManager } from './managers/tray'
|
import { trayManager } from './managers/tray'
|
||||||
import { logSystemInfo } from './utils/system'
|
import { logSystemInfo } from './utils/system'
|
||||||
|
import { registerGlobalShortcuts } from './utils/shortcut'
|
||||||
|
|
||||||
const preloadPath = join(__dirname, 'preload.js')
|
const preloadPath = join(__dirname, 'preload.js')
|
||||||
const rendererPath = join(__dirname, '..', 'renderer')
|
const rendererPath = join(__dirname, '..', 'renderer')
|
||||||
@ -38,8 +38,6 @@ const mainPath = join(rendererPath, 'index.html')
|
|||||||
const mainUrl = 'http://localhost:3000'
|
const mainUrl = 'http://localhost:3000'
|
||||||
const quickAskUrl = `${mainUrl}/search`
|
const quickAskUrl = `${mainUrl}/search`
|
||||||
|
|
||||||
const quickAskHotKey = 'CommandOrControl+J'
|
|
||||||
|
|
||||||
const gotTheLock = app.requestSingleInstanceLock()
|
const gotTheLock = app.requestSingleInstanceLock()
|
||||||
|
|
||||||
app
|
app
|
||||||
@ -60,6 +58,7 @@ app
|
|||||||
.then(handleAppUpdates)
|
.then(handleAppUpdates)
|
||||||
.then(() => process.env.CI !== 'e2e' && createQuickAskWindow())
|
.then(() => process.env.CI !== 'e2e' && createQuickAskWindow())
|
||||||
.then(createMainWindow)
|
.then(createMainWindow)
|
||||||
|
.then(registerGlobalShortcuts)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (!app.isPackaged) {
|
if (!app.isPackaged) {
|
||||||
windowManager.mainWindow?.webContents.openDevTools()
|
windowManager.mainWindow?.webContents.openDevTools()
|
||||||
@ -82,12 +81,6 @@ app.on('second-instance', (_event, _commandLine, _workingDirectory) => {
|
|||||||
windowManager.showMainWindow()
|
windowManager.showMainWindow()
|
||||||
})
|
})
|
||||||
|
|
||||||
app.on('ready', () => {
|
|
||||||
if (!getAppConfigurations().quick_ask) return
|
|
||||||
|
|
||||||
registerGlobalShortcuts()
|
|
||||||
})
|
|
||||||
|
|
||||||
app.on('before-quit', function (evt) {
|
app.on('before-quit', function (evt) {
|
||||||
trayManager.destroyCurrentTray()
|
trayManager.destroyCurrentTray()
|
||||||
})
|
})
|
||||||
@ -118,23 +111,6 @@ function createMainWindow() {
|
|||||||
windowManager.createMainWindow(preloadPath, startUrl)
|
windowManager.createMainWindow(preloadPath, startUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
function registerGlobalShortcuts() {
|
|
||||||
const ret = registerShortcut(quickAskHotKey, (selectedText: string) => {
|
|
||||||
// Feature Toggle for Quick Ask
|
|
||||||
if (!windowManager.isQuickAskWindowVisible()) {
|
|
||||||
windowManager.showQuickAskWindow()
|
|
||||||
windowManager.sendQuickAskSelectedText(selectedText)
|
|
||||||
} else {
|
|
||||||
windowManager.hideQuickAskWindow()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!ret) {
|
|
||||||
console.error('Global shortcut registration failed')
|
|
||||||
} else {
|
|
||||||
console.log('Global shortcut registered successfully')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles various IPC messages from the renderer process.
|
* Handles various IPC messages from the renderer process.
|
||||||
|
|||||||
24
electron/utils/shortcut.ts
Normal file
24
electron/utils/shortcut.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import { getAppConfigurations } from '@janhq/core/node'
|
||||||
|
import { registerShortcut } from './selectedText'
|
||||||
|
import { windowManager } from '../managers/window'
|
||||||
|
// TODO: Retrieve from config later
|
||||||
|
const quickAskHotKey = 'CommandOrControl+J'
|
||||||
|
|
||||||
|
export function registerGlobalShortcuts() {
|
||||||
|
if (!getAppConfigurations().quick_ask) return
|
||||||
|
const ret = registerShortcut(quickAskHotKey, (selectedText: string) => {
|
||||||
|
// Feature Toggle for Quick Ask
|
||||||
|
if (!windowManager.isQuickAskWindowVisible()) {
|
||||||
|
windowManager.showQuickAskWindow()
|
||||||
|
windowManager.sendQuickAskSelectedText(selectedText)
|
||||||
|
} else {
|
||||||
|
windowManager.hideQuickAskWindow()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!ret) {
|
||||||
|
console.error('Global shortcut registration failed')
|
||||||
|
} else {
|
||||||
|
console.log('Global shortcut registered successfully')
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user