import { Channels, WindowChannel } from '@/constants/channels'; import { BrowserWindow } from 'electron'; import { ProxyPropertyType } from 'electron-ipc-cat/common'; import { WindowMeta, WindowNames } from './WindowProperties'; export interface IWindowOpenConfig { /** * Allow multiple window with same name */ multiple?: boolean; /** * If recreate is true, we will close the window if it is already opened, and create a new one. */ recreate?: boolean | ((windowMeta: WindowMeta[N]) => boolean); } /** * Create and manage window open and destroy, you can get all opened electron window instance here */ export interface IWindowService { clearStorageData(workspaceID: string, windowName?: WindowNames): Promise; /** cleanup all window references for GC */ clearWindowsReference(): Promise; /** * Completely close a window, destroy its all state and WebContentsView. Need more time to restore. Use `hide` if you want to hide it temporarily. */ close(windowName: WindowNames): Promise; findInPage(text: string, forward?: boolean): Promise; /** get window, this should not be called in renderer side */ get(windowName: WindowNames): BrowserWindow | undefined; getWindowMeta(windowName: N): Promise; goBack(): Promise; goForward(): Promise; goHome(): Promise; /** * Temporarily hide window, it will not be destroyed, and can be shown again very quick, with WebContentsView restored immediately. */ hide(windowName: WindowNames): Promise; isFullScreen(windowName?: WindowNames): Promise; isTidgiMiniWindowOpen(): Promise; loadURL(windowName: WindowNames, newUrl?: string): Promise; maximize(): Promise; /** * Create a new window. Handles setup of window configs. * See `src/services/windows/handleCreateBasicWindow.ts` for `new BrowserWindow` process. * @param returnWindow Return created window or not. Usually false, so this method can be call IPC way (because window will cause `Failed to serialize arguments`). */ open(windowName: N, meta?: WindowMeta[N], config?: IWindowOpenConfig): Promise; open(windowName: N, meta: WindowMeta[N] | undefined, config: IWindowOpenConfig | undefined, returnWindow: true): Promise; open(windowName: N, meta?: WindowMeta[N], config?: IWindowOpenConfig, returnWindow?: boolean): Promise; reload(windowName: WindowNames): Promise; requestRestart(): Promise; sendToAllWindows: (channel: Channels, ...arguments_: unknown[]) => Promise; /** set window or delete window object by passing undefined (will not close it, only remove reference), this should not be called in renderer side */ set(windowName: WindowNames, win: BrowserWindow | undefined): void; setWindowMeta(windowName: N, meta?: WindowMeta[N]): Promise; stopFindInPage(close?: boolean, windowName?: WindowNames): Promise; toggleTidgiMiniWindow(): Promise; updateWindowMeta(windowName: N, meta?: WindowMeta[N]): Promise; /** Open tidgi mini window without restart - hot reload. enableIt=true means fully enable and open. */ openTidgiMiniWindow(enableIt?: boolean, showWindow?: boolean): Promise; /** Close tidgi mini window. disableIt=true means fully disable and cleanup tray. */ closeTidgiMiniWindow(disableIt?: boolean): Promise; /** Update window properties without restart - hot reload */ updateWindowProperties(windowName: WindowNames, properties: { alwaysOnTop?: boolean }): Promise; /** React to preference changes related to windows (tidgi mini window etc.) */ reactWhenPreferencesChanged(key: string, value: unknown): Promise; } export const WindowServiceIPCDescriptor = { channel: WindowChannel.name, properties: { clearStorageData: ProxyPropertyType.Function, close: ProxyPropertyType.Function, findInPage: ProxyPropertyType.Function, get: ProxyPropertyType.Function, getWindowMeta: ProxyPropertyType.Function, goBack: ProxyPropertyType.Function, goForward: ProxyPropertyType.Function, goHome: ProxyPropertyType.Function, isFullScreen: ProxyPropertyType.Function, isTidgiMiniWindowOpen: ProxyPropertyType.Function, loadURL: ProxyPropertyType.Function, maximize: ProxyPropertyType.Function, open: ProxyPropertyType.Function, reload: ProxyPropertyType.Function, requestRestart: ProxyPropertyType.Function, sendToAllWindows: ProxyPropertyType.Function, setWindowMeta: ProxyPropertyType.Function, stopFindInPage: ProxyPropertyType.Function, toggleTidgiMiniWindow: ProxyPropertyType.Function, updateWindowMeta: ProxyPropertyType.Function, openTidgiMiniWindow: ProxyPropertyType.Function, closeTidgiMiniWindow: ProxyPropertyType.Function, updateWindowProperties: ProxyPropertyType.Function, }, };