mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-06-21 07:33:54 +08:00
Fix typora macos (#542)
* 🔨 Refactor(custom): add debug log * 🐛 Fix(custom): fix active enent with typora
This commit is contained in:
@@ -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<typeof setTimeout> | 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<boolean>(configPaths.settings.autoStart) || false
|
||||
|
||||
@@ -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<string>(configPaths.settings.serverKey) || ''
|
||||
if (urlSP) {
|
||||
urlSP.set('key', serverKey)
|
||||
|
||||
Reference in New Issue
Block a user