|
@@ -1,35 +1,67 @@
|
|
|
import {App} from "vue";
|
|
|
|
|
|
-import {ipcRenderer} from "electron";
|
|
|
+// import {ipcRenderer} from "electron";
|
|
|
import {IpcAction, windowAction} from "../tools/IpcCmd.ts";
|
|
|
import {registerWindowData} from "../types/appConfig.ts";
|
|
|
|
|
|
-function winHandle(ipc: Electron.IpcRenderer, windowName: string, action: IpcAction){
|
|
|
+const ipcRenderer = {
|
|
|
+ on: (code: string, _: Function)=>{
|
|
|
+ console.log(code)
|
|
|
+ },
|
|
|
+ send: (code: string, data: any)=>{
|
|
|
+ console.log(code, data)
|
|
|
+ },
|
|
|
+
|
|
|
+};
|
|
|
+function winHandle(ipc: Electron.IpcRenderer, windowName: string, action: IpcAction): boolean{
|
|
|
let sendCode = action.code;
|
|
|
- ipc.send(sendCode, windowName);
|
|
|
+ try {
|
|
|
+ ipc.send(sendCode, windowName);
|
|
|
+ return true;
|
|
|
+ }catch (e){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-function registerWinHandle(ipc: Electron.IpcRenderer, windowName: string): (action: IpcAction)=>void
|
|
|
+function registerWinHandle(ipc: Electron.IpcRenderer, windowName: string): (action: IpcAction)=> boolean
|
|
|
{
|
|
|
windowName = windowName.toString();
|
|
|
return winHandle.bind(null, ipc, windowName);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+function tryBindWindow(ipc: Electron.IpcRenderer, type: string): (action: IpcAction)=>void
|
|
|
+{
|
|
|
+ return (_: IpcAction): boolean =>{
|
|
|
+ console.log(`未绑定窗口, 等待绑定`);
|
|
|
+ ipc.send(windowAction.bindSignId.code, type)
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 初始化页面 挂载$winHandle为全局函数. 操作窗口
|
|
|
* @param app
|
|
|
*
|
|
|
*/
|
|
|
-export function windowInit(app: App){
|
|
|
+export function windowInit(app: App, type: string){
|
|
|
+ // 先将验证窗口绑定到全局, 接收到 绑定消息后再进行绑定
|
|
|
+ app.config.globalProperties.$winHandle = tryBindWindow(ipcRenderer, type)
|
|
|
ipcRenderer.on(
|
|
|
- windowAction.bindSignId.code,
|
|
|
- (_: Electron.IpcRendererEvent , data: registerWindowData)=>
|
|
|
- {
|
|
|
- console.log(`获取到窗口id${data.signId}`);
|
|
|
- app.config.globalProperties.$winHandle = registerWinHandle(ipcRenderer, data.signId);
|
|
|
- console.log( `窗口绑定:${windowAction.bindSignId.resCode}` );
|
|
|
- ipcRenderer.send(windowAction.bindSignId.resCode, data.signId);
|
|
|
- });
|
|
|
+ windowAction.bindSignId.code,
|
|
|
+ (_: Electron.IpcRendererEvent , data: registerWindowData)=>
|
|
|
+ {
|
|
|
+ console.log(`获取到窗口id${data.signId}`);
|
|
|
+ if(type !== data.type){
|
|
|
+ console.warn(`未知的窗口绑定 ${data.type}`);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ app.config.globalProperties.$winHandle = registerWinHandle(ipcRenderer, data.signId);
|
|
|
+ console.log( `窗口绑定:${windowAction.bindSignId.resCode}` );
|
|
|
+ ipcRenderer.send(windowAction.bindSignId.resCode, data.signId);
|
|
|
+ });
|
|
|
+
|
|
|
// todo 初始化axios
|
|
|
// if(axios){
|
|
|
// axios.initAxios(
|