fix(window): don't steal focus when the app starts at login
The login item now passes --autostart (also used when querying it, which Windows needs to match the registration). On such a launch the main window is shown inactive instead of focused, flashed and pinned on top for a second, so typing that already started in another app is not interrupted. Existing registrations migrate on the next startup sync.
This commit is contained in:
parent
e7937c877f
commit
ddd734fd30
3 changed files with 67 additions and 15 deletions
|
|
@ -7,13 +7,26 @@ import { configGet, configSet } from './ConfigService'
|
|||
|
||||
const logger = getLogger('AutoLaunchService')
|
||||
|
||||
/** 로그인 자동 실행으로 켜졌다는 표시 — 이때는 창을 띄우되 사용자가 쓰던 창의 포커스를 뺏지 않는다. */
|
||||
export const AUTOSTART_ARG = '--autostart'
|
||||
|
||||
export function launchedAtLogin(argv: readonly string[] = process.argv): boolean {
|
||||
return argv.includes(AUTOSTART_ARG)
|
||||
}
|
||||
|
||||
/** Windows 는 같은 args 로 조회해야 등록 여부를 맞게 돌려준다 — 등록·조회가 같은 값을 쓴다. */
|
||||
function loginItemArgs(): string[] {
|
||||
// 개발 모드에서는 electron.exe 경로가 등록되므로 앱 경로를 함께 넘긴다
|
||||
return app.isPackaged ? [AUTOSTART_ARG] : [app.getAppPath(), AUTOSTART_ARG]
|
||||
}
|
||||
|
||||
class AutoLaunchService {
|
||||
/**
|
||||
* 현재 자동 실행 설정 상태를 조회한다.
|
||||
*/
|
||||
isEnabled(): boolean {
|
||||
// Electron API로 실제 OS 설정 확인
|
||||
const settings = app.getLoginItemSettings()
|
||||
const settings = app.getLoginItemSettings({ args: loginItemArgs() })
|
||||
return settings.openAtLogin
|
||||
}
|
||||
|
||||
|
|
@ -25,8 +38,7 @@ class AutoLaunchService {
|
|||
app.setLoginItemSettings({
|
||||
openAtLogin: enabled,
|
||||
// Windows: 시작 프로그램에 등록
|
||||
// 개발 모드에서는 electron.exe 경로가 등록되므로 주의
|
||||
args: app.isPackaged ? [] : [app.getAppPath()]
|
||||
args: loginItemArgs()
|
||||
})
|
||||
|
||||
configSet('autoLaunch', enabled)
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ import {
|
|||
} from './popup-window-factory'
|
||||
import { createElectronScreenGeometry } from './screen-geometry'
|
||||
import { installApplicationMenu } from './app-menu'
|
||||
import { launchedAtLogin } from '../services/AutoLaunchService'
|
||||
import {
|
||||
SUGGESTION_OVERLAY_MAX_HEIGHT,
|
||||
SUGGESTION_OVERLAY_WIDTH,
|
||||
|
|
@ -247,6 +248,7 @@ export function createMainWindow(): BrowserWindow {
|
|||
const initWidth = Math.min(WINDOW_SIZE.MAIN.width, screenWidth)
|
||||
const initHeight = Math.min(WINDOW_SIZE.MAIN.height, screenHeight)
|
||||
|
||||
const quietLaunch = launchedAtLogin()
|
||||
mainWindow = new BrowserWindow({
|
||||
title: 'D3RO Voice',
|
||||
width: initWidth,
|
||||
|
|
@ -255,7 +257,8 @@ export function createMainWindow(): BrowserWindow {
|
|||
y: Math.max(0, Math.round((screenHeight - initHeight) / 2)),
|
||||
minWidth: 800,
|
||||
minHeight: 600,
|
||||
show: true,
|
||||
// 로그인 자동 실행이면 아래에서 포커스 없이 띄운다 — 막 입력을 시작한 사용자의 창을 뺏지 않게.
|
||||
show: !quietLaunch,
|
||||
autoHideMenuBar: true,
|
||||
// 보더리스: 렌더러의 커스텀 TitleBar(AppLayout 최상단)가 크롬을 대체한다.
|
||||
// macOS는 hiddenInset으로 네이티브 교통신호(traffic lights)를 콘텐츠 위에
|
||||
|
|
@ -282,6 +285,11 @@ export function createMainWindow(): BrowserWindow {
|
|||
installApplicationMenu(Menu, process.platform)
|
||||
|
||||
mainWindow.on('ready-to-show', () => {
|
||||
if (quietLaunch) {
|
||||
mainWindow?.showInactive()
|
||||
logger.info('Main window shown without focus (launched at login)')
|
||||
return
|
||||
}
|
||||
mainWindow?.show()
|
||||
mainWindow?.restore()
|
||||
mainWindow?.focus()
|
||||
|
|
@ -325,17 +333,19 @@ export function createMainWindow(): BrowserWindow {
|
|||
}
|
||||
|
||||
mainWindow.center()
|
||||
mainWindow.restore()
|
||||
mainWindow.show()
|
||||
mainWindow.focus()
|
||||
mainWindow.setAlwaysOnTop(true)
|
||||
setTimeout(() => {
|
||||
try {
|
||||
mainWindow?.setAlwaysOnTop(false)
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}, 1000)
|
||||
if (!quietLaunch) {
|
||||
mainWindow.restore()
|
||||
mainWindow.show()
|
||||
mainWindow.focus()
|
||||
mainWindow.setAlwaysOnTop(true)
|
||||
setTimeout(() => {
|
||||
try {
|
||||
mainWindow?.setAlwaysOnTop(false)
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
logger.info('Main window created')
|
||||
return mainWindow
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue