mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-16 13:03:31 +08:00
Electron was showing the main BrowserWindow before renderer load completed, so macOS could paint a blank window surface behind the menu bar. Persisted y=0 window state could also restore the titlebar under the menu-bar work area on external displays. Delay the initial show until the renderer entry is loaded, clamp restored macOS bounds into the display workArea, skip the macOS status-bar tray, and unhide the app before focusing restored windows. Constraint: macOS external displays expose menu-bar and status-item chrome differently from Windows and Linux. Rejected: Remove the native application menu | it would break expected macOS menu behavior without fixing the pre-load window surface. Confidence: high Scope-risk: narrow Directive: Do not reintroduce pre-load main-window show without validating macOS external-display menu-bar rendering. Tested: cd desktop && bun test electron/services/windows.test.ts electron/services/tray.test.ts electron/services/singleInstance.test.ts electron/services/menu.test.ts Tested: bun run check:desktop Tested: bun run check:native Tested: git diff --check Not-tested: Live dual-external-monitor screenshot smoke.
25 lines
540 B
TypeScript
25 lines
540 B
TypeScript
import type { App, BrowserWindow } from 'electron'
|
|
import { showMainWindow } from './windows'
|
|
|
|
export function acquireSingleInstanceLock(
|
|
app: App,
|
|
getMainWindow: () => BrowserWindow | null,
|
|
env: NodeJS.ProcessEnv = process.env,
|
|
): boolean {
|
|
if (env.CC_HAHA_ELECTRON_DISABLE_SINGLE_INSTANCE_LOCK === '1') {
|
|
return true
|
|
}
|
|
|
|
const hasLock = app.requestSingleInstanceLock()
|
|
if (!hasLock) {
|
|
app.quit()
|
|
return false
|
|
}
|
|
|
|
app.on('second-instance', () => {
|
|
showMainWindow(getMainWindow(), app)
|
|
})
|
|
|
|
return true
|
|
}
|