@longzai-intelligence-electron/core 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +9 -0
- package/dist/index.js +1 -1
- package/package.json +1 -2
package/dist/index.d.ts
CHANGED
|
@@ -351,6 +351,14 @@ type WindowOptions = {
|
|
|
351
351
|
* 是否启用 DevTools(开发环境)
|
|
352
352
|
*/
|
|
353
353
|
devTools?: boolean;
|
|
354
|
+
/**
|
|
355
|
+
* 预载脚本绝对路径,缺省按应用根的 out/preload 布局探测 cjs 与 mjs 两种产物
|
|
356
|
+
*/
|
|
357
|
+
preloadPath?: string;
|
|
358
|
+
/**
|
|
359
|
+
* 渲染产物入口绝对路径,缺省取应用根的 out/renderer/index.html
|
|
360
|
+
*/
|
|
361
|
+
rendererPath?: string;
|
|
354
362
|
/**
|
|
355
363
|
* 额外的 BrowserWindow 选项
|
|
356
364
|
*/
|
|
@@ -404,6 +412,7 @@ declare function getMainWindow(): BrowserWindow | null;
|
|
|
404
412
|
* 注册窗口控制 IPC 处理器
|
|
405
413
|
*
|
|
406
414
|
* 注册以下窗口控制处理器:
|
|
415
|
+
*
|
|
407
416
|
* - window-minimize: 最小化窗口
|
|
408
417
|
* - window-maximize: 最大化/还原窗口
|
|
409
418
|
* - window-close: 关闭窗口
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./rolldown-runtime-BqT_7tdF.js";import{t as e}from"./ipc.schema-CRktvhDm.js";import{BrowserWindow as t,ipcMain as n,session as r,shell as i}from"electron";import*as a from"zod";import{defineEnumSchema as o}from"@longzai-intelligence-zod/utils";import{createNodeLogger as s}from"@longzai-intelligence-logger/node";import{join as c,resolve as l}from"node:path";const u=new Set([`operation`,`channel`,`handler`,`module`,`feature`,`action`,`phase`,`stage`,`scope`,`type`,`reason`,`status`,`code`,`count`,`total`,`size`,`limit`,`offset`,`attempt`,`retry`]),d=/(stack|trace|path|token|secret|password|key|sql|query|prompt|content|raw|payload)/i;function f(){return process.env.NODE_ENV===`development`}function p(e){return e===null||[`string`,`number`,`boolean`].includes(typeof e)}function ee(e){return d.test(e)?!1:u.has(e)?!0:/(?:^|_)(?:id|uuid)$/i.test(e)||/(?:Id|UUID|Uuid)$/.test(e)}function te(e){if(e===void 0)return;if(f())return e;let t={};for(let[n,r]of Object.entries(e))if(ee(n)){if(p(r)){t[n]=r;continue}Array.isArray(r)&&r.every(p)&&(t[n]=r.slice(0,20))}return Object.keys(t).length>0?t:void 0}function ne(e){return e===void 0?{success:!0}:{success:!0,data:e}}function re(e,t,n){let r={code:e,message:t},i=te(n);return i!==void 0&&(r.details=i),{success:!1,error:r}}function m(e){return e.success===!0}function h(e){return e.success===!1}function g(e,t){if(m(e))return e.data;let n=e.error?.code?`[${e.error.code}] `:``,r=e.error?.message??t;throw Error(`${n}${r}`)}function ie(e){return e instanceof a.ZodFunction}function _(e){return e instanceof a.ZodTuple}function v(e){return e instanceof a.ZodArray}function y(e){return e.length>0}function b(e){return y(e)?a.tuple(e):a.tuple([])}async function x(e,t,n){return Reflect.apply(e,null,[t,...Array.isArray(n)?n:[n]])}function S(e){return(t,...n)=>e(t,...n)}function C(e){let t=e._zod.def.input;return e=>{let n=a.core.safeParse(t,e);return n.success?{success:!0,data:n.data}:{success:!1,error:JSON.stringify(n.error.issues)}}}function w(e){return t=>{let n=_(e)||v(e)?t:[t],r=a.core.safeParse(e,_(e)||v(e)?t:n);return r.success?{success:!0,data:r.data}:{success:!1,error:JSON.stringify(r.error.issues)}}}function ae(){return(e,t)=>{let r=String(e),i=S(t);n.handle(r,i)}}function oe(){return e=>{let t=String(e);n.removeHandler(t)}}function se(e,t){n.handle(e,t)}function ce(e){for(let t in e){let n=e[t];n&&se(t,S(n))}}const T=a.object({code:e,message:a.string(),details:a.record(a.string(),a.unknown()).optional()});function E(e){return a.object({success:a.boolean(),data:e.optional(),error:T.optional()})}const D=E(a.void());function O(e,t){return a.object({params:e,return:t})}function k(e){return e}function A(e,t){return a.function({input:e,output:t})}function j(e,t){let n={},r={};for(let[i,o]of Object.entries(t)){n[i]=`${e}:${i}`;let t=b(o.input?.filter(Boolean)??[]),s=E(o.output);r[i]=a.function({input:t,output:s})}return M(n,a.object(r))}function M(e,t){return{channels:e,schema:t}}const N=s(`src/ipc/zod/main/handlers`),P=a.object({success:a.boolean(),data:a.unknown().optional(),error:a.object({code:e,message:a.string(),details:a.record(a.string(),a.unknown()).optional()}).optional()});function F(e,t,r,i){let a=w(t);n.handle(e,async(e,...t)=>{let n=a(t);if(!n.success)return{success:!1,error:{code:`INVALID_INPUT`,message:`参数验证失败: ${n.error}`}};let r=Array.isArray(n.data)?[e,...n.data]:[e,n.data],o=P.safeParse(await Reflect.apply(i,null,r));return o.success?o.data:{success:!1,error:{code:`INTERNAL_ERROR`,message:`Handler 返回值类型无效`}}})}function I(e){let t=e.schema.shape,r=e.channels;return(e,i)=>{let a=String(e),o=t[a];if(!o||!ie(o)){N.error(`Schema for key "${a}" is not a ZodFunction`);return}let s=C(o),c=r[a];if(!c){N.error(`Channel for key "${a}" not found`);return}n.handle(c,async(e,...t)=>{let n=s(t);return n.success?await x(i,e,n.data):{success:!1,error:{code:`INVALID_INPUT`,message:`参数验证失败: ${n.error}`}}})}}function L(e,t){let n=I(e);Object.entries(t).forEach(([e,t])=>{t&&n(e,t)})}function R(e){n.removeHandler(e)}function z(e){let t=e.channels;return e=>{let n=t[e];R(n)}}const B={width:1200,height:800,frame:!1,titleBarStyle:`hidden`,autoHideMenuBar:!0},V={MINIMIZE:`window:minimize`,MAXIMIZE:`window:maximize`,CLOSE:`window:close`,IS_MAXIMIZED:`window:is-maximized`};let H=null;function U(){return H}function W(){n.removeHandler(V.MINIMIZE),n.handle(V.MINIMIZE,()=>{H?.minimize()}),n.removeHandler(V.MAXIMIZE),n.handle(V.MAXIMIZE,()=>{H?.isMaximized()?H.unmaximize():H?.maximize()}),n.removeHandler(V.CLOSE),n.handle(V.CLOSE,()=>{H?.close()}),n.removeHandler(V.IS_MAXIMIZED),n.handle(V.IS_MAXIMIZED,()=>H?.isMaximized()||!1)}function le(e={}){let n={...B,...e};H=new t({width:n.width,height:n.height,minWidth:n.minWidth,minHeight:n.minHeight,frame:n.frame,titleBarStyle:n.titleBarStyle,autoHideMenuBar:n.autoHideMenuBar,show:!1,webPreferences:{preload:c(__dirname,`../preload/index.cjs`),sandbox:!1,contextIsolation:!0,webviewTag:!0,...n.browserWindowOptions?.webPreferences},...n.browserWindowOptions}),H.on(`ready-to-show`,()=>{H?.show()}),process.env.ELECTRON_RENDERER_URL?(H.loadURL(process.env.ELECTRON_RENDERER_URL),n.devTools!==!1&&H.webContents.openDevTools()):H.loadFile(c(__dirname,`../renderer/index.html`)),H.webContents.setWindowOpenHandler(e=>(i.openExternal(e.url),{action:`deny`}))}function ue(){H=null}var G=class e{static instance;instances=new Map;constructor(){}static getInstance(){return e.instance||=new e,e.instance}register(e,t){this.instances.set(e,t)}resolve(e){let t=this.instances.get(e);if(!t)throw Error(`依赖 '${e}' 未注册`);return t}resolveWithGuard(e,t){let n=this.resolve(e);if(!t(n))throw Error(`依赖 '${e}' 类型守卫检查失败`);return n}has(e){return this.instances.has(e)}clear(){this.instances.clear()}};function de(){return G.getInstance()}const K={LOGGER:`logger`,DATABASE:`database`,WINDOW_SERVICE:`window-service`,LIFECYCLE_MANAGER:`lifecycle-manager`},fe={...K},q=o([`UNKNOWN`,`INVALID_ARGUMENT`,`OPERATION_FAILED`,`AUTH_FAILED`,`AUTH_UNAUTHORIZED`,`AUTH_TOKEN_EXPIRED`,`AUTH_INVALID_CREDENTIALS`,`DB_CONNECTION_ERROR`,`DB_QUERY_ERROR`,`DB_NOT_FOUND`,`DB_CONSTRAINT_VIOLATION`,`FILE_NOT_FOUND`,`FILE_READ_ERROR`,`FILE_WRITE_ERROR`,`FILE_PERMISSION_DENIED`,`GIT_NOT_A_REPO`,`GIT_COMMAND_FAILED`,`GIT_MERGE_CONFLICT`,`NETWORK_ERROR`,`NETWORK_TIMEOUT`,`PLUGIN_NOT_FOUND`,`PLUGIN_LOAD_FAILED`,`PLUGIN_EXECUTION_ERROR`],`错误码`);var J=class e extends Error{code;details;timestamp;constructor(e,t,n){super(t),this.name=`AppError`,this.code=e,this.details=n,this.timestamp=Date.now()}toJSON(){return{name:this.name,code:this.code,message:this.message,details:this.details,timestamp:this.timestamp,stack:this.stack}}static fromError(t,n=q.enum.UNKNOWN){return t instanceof e?t:new e(n,t.message,{originalError:t})}static unknown(t){return new e(q.enum.UNKNOWN,t)}static invalidArgument(t){return new e(q.enum.INVALID_ARGUMENT,t)}static operationFailed(t){return new e(q.enum.OPERATION_FAILED,t)}};function Y(e){return{success:!0,data:e}}function X(e,t,n){return{success:!1,error:new J(e,t,n)}}async function pe(e,t=q.enum.OPERATION_FAILED){try{return Y(await e())}catch(e){let n=e instanceof Error?e:Error(String(e)),r=J.fromError(n,t);return X(r.code,r.message,r.details)}}const me=s(`src/lifecycle/lifecycle-manager.manager`),Z=o([`IDLE`,`INITIALIZING`,`READY`,`SHUTTING_DOWN`],`生命周期阶段`);var Q=class{phase=Z.enum.IDLE;database=null;startupHooks=[];readyHooks=[];shutdownHooks=[];readyResolvers=[];setDatabase(e){this.database=e}getPhase(){return this.phase}isReady(){return this.phase===Z.enum.READY}getDatabase(){return this.database}onShutdown(e){this.shutdownHooks.push(e)}onBeforeStartup(e){this.startupHooks.push(e)}onReady(e){this.readyHooks.push(e)}async initialize(){if(this.phase===Z.enum.IDLE){this.phase=Z.enum.INITIALIZING;for(let e of this.startupHooks)await e();for(let e of this.readyHooks)await e();this.phase=Z.enum.READY,this.readyResolvers.forEach(e=>e()),this.readyResolvers=[]}}whenReady(){return this.phase===Z.enum.READY?Promise.resolve():new Promise(e=>{this.readyResolvers.push(e)})}async shutdown(){this.phase=Z.enum.SHUTTING_DOWN;for(let e of this.shutdownHooks)try{await e()}catch(e){me.error(`关闭钩子执行失败`,e instanceof Error?e:Error(String(e)))}this.phase=Z.enum.IDLE,this.startupHooks=[],this.readyHooks=[],this.shutdownHooks=[],this.readyResolvers=[],this.database=null}};const he=new Q;function $(e,t={}){let n=t.devConnectSrc??[`http://127.0.0.1:3000`,`http://localhost:*`,`ws://localhost:*`,`wss://localhost:*`],r=t.prodConnectSrc??[`https:`,`wss:`];return e?[`default-src 'self'`,`script-src 'self' 'unsafe-inline' 'unsafe-eval' https: http:`,`style-src 'self' 'unsafe-inline' https: http:`,`img-src 'self' data: https: http:`,`connect-src 'self' ${n.join(` `)}`,`font-src 'self' https: data:`].join(`; `):[`default-src 'self'`,`script-src 'self' 'unsafe-inline' https:`,`style-src 'self' 'unsafe-inline' https:`,`img-src 'self' data: https:`,`connect-src 'self' ${r.join(` `)}`,`font-src 'self' https: data:`].join(`; `)}function ge(e={}){let t=$(process.env.ELECTRON_RENDERER_URL!==void 0,e);r.defaultSession.webRequest.onHeadersReceived((e,n)=>{n({responseHeaders:{...e.responseHeaders,"Content-Security-Policy":[t]}})})}function _e(e){return{resolve:{alias:{"@shared":l(`src/shared`),"@main":l(`src/main`)}},build:{externalizeDeps:{exclude:e}}}}function ve(){return{resolve:{alias:{"@shared":l(`src/shared`),"@preload":l(`src/preload`)}},build:{externalizeDeps:{exclude:[`@electron-toolkit/preload`]},rollupOptions:{external:[`electron`],output:{entryFileNames:`[name].cjs`}}},lib:{entry:`src/preload/index.ts`,formats:[`cjs`]}}}function ye(){return{resolve:{alias:{"@renderer":l(`src/renderer/src`),"@shared":l(`src/shared`)}}}}function be(e){let{externalPackages:t=[]}=e;return{main:_e(t),preload:ve(),renderer:ye()}}export{J as AppError,K as CORE_TOKENS,B as DEFAULT_WINDOW_OPTIONS,G as DIContainer,G as DIContainerService,q as ErrorCode,e as IPCErrorCodeSchema,T as IPCErrorSchema,D as IPCResultSchema,Q as LifecycleManager,Z as LifecyclePhase,fe as REPOSITORY_TOKENS,V as WINDOW_CONTROL_CHANNELS,ge as configureCSP,$ as createCSPPolicy,be as createDesktopViteConfig,ae as createHandle,k as createIPCAPISchema,A as createIPCFunctionSchema,O as createIPCMethodDefinitionSchema,E as createIPCResultSchema,w as createParamsValidator,oe as createRemove,le as createWindow,I as createZodHandle,z as createZodRemove,j as defineZodIPCSchema,ue as destroyMainWindow,X as errorFailure,Y as errorSuccess,re as failure,de as getContainer,U as getMainWindow,h as isFailure,m as isSuccess,he as lifecycleManager,ce as registerHandlers,W as registerWindowControlHandlers,F as registerZodHandler,L as registerZodHandlers,R as removeZodHandler,ne as success,g as unwrap,pe as wrapAsync};
|
|
1
|
+
import"./rolldown-runtime-BqT_7tdF.js";import{t as e}from"./ipc.schema-CRktvhDm.js";import{BrowserWindow as t,app as n,ipcMain as r,session as i,shell as a}from"electron";import*as o from"zod";import{defineEnumSchema as s}from"@longzai-intelligence-zod/utils";import{createNodeLogger as c}from"@longzai-intelligence-logger/node";import{existsSync as l}from"node:fs";import{join as u,resolve as d}from"node:path";const f=new Set([`operation`,`channel`,`handler`,`module`,`feature`,`action`,`phase`,`stage`,`scope`,`type`,`reason`,`status`,`code`,`count`,`total`,`size`,`limit`,`offset`,`attempt`,`retry`]),p=/(stack|trace|path|token|secret|password|key|sql|query|prompt|content|raw|payload)/i;function ee(){return process.env.NODE_ENV===`development`}function m(e){return e===null||[`string`,`number`,`boolean`].includes(typeof e)}function te(e){return p.test(e)?!1:f.has(e)?!0:/(?:^|_)(?:id|uuid)$/i.test(e)||/(?:Id|UUID|Uuid)$/.test(e)}function ne(e){if(e===void 0)return;if(ee())return e;let t={};for(let[n,r]of Object.entries(e))if(te(n)){if(m(r)){t[n]=r;continue}Array.isArray(r)&&r.every(m)&&(t[n]=r.slice(0,20))}return Object.keys(t).length>0?t:void 0}function re(e){return e===void 0?{success:!0}:{success:!0,data:e}}function h(e,t,n){let r={code:e,message:t},i=ne(n);return i!==void 0&&(r.details=i),{success:!1,error:r}}function g(e){return e.success===!0}function ie(e){return e.success===!1}function ae(e,t){if(g(e))return e.data;let n=e.error?.code?`[${e.error.code}] `:``,r=e.error?.message??t;throw Error(`${n}${r}`)}function oe(e){return e instanceof o.ZodFunction}function _(e){return e instanceof o.ZodTuple}function v(e){return e instanceof o.ZodArray}function y(e){return e.length>0}function b(e){return y(e)?o.tuple(e):o.tuple([])}async function x(e,t,n){return Reflect.apply(e,null,[t,...Array.isArray(n)?n:[n]])}function S(e){return(t,...n)=>e(t,...n)}function se(e){let t=e._zod.def.input;return e=>{let n=o.core.safeParse(t,e);return n.success?{success:!0,data:n.data}:{success:!1,error:JSON.stringify(n.error.issues)}}}function C(e){return t=>{let n=_(e)||v(e)?t:[t],r=o.core.safeParse(e,_(e)||v(e)?t:n);return r.success?{success:!0,data:r.data}:{success:!1,error:JSON.stringify(r.error.issues)}}}function ce(){return(e,t)=>{let n=String(e),i=S(t);r.handle(n,i)}}function le(){return e=>{let t=String(e);r.removeHandler(t)}}function ue(e,t){r.handle(e,t)}function de(e){for(let t in e){let n=e[t];n&&ue(t,S(n))}}const w=o.object({code:e,message:o.string(),details:o.record(o.string(),o.unknown()).optional()});function T(e){return o.object({success:o.boolean(),data:e.optional(),error:w.optional()})}const E=T(o.void());function D(e,t){return o.object({params:e,return:t})}function O(e){return e}function k(e,t){return o.function({input:e,output:t})}function A(e,t){let n={},r={};for(let[i,a]of Object.entries(t)){n[i]=`${e}:${i}`;let t=b(a.input?.filter(Boolean)??[]),s=T(a.output);r[i]=o.function({input:t,output:s})}return j(n,o.object(r))}function j(e,t){return{channels:e,schema:t}}const M=c(`src/ipc/zod/main/handlers`),N=o.object({success:o.boolean(),data:o.unknown().optional(),error:o.object({code:e,message:o.string(),details:o.record(o.string(),o.unknown()).optional()}).optional()});function P(e,t,n,i){let a=C(t);r.handle(e,async(e,...t)=>{let n=a(t);if(!n.success)return{success:!1,error:{code:`INVALID_INPUT`,message:`参数验证失败: ${n.error}`}};let r=Array.isArray(n.data)?[e,...n.data]:[e,n.data],o=N.safeParse(await Reflect.apply(i,null,r));return o.success?o.data:{success:!1,error:{code:`INTERNAL_ERROR`,message:`Handler 返回值类型无效`}}})}function F(e){let t=e.schema.shape,n=e.channels;return(e,i)=>{let a=String(e),o=t[a];if(!o||!oe(o)){M.error(`Schema for key "${a}" is not a ZodFunction`);return}let s=se(o),c=n[a];if(!c){M.error(`Channel for key "${a}" not found`);return}r.handle(c,async(e,...t)=>{let n=s(t);return n.success?await x(i,e,n.data):{success:!1,error:{code:`INVALID_INPUT`,message:`参数验证失败: ${n.error}`}}})}}function I(e,t){let n=F(e);Object.entries(t).forEach(([e,t])=>{t&&n(e,t)})}function L(e){r.removeHandler(e)}function R(e){let t=e.channels;return e=>{let n=t[e];L(n)}}const z={width:1200,height:800,frame:!1,titleBarStyle:`hidden`,autoHideMenuBar:!0},B={MINIMIZE:`window:minimize`,MAXIMIZE:`window:maximize`,CLOSE:`window:close`,IS_MAXIMIZED:`window:is-maximized`},V=[`index.cjs`,`index.mjs`];function H(e){if(e.preloadPath!==void 0&&e.preloadPath!==``)return e.preloadPath;let t=u(n.getAppPath(),`out`,`preload`);for(let e of V){let n=u(t,e);if(l(n))return n}return u(t,V[0]??`index.cjs`)}function U(e){return e.rendererPath!==void 0&&e.rendererPath!==``?e.rendererPath:u(n.getAppPath(),`out`,`renderer`,`index.html`)}let W=null;function fe(){return W}function pe(){r.removeHandler(B.MINIMIZE),r.handle(B.MINIMIZE,()=>{W?.minimize()}),r.removeHandler(B.MAXIMIZE),r.handle(B.MAXIMIZE,()=>{W?.isMaximized()?W.unmaximize():W?.maximize()}),r.removeHandler(B.CLOSE),r.handle(B.CLOSE,()=>{W?.close()}),r.removeHandler(B.IS_MAXIMIZED),r.handle(B.IS_MAXIMIZED,()=>W?.isMaximized()||!1)}function me(e={}){let n={...z,...e};W=new t({width:n.width,height:n.height,minWidth:n.minWidth,minHeight:n.minHeight,frame:n.frame,titleBarStyle:n.titleBarStyle,autoHideMenuBar:n.autoHideMenuBar,show:!1,webPreferences:{preload:H(e),sandbox:!1,contextIsolation:!0,webviewTag:!0,...n.browserWindowOptions?.webPreferences},...n.browserWindowOptions}),W.on(`ready-to-show`,()=>{W?.show()}),process.env.ELECTRON_RENDERER_URL?(W.loadURL(process.env.ELECTRON_RENDERER_URL),n.devTools!==!1&&W.webContents.openDevTools()):W.loadFile(U(e)),W.webContents.setWindowOpenHandler(e=>(a.openExternal(e.url),{action:`deny`}))}function he(){W=null}var G=class e{static instance;instances=new Map;constructor(){}static getInstance(){return e.instance||=new e,e.instance}register(e,t){this.instances.set(e,t)}resolve(e){let t=this.instances.get(e);if(!t)throw Error(`依赖 '${e}' 未注册`);return t}resolveWithGuard(e,t){let n=this.resolve(e);if(!t(n))throw Error(`依赖 '${e}' 类型守卫检查失败`);return n}has(e){return this.instances.has(e)}clear(){this.instances.clear()}};function ge(){return G.getInstance()}const K={LOGGER:`logger`,DATABASE:`database`,WINDOW_SERVICE:`window-service`,LIFECYCLE_MANAGER:`lifecycle-manager`},_e={...K},q=s([`UNKNOWN`,`INVALID_ARGUMENT`,`OPERATION_FAILED`,`AUTH_FAILED`,`AUTH_UNAUTHORIZED`,`AUTH_TOKEN_EXPIRED`,`AUTH_INVALID_CREDENTIALS`,`DB_CONNECTION_ERROR`,`DB_QUERY_ERROR`,`DB_NOT_FOUND`,`DB_CONSTRAINT_VIOLATION`,`FILE_NOT_FOUND`,`FILE_READ_ERROR`,`FILE_WRITE_ERROR`,`FILE_PERMISSION_DENIED`,`GIT_NOT_A_REPO`,`GIT_COMMAND_FAILED`,`GIT_MERGE_CONFLICT`,`NETWORK_ERROR`,`NETWORK_TIMEOUT`,`PLUGIN_NOT_FOUND`,`PLUGIN_LOAD_FAILED`,`PLUGIN_EXECUTION_ERROR`],`错误码`);var J=class e extends Error{code;details;timestamp;constructor(e,t,n){super(t),this.name=`AppError`,this.code=e,this.details=n,this.timestamp=Date.now()}toJSON(){return{name:this.name,code:this.code,message:this.message,details:this.details,timestamp:this.timestamp,stack:this.stack}}static fromError(t,n=q.enum.UNKNOWN){return t instanceof e?t:new e(n,t.message,{originalError:t})}static unknown(t){return new e(q.enum.UNKNOWN,t)}static invalidArgument(t){return new e(q.enum.INVALID_ARGUMENT,t)}static operationFailed(t){return new e(q.enum.OPERATION_FAILED,t)}};function Y(e){return{success:!0,data:e}}function X(e,t,n){return{success:!1,error:new J(e,t,n)}}async function ve(e,t=q.enum.OPERATION_FAILED){try{return Y(await e())}catch(e){let n=e instanceof Error?e:Error(String(e)),r=J.fromError(n,t);return X(r.code,r.message,r.details)}}const ye=c(`src/lifecycle/lifecycle-manager.manager`),Z=s([`IDLE`,`INITIALIZING`,`READY`,`SHUTTING_DOWN`],`生命周期阶段`);var Q=class{phase=Z.enum.IDLE;database=null;startupHooks=[];readyHooks=[];shutdownHooks=[];readyResolvers=[];setDatabase(e){this.database=e}getPhase(){return this.phase}isReady(){return this.phase===Z.enum.READY}getDatabase(){return this.database}onShutdown(e){this.shutdownHooks.push(e)}onBeforeStartup(e){this.startupHooks.push(e)}onReady(e){this.readyHooks.push(e)}async initialize(){if(this.phase===Z.enum.IDLE){this.phase=Z.enum.INITIALIZING;for(let e of this.startupHooks)await e();for(let e of this.readyHooks)await e();this.phase=Z.enum.READY,this.readyResolvers.forEach(e=>e()),this.readyResolvers=[]}}whenReady(){return this.phase===Z.enum.READY?Promise.resolve():new Promise(e=>{this.readyResolvers.push(e)})}async shutdown(){this.phase=Z.enum.SHUTTING_DOWN;for(let e of this.shutdownHooks)try{await e()}catch(e){ye.error(`关闭钩子执行失败`,e instanceof Error?e:Error(String(e)))}this.phase=Z.enum.IDLE,this.startupHooks=[],this.readyHooks=[],this.shutdownHooks=[],this.readyResolvers=[],this.database=null}};const be=new Q;function $(e,t={}){let n=t.devConnectSrc??[`http://127.0.0.1:3000`,`http://localhost:*`,`ws://localhost:*`,`wss://localhost:*`],r=t.prodConnectSrc??[`https:`,`wss:`];return e?[`default-src 'self'`,`script-src 'self' 'unsafe-inline' 'unsafe-eval' https: http:`,`style-src 'self' 'unsafe-inline' https: http:`,`img-src 'self' data: https: http:`,`connect-src 'self' ${n.join(` `)}`,`font-src 'self' https: data:`].join(`; `):[`default-src 'self'`,`script-src 'self' 'unsafe-inline' https:`,`style-src 'self' 'unsafe-inline' https:`,`img-src 'self' data: https:`,`connect-src 'self' ${r.join(` `)}`,`font-src 'self' https: data:`].join(`; `)}function xe(e={}){let t=$(process.env.ELECTRON_RENDERER_URL!==void 0,e);i.defaultSession.webRequest.onHeadersReceived((e,n)=>{n({responseHeaders:{...e.responseHeaders,"Content-Security-Policy":[t]}})})}function Se(e){return{resolve:{alias:{"@shared":d(`src/shared`),"@main":d(`src/main`)}},build:{externalizeDeps:{exclude:e}}}}function Ce(){return{resolve:{alias:{"@shared":d(`src/shared`),"@preload":d(`src/preload`)}},build:{externalizeDeps:{exclude:[`@electron-toolkit/preload`]},rollupOptions:{external:[`electron`],output:{entryFileNames:`[name].cjs`}}},lib:{entry:`src/preload/index.ts`,formats:[`cjs`]}}}function we(){return{resolve:{alias:{"@renderer":d(`src/renderer/src`),"@shared":d(`src/shared`)}}}}function Te(e){let{externalPackages:t=[]}=e;return{main:Se(t),preload:Ce(),renderer:we()}}export{J as AppError,K as CORE_TOKENS,z as DEFAULT_WINDOW_OPTIONS,G as DIContainer,G as DIContainerService,q as ErrorCode,e as IPCErrorCodeSchema,w as IPCErrorSchema,E as IPCResultSchema,Q as LifecycleManager,Z as LifecyclePhase,_e as REPOSITORY_TOKENS,B as WINDOW_CONTROL_CHANNELS,xe as configureCSP,$ as createCSPPolicy,Te as createDesktopViteConfig,ce as createHandle,O as createIPCAPISchema,k as createIPCFunctionSchema,D as createIPCMethodDefinitionSchema,T as createIPCResultSchema,C as createParamsValidator,le as createRemove,me as createWindow,F as createZodHandle,R as createZodRemove,A as defineZodIPCSchema,he as destroyMainWindow,X as errorFailure,Y as errorSuccess,h as failure,ge as getContainer,fe as getMainWindow,ie as isFailure,g as isSuccess,be as lifecycleManager,de as registerHandlers,pe as registerWindowControlHandlers,P as registerZodHandler,I as registerZodHandlers,L as removeZodHandler,re as success,ae as unwrap,ve as wrapAsync};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@longzai-intelligence-electron/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "Longzai Intelligence Electron 桌面端运行时基础设施包",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"longzai-intelligence",
|
|
@@ -49,7 +49,6 @@
|
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@longzai-intelligence-testing/utils": "^0.0.3",
|
|
52
|
-
"@longzai-intelligence-vitest/config": "^0.0.12",
|
|
53
52
|
"electron": "^43",
|
|
54
53
|
"typeorm": "^1.1.2",
|
|
55
54
|
"vitest": "^4.1.4"
|