feat: remove getCurrentWindowId IPC event and related functionality for cleaner API

This commit is contained in:
duanshuwen
2026-04-21 22:37:32 +08:00
parent f9c331315b
commit 97a956ffe8
11 changed files with 5 additions and 105 deletions

View File

@@ -2,7 +2,7 @@ import { useSyncExternalStore } from 'react';
import { CONFIG_KEYS, DEFAULT_LANGUAGE, DEFAULT_THEME_MODE, IPC_EVENTS } from '../lib/constants';
import { hasHostApiBridge, hostApiFetch, invokeIpc, onIpc } from '../lib/host-api';
import { applyThemeModeToDocument, detectSystemTheme, resolveAppliedTheme, watchSystemTheme } from '../lib/theme';
import { detectRuntimePlatform, resolveWindowIdentity } from '../lib/runtime';
import { detectRuntimePlatform } from '../lib/runtime';
import { i18n, setLocale as setI18nLocale } from '../i18n';
import { detectSystemLanguage, resolveSupportedLanguage } from '../i18n/resolver';
import type {
@@ -11,15 +11,11 @@ import type {
ResolvedThemeMode,
RuntimePlatform,
ThemeMode,
WindowIdentity,
WindowName,
} from '../types/runtime';
export interface SettingsState {
initialized: boolean;
platform: RuntimePlatform;
windowId: string | number | null;
windowName: WindowName;
themeMode: ThemeMode;
systemTheme: ResolvedThemeMode;
appliedTheme: ResolvedThemeMode;
@@ -64,8 +60,6 @@ function createInitialState(): SettingsState {
return {
initialized: false,
platform: detectRuntimePlatform(),
windowId: null,
windowName: 'main',
themeMode: DEFAULT_THEME_MODE,
systemTheme,
appliedTheme: resolveAppliedTheme(DEFAULT_THEME_MODE, systemTheme),
@@ -180,16 +174,6 @@ function syncSystemTheme(): void {
});
}
async function syncWindowIdentity(): Promise<WindowIdentity> {
const identity = await resolveWindowIdentity();
patchState({
platform: identity.platform,
windowId: identity.windowId,
windowName: identity.windowName,
});
return identity;
}
async function syncThemeEvent(): Promise<void> {
if (unsubscribeThemeEvent || typeof window === 'undefined' || !window.api?.on) return;
@@ -207,7 +191,7 @@ async function hydrate(): Promise<SettingsState> {
if (initPromise) return initPromise;
initPromise = (async () => {
const identity = await syncWindowIdentity();
const platform = detectRuntimePlatform();
const systemTheme = detectSystemTheme();
const systemLanguage = detectSystemLanguage();
@@ -228,9 +212,7 @@ async function hydrate(): Promise<SettingsState> {
patchState({
initialized: true,
platform: identity.platform,
windowId: identity.windowId,
windowName: identity.windowName,
platform,
themeMode,
systemTheme,
appliedTheme,