Appearance
AppConfig
createApp()에 전달하는 설정 객체의 필드별 상세 설명.
ts
interface AppConfig<Cs, W extends WindowKinds> {
ipc: IpcManifest<Cs, W>
windows: WindowsPolicy<W>
modules: Constructor[]
guards?: IpcGuard[]
pipes?: IpcPipe[]
exceptionHandler?: IpcExceptionHandler
logger?: AppLogger
onError?: (name: string, error: unknown) => void
}필수 필드
ipc
ts
ipc: IpcManifest // shared의 defineIpc({ contracts, windows }) 결과앱의 IPC 선언. contract 목록과 창 목록의 출처다. 같은 객체를 preload의 exposeBridge(ipc)와 렌더러의 createService(ipc)에도 넘긴다.
ipc.windows의 키가 창 이름이고main은 필수다 —start()에서 프레임워크가 연다. 값은 ElectronBrowserWindowConstructorOptions에show: 'ready'를 더한WindowDef이며, 앱이 쓸 추가 속성(route등)을 얹을 수 있다ipc.contracts에 있는데 바인딩된 컨트롤러가 없는 contract는 부트스트랩 에러다
windows
ts
windows: {
defaults?: WindowDef // 모든 창 공통 옵션 (얕은 병합, 창별 선언이 우선)
load: (window, kind, def) => void // 창을 만든 뒤 무엇을 로드할지
}메인만 아는 창 정책. 창 목록 자체는 ipc.windows(shared)에 있고, 여기에는 preload 경로처럼 메인 프로세스에서만 의미 있는 것과 로드 규칙을 둔다. URL 규칙(dev 서버·파일 경로·라우트)은 앱마다 달라 프레임워크가 정하지 않는다.
ts
// shared/ipc.ts
windows: {
main: { width: 1200, height: 800, route: '/' },
settings: { width: 750, height: 500, route: '/settings' },
}
// main
windows: {
defaults: { show: 'ready', webPreferences: { preload, contextIsolation: true } },
load: (win, kind, def) => win.loadFile('index.html', { hash: def.route }),
}show: 'ready'면 숨긴 채 만들고 첫 화면이 준비되면(ready-to-show) 보여준다 — 빈 창이 먼저 뜨는 것을 프레임워크가 막는다. 창 선언에 얹은 추가 속성(위의 route)은 그대로 load의 def로 전달된다. 창 종류는 프레임워크가 preload 프로세스 인자로 심어 주므로(service.window.self) URL에 실을 필요가 없다. 창 이름을 타입으로 좁히려면 Register에 등록한다(선택).
창 생성·하나만 열기·메인 창 닫힐 때 서브 창 정리는 프레임워크의 WindowRegistry가 맡는다. 서비스는 inject(WindowRegistry)로 받아 open('settings')처럼 쓴다.
modules
ts
modules: Constructor[]@Module() 데코레이터가 적용된 모듈 클래스 배열. 배열 순서가 provider 등록 순서를 결정한다.
모듈 A의 provider가 모듈 B의 provider를 inject()하려면 모듈 B가 먼저 나열되어야 한다:
ts
modules: [
CoreModule, // 먼저 등록
FeatureModule, // CoreModule의 provider를 inject 가능
]선택 필드
guards
ts
guards?: IpcGuard[]기본값: []
IPC 요청을 검증하는 Guard 인스턴스 배열. 배열 순서대로 canActivate()를 실행하며, 하나라도 false를 반환하면 요청을 거부한다.
ts
guards: [new SenderGuard(), new RateLimitGuard()]sendGuards
ts
sendGuards?: IpcGuard[]기본값: 없음 — contract에 sends가 있으면 필수 (없으면 부트스트랩 에러)
send 채널(렌더러 → 메인 단방향) 전용 Guard 배열. 발신자 정책이 handle과 반대라 별도로 받는다 — handle은 앱 창(SenderGuard), send는 보통 게스트 뷰(GuestViewGuard)가 발신자다. send는 응답 경로가 없으므로 Guard 거부·schema 실패·핸들러 예외 모두 버려지고 onError로만 보고된다.
ts
sendGuards: [new GuestViewGuard()]pipes
ts
pipes?: IpcPipe[]기본값: []
IPC 인자를 변환하거나 검증하는 Pipe 인스턴스 배열. Guard 통과 후, 핸들러 실행 전에 배열 순서대로 transform()을 실행한다. 각 Pipe의 반환값이 다음 Pipe의 입력이 된다.
글로벌 Pipe는 모든 IPC 요청에 적용된다. 특정 핸들러에만 적용하려면 @UsePipes() 데코레이터를 사용한다.
ts
pipes: [new NormalizePipe()]Pipe에서 throw하면 ExceptionHandler가 처리한다. Zod의 parse() 실패 등이 자연스럽게 에러 응답이 된다.
exceptionHandler
ts
exceptionHandler?: IpcExceptionHandler기본값: undefined
Guard 실패 또는 핸들러 에러를 처리하는 단일 ExceptionHandler. Guard가 실패하거나 핸들러에서 에러가 발생하면 catch()가 호출된다. catch()는 IpcError ({ code, message })를 반환하고, 프레임워크가 { ok: false, error } 형태의 IpcResponse로 래핑하여 렌더러에 전달한다.
handler가 없으면 프레임워크가 기본 IpcError를 생성한다 (Guard 실패 시 UNAUTHORIZED, 핸들러 에러 시 INTERNAL_ERROR).
ts
exceptionHandler: new ErrorHandler()logger
ts
logger?: AppLogger기본값: undefined (로깅 없음)
부트스트랩 과정의 로그를 출력하는 로거. info() 메서드만 요구한다.
ts
interface AppLogger {
info(message: string): void
}ts
logger: {
info: (msg) => console.log(`[ipc] ${msg}`),
}로깅 내용:
- 창 열림·닫힘 (
Window opened: <kind>/Window closed: <kind>) - 부트스트랩 완료
onError
ts
onError?: (name: string, error: unknown) => void기본값: undefined
Lifecycle 메서드(onInit, @OnWindow 훅, onDispose) 실행 중 에러가 발생했을 때 호출되는 콜백. 에러가 발생해도 나머지 provider의 lifecycle은 계속 실행된다.
ts
onError: (name, error) => {
logger.error(`Lifecycle error in ${name}:`, error);
}name은 에러가 발생한 provider 클래스의 이름이다.