添加 ipc 同步/异步发送消息

This commit is contained in:
gsx
2022-04-23 18:38:24 +08:00
parent 61749ff5e4
commit f3e8d31753
5 changed files with 109 additions and 9 deletions

View File

@@ -11,6 +11,7 @@ const electronApp = require('electron').app;
const {dialog, webContents, shell, BrowserWindow, BrowserView,
Notification, powerMonitor, screen, nativeTheme} = require('electron');
const autoLaunchManager = require('../library/autoLaunch');
const dayjs = require('dayjs');
let myTimer = null;
let browserViewObj = null;
@@ -29,7 +30,7 @@ class ExampleController extends Controller {
/**
* 所有方法接收两个参数
* @param args 前端传的参数
* @param event - IpcMainEvent 文档https://www.electronjs.org/docs/latest/api/structures/ipc-main-event
* @param event - ipc通信时才有值。invoke()方法时event == IpcMainInvokeEvent; send()/sendSync()方法时event == IpcMainEvent
*/
/**
@@ -580,7 +581,32 @@ class ExampleController extends Controller {
shell.openPath(dir);
return true;
}
}
/**
* 异步消息类型
* @param args 前端传的参数
* @param event - IpcMainInvokeEvent 文档https://www.electronjs.org/zh/docs/latest/api/structures/ipc-main-invoke-event
*/
async ipcInvokeMsg (args, event) {
let timeNow = dayjs().format('YYYY-MM-DD HH:mm:ss');
const data = args + ' - ' + timeNow;
return data;
}
/**
* 同步消息类型
* @param args 前端传的参数
* @param event - IpcMainEvent 文档https://www.electronjs.org/docs/latest/api/structures/ipc-main-event
*/
async ipcSendSyncMsg (args) {
let timeNow = dayjs().format('YYYY-MM-DD HH:mm:ss');
const data = args + ' - ' + timeNow;
return data;
}
}
module.exports = ExampleController;