fix: quick app bugs (#2327)

This commit is contained in:
Louis 2024-03-12 17:25:50 +07:00 committed by GitHub
parent f4f1888468
commit b9b421a495
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 35 additions and 31 deletions

View File

@ -43,6 +43,12 @@ const gotTheLock = app.requestSingleInstanceLock()
app
.whenReady()
.then(() => {
if (!gotTheLock) {
app.quit()
throw new Error('Another instance of the app is already running')
}
})
.then(setupReactDevTool)
.then(setupCore)
.then(createUserSpace)
@ -63,22 +69,20 @@ app
log(`Version: ${app.getVersion()}`)
})
.then(() => {
if (!gotTheLock) {
app.quit()
} else {
app.on('second-instance', (_event, _commandLine, _workingDirectory) => {
// Someone tried to run a second instance, we should focus our window.
windowManager.showMainWindow()
})
}
app.on('activate', () => {
if (!BrowserWindow.getAllWindows().length) {
createMainWindow()
} else {
windowManager.showMainWindow()
}
})
})
.then(() => cleanLogs())
app.on('second-instance', (_event, _commandLine, _workingDirectory) => {
windowManager.showMainWindow()
})
app.on('ready', () => {
registerGlobalShortcuts()
})

View File

@ -5,7 +5,7 @@ export const mainWindowConfig: Electron.BrowserWindowConstructorOptions = {
width: DEFAULT_WIDTH,
minWidth: DEFAULT_WIDTH,
height: DEFAULT_HEIGHT,
skipTaskbar: true,
skipTaskbar: false,
show: true,
trafficLightPosition: {
x: 10,

View File

@ -13,20 +13,28 @@ class TrayManager {
const tray = new Tray(iconPath)
tray.setToolTip(app.getName())
const contextMenu = Menu.buildFromTemplate([
{
label: 'Open Jan',
type: 'normal',
click: () => windowManager.showMainWindow(),
},
{
label: 'Open Quick Ask',
type: 'normal',
click: () => windowManager.showQuickAskWindow(),
},
{ label: 'Quit', type: 'normal', click: () => app.quit() },
])
tray.setContextMenu(contextMenu)
tray.on('click', () => {
windowManager.showQuickAskWindow()
})
// Add context menu for windows only
if (process.platform === 'win32') {
const contextMenu = Menu.buildFromTemplate([
{
label: 'Open Jan',
type: 'normal',
click: () => windowManager.showMainWindow(),
},
{
label: 'Open Quick Ask',
type: 'normal',
click: () => windowManager.showQuickAskWindow(),
},
{ label: 'Quit', type: 'normal', click: () => app.quit() },
])
tray.setContextMenu(contextMenu)
}
this.currentTray = tray
}

View File

@ -73,15 +73,11 @@ class WindowManager {
hideMainWindow(): void {
this.mainWindow?.hide()
this._mainWindowVisible = false
// Only macos
if (process.platform === 'darwin') app.dock.hide()
}
showMainWindow(): void {
this.mainWindow?.show()
this._mainWindowVisible = true
// Only macos
if (process.platform === 'darwin') app.dock.show()
}
hideQuickAskWindow(): void {

View File

@ -24,10 +24,6 @@ export default function KeyListener({ children }: Props) {
useEffect(() => {
const onKeyDown = (e: KeyboardEvent) => {
if (e.key === 'Escape') {
window.core?.api?.hideMainWindow()
}
const prefixKey = isMac ? e.metaKey : e.ctrlKey
if (e.key === 'b' && prefixKey) {