TidGi-Desktop/src/services/windows/interface.ts
lin onetwo 19ef74a4a6
Feat/mini window (#642)
* feat: new config for tidgi mini window

* chore: upgrade electron-forge

* fix: use 汉语 和 漢語

* feat: shortcut to open mini window

* test: TidGiMenubarWindow

* feat: allow updateWindowProperties on the fly

* fix: wrong icon path

* fix: log not showing error message and stack

* refactor: directly log error when using logger.error

* feat: shortcut to open window

* fix: menubar not closed

* test: e2e for menubar

* test: keyboard shortcut

* test: wiki web content, and refactor to files

* test: update command

* Update Testing.md

* test: menubar settings about menubarSyncWorkspaceWithMainWindow, menubarFixedWorkspaceId

* test: simplify menubar test and cleanup test config

* fix: view missing when execute several test all together

* refactor: use hook to cleanup menubar setting

* refactor: I clear test ai settings to before hook

* Add option to show title bar on menubar window

Introduces a new preference 'showMenubarWindowTitleBar' allowing users to toggle the title bar visibility on the menubar window. Updates related services, interfaces, and UI components to support this feature, and adds corresponding localization strings for English and Chinese.

* refactor: tidgiminiwindow

* refactor: preference keys to right order

* Refactor window dimension checks to use constants

Replaces hardcoded window dimensions with values from windowDimension and WindowNames constants for improved maintainability and consistency in window identification and checks.

* I cleanup test wiki

* Update defaultPreferences.ts

* test: mini window workspace switch

* fix: image broken by ai, and lint

* fix: can't switch to mini window

* refactor: useless todo

* Update index.ts

* refactor: reuse serialize-error

* Update index.ts

* Update testKeyboardShortcuts.ts

* refactor: dup logic

* Update ui.ts

* fix: electron-ipc-cat
2025-10-21 20:07:04 +08:00

96 lines
5 KiB
TypeScript

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<N extends WindowNames> {
/**
* 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<void>;
/** cleanup all window references for GC */
clearWindowsReference(): Promise<void>;
/**
* 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<void>;
findInPage(text: string, forward?: boolean): Promise<void>;
/** get window, this should not be called in renderer side */
get(windowName: WindowNames): BrowserWindow | undefined;
getWindowMeta<N extends WindowNames>(windowName: N): Promise<WindowMeta[N] | undefined>;
goBack(): Promise<void>;
goForward(): Promise<void>;
goHome(): Promise<void>;
/**
* Temporarily hide window, it will not be destroyed, and can be shown again very quick, with WebContentsView restored immediately.
*/
hide(windowName: WindowNames): Promise<void>;
isFullScreen(windowName?: WindowNames): Promise<boolean | undefined>;
isTidgiMiniWindowOpen(): Promise<boolean>;
loadURL(windowName: WindowNames, newUrl?: string): Promise<void>;
maximize(): Promise<void>;
/**
* 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<N extends WindowNames>(windowName: N, meta?: WindowMeta[N], config?: IWindowOpenConfig<N>): Promise<undefined>;
open<N extends WindowNames>(windowName: N, meta: WindowMeta[N] | undefined, config: IWindowOpenConfig<N> | undefined, returnWindow: true): Promise<BrowserWindow>;
open<N extends WindowNames>(windowName: N, meta?: WindowMeta[N], config?: IWindowOpenConfig<N>, returnWindow?: boolean): Promise<undefined | BrowserWindow>;
reload(windowName: WindowNames): Promise<void>;
requestRestart(): Promise<void>;
sendToAllWindows: (channel: Channels, ...arguments_: unknown[]) => Promise<void>;
/** 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<N extends WindowNames>(windowName: N, meta?: WindowMeta[N]): Promise<void>;
stopFindInPage(close?: boolean, windowName?: WindowNames): Promise<void>;
toggleTidgiMiniWindow(): Promise<void>;
updateWindowMeta<N extends WindowNames>(windowName: N, meta?: WindowMeta[N]): Promise<void>;
/** Open tidgi mini window without restart - hot reload. enableIt=true means fully enable and open. */
openTidgiMiniWindow(enableIt?: boolean, showWindow?: boolean): Promise<void>;
/** Close tidgi mini window. disableIt=true means fully disable and cleanup tray. */
closeTidgiMiniWindow(disableIt?: boolean): Promise<void>;
/** Update window properties without restart - hot reload */
updateWindowProperties(windowName: WindowNames, properties: { alwaysOnTop?: boolean }): Promise<void>;
/** React to preference changes related to windows (tidgi mini window etc.) */
reactWhenPreferencesChanged(key: string, value: unknown): Promise<void>;
}
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,
},
};