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 app
.whenReady() .whenReady()
.then(() => {
if (!gotTheLock) {
app.quit()
throw new Error('Another instance of the app is already running')
}
})
.then(setupReactDevTool) .then(setupReactDevTool)
.then(setupCore) .then(setupCore)
.then(createUserSpace) .then(createUserSpace)
@ -63,22 +69,20 @@ app
log(`Version: ${app.getVersion()}`) log(`Version: ${app.getVersion()}`)
}) })
.then(() => { .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', () => { app.on('activate', () => {
if (!BrowserWindow.getAllWindows().length) { if (!BrowserWindow.getAllWindows().length) {
createMainWindow() createMainWindow()
} else {
windowManager.showMainWindow()
} }
}) })
}) })
.then(() => cleanLogs()) .then(() => cleanLogs())
app.on('second-instance', (_event, _commandLine, _workingDirectory) => {
windowManager.showMainWindow()
})
app.on('ready', () => { app.on('ready', () => {
registerGlobalShortcuts() registerGlobalShortcuts()
}) })

View File

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

View File

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

View File

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

View File

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