feat: prepare Zhinian desktop client for pilot release

This commit is contained in:
inman
2026-04-29 10:23:20 +08:00
parent f9361e686a
commit 47b83b79fc
149 changed files with 15341 additions and 3590 deletions

View File

@@ -3,6 +3,10 @@
* Exposes safe APIs to the renderer process via contextBridge
*/
import { contextBridge, ipcRenderer } from 'electron';
import type {
YinianLoginWithPasswordInput,
YinianLoginWithSmsInput,
} from '../../shared/yinian';
/**
* IPC renderer methods exposed to the renderer process
@@ -45,6 +49,22 @@ const electronAPI = {
'app:quit',
'app:relaunch',
'app:request',
// YINIAN
'yinian:auth:restoreSession',
'yinian:auth:createImageCaptcha',
'yinian:auth:getSessionState',
'yinian:auth:loginWithSms',
'yinian:auth:loginWithPassword',
'yinian:auth:logout',
'yinian:auth:getSavedCredentials',
'yinian:auth:saveCredentials',
'yinian:auth:clearSavedCredentials',
'yinian:config:get',
'yinian:hotel:switch',
'yinian:skills:sync',
'yinian:skills:listLocal',
'yinian:skills:getRegistry',
'yinian:server:status',
// Window controls
'window:minimize',
'window:maximize',
@@ -266,8 +286,35 @@ const electronAPI = {
isDev: process.env.NODE_ENV === 'development' || !!process.env.VITE_DEV_SERVER_URL,
};
const yinianAPI = {
auth: {
createImageCaptcha: (randomStr?: string) => ipcRenderer.invoke('yinian:auth:createImageCaptcha', randomStr),
restoreSession: () => ipcRenderer.invoke('yinian:auth:restoreSession'),
getSessionState: () => ipcRenderer.invoke('yinian:auth:getSessionState'),
loginWithSms: (input: YinianLoginWithSmsInput) => ipcRenderer.invoke('yinian:auth:loginWithSms', input),
loginWithPassword: (input: YinianLoginWithPasswordInput) => ipcRenderer.invoke('yinian:auth:loginWithPassword', input),
logout: () => ipcRenderer.invoke('yinian:auth:logout'),
getSavedCredentials: () => ipcRenderer.invoke('yinian:auth:getSavedCredentials'),
saveCredentials: (input: Pick<import('../../shared/yinian').YinianSavedCredentials, 'account' | 'password' | 'rememberPassword'>) => ipcRenderer.invoke('yinian:auth:saveCredentials', input),
clearSavedCredentials: () => ipcRenderer.invoke('yinian:auth:clearSavedCredentials'),
},
app: {
getServerStatus: () => ipcRenderer.invoke('yinian:server:status'),
getConfig: () => ipcRenderer.invoke('yinian:config:get'),
switchHotel: (hotelId: string) => ipcRenderer.invoke('yinian:hotel:switch', hotelId),
switchWorkspace: (workspaceId: string) => ipcRenderer.invoke('yinian:hotel:switch', workspaceId),
},
skills: {
sync: () => ipcRenderer.invoke('yinian:skills:sync'),
listLocal: () => ipcRenderer.invoke('yinian:skills:listLocal'),
getRegistry: (hotelId?: string) => ipcRenderer.invoke('yinian:skills:getRegistry', hotelId),
},
};
// Expose the API to the renderer process
contextBridge.exposeInMainWorld('electron', electronAPI);
contextBridge.exposeInMainWorld('yinian', yinianAPI);
// Type declarations for the renderer process
export type ElectronAPI = typeof electronAPI;
export type YinianAPI = typeof yinianAPI;