diff --git a/src/main/lifeCycle/index.ts b/src/main/lifeCycle/index.ts index 466c01b0..0fbaff20 100644 --- a/src/main/lifeCycle/index.ts +++ b/src/main/lifeCycle/index.ts @@ -47,6 +47,24 @@ const defaultStartMode = { linux: ISartMode.MINI, } +const isPointInRect = (point: Electron.Point, rect: Electron.Rectangle) => + point.x >= rect.x && point.x < rect.x + rect.width && point.y >= rect.y && point.y < rect.y + rect.height + +const isLikelyDockActivation = () => { + if (process.platform !== 'darwin') return true + + const cursorPoint = screen.getCursorScreenPoint() + const display = screen.getDisplayNearestPoint(cursorPoint) + const isInWorkArea = isPointInRect(cursorPoint, display.workArea) + const isInMenuBar = + cursorPoint.y >= display.bounds.y && + cursorPoint.y < display.workArea.y && + cursorPoint.x >= display.workArea.x && + cursorPoint.x < display.workArea.x + display.workArea.width + + return !isInWorkArea && !isInMenuBar +} + const handleStartUpFiles = (argv: string[], cwd: string) => { const files = getUploadFiles(argv, cwd, logger) @@ -218,28 +236,18 @@ class LifeCycle { } #onRunning() { - let pendingActivateWindowTimer: ReturnType | null = null - app.on('second-instance', (_, commandLine, workingDirectory) => { logger.info('detect second instance') - if (pendingActivateWindowTimer !== null) { - clearTimeout(pendingActivateWindowTimer) - pendingActivateWindowTimer = null - } const result = handleStartUpFiles(commandLine, workingDirectory) + logger.info('handleStartUpFiles result:', String(result)) if (!result) { windowManager.create(IWindowList.SETTING_WINDOW) } }) app.on('activate', () => { - if (!windowManager.has(IWindowList.SETTING_WINDOW)) { - if (pendingActivateWindowTimer !== null) clearTimeout(pendingActivateWindowTimer) - pendingActivateWindowTimer = setTimeout(() => { - pendingActivateWindowTimer = null - if (!windowManager.has(IWindowList.SETTING_WINDOW)) { - windowManager.create(IWindowList.SETTING_WINDOW) - } - }, 300) + logger.info('activate is called') + if (!windowManager.has(IWindowList.SETTING_WINDOW) && isLikelyDockActivation()) { + windowManager.create(IWindowList.SETTING_WINDOW) } }) const storedAutoStartEnabled = picgo.getConfig(configPaths.settings.autoStart) || false diff --git a/src/main/server/index.ts b/src/main/server/index.ts index 147a2160..32cf43f2 100644 --- a/src/main/server/index.ts +++ b/src/main/server/index.ts @@ -90,8 +90,10 @@ class Server { } else { const remoteAddress = request.socket.remoteAddress || 'unknown' logger.info('[PicList Server] get a POST request from IP:', remoteAddress) + const isLocalRequest = + remoteAddress === '::1' || remoteAddress === '127.0.0.1' || remoteAddress === '::ffff:127.0.0.1' let urlSP = query ? new URLSearchParams(query) : undefined - if (remoteAddress === '::1' || remoteAddress === '127.0.0.1' || remoteAddress === '::ffff:127.0.0.1') { + if (isLocalRequest) { const serverKey = picgo.getConfig(configPaths.settings.serverKey) || '' if (urlSP) { urlSP.set('key', serverKey)