perf: 优化数据

This commit is contained in:
kuaifan 2025-03-19 15:06:31 +08:00
parent 8bbe9c97e9
commit 8d24be914d
8 changed files with 31 additions and 39 deletions

View File

@ -33,27 +33,25 @@ contextBridge.exposeInMainWorld(
request: (msg, callback, error) => {
msg.reqId = reqId++;
reqInfo[msg.reqId] = {callback: callback, error: error};
//TODO Maybe a special function for this better than this hack?
//File watch special case where the callback is called multiple times
if (msg.action == 'watchFile') {
fileChangedListeners[msg.path] = msg.listener;
delete msg.listener;
}
ipcRenderer.send('rendererReq', msg);
},
registerMsgListener: function (action, callback) {
ipcRenderer.on(action, function (event, args) {
callback(args);
});
},
sendMessage: function (action, args) {
ipcRenderer.send(action, args);
},
sendAsync: function (action, args) {
return ipcRenderer.invoke(action, args)
},
listener: function (action, callback) {
ipcRenderer.on(action, function (event, args) {
callback(args);
});
},
listenOnce: function (action, callback) {
ipcRenderer.once(action, function (event, args) {
callback(args);

19
electron/electron.js vendored
View File

@ -1261,24 +1261,15 @@ ipcMain.on('windowMax', (event) => {
})
/**
* 给主窗口发送信息
* @param args {channel, data}
*/
ipcMain.on('sendForwardMain', (event, args) => {
if (mainWindow) {
mainWindow.webContents.send(args.channel, args.data)
}
event.returnValue = "ok"
})
/**
* 窗口同步执行派遣
* 给所有窗口广播指令除了本身
* @param args {type, payload}
*/
ipcMain.on('syncDispatch', (event, args) => {
ipcMain.on('broadcastCommand', (event, args) => {
const channel = args.channel || args.command
const payload = args.payload || args.data
BrowserWindow.getAllWindows().forEach(window => {
if (window.webContents.id !== event.sender.id) {
window.webContents.send('syncDispatch', args)
window.webContents.send(channel, payload)
}
})
event.returnValue = "ok"

View File

@ -440,13 +440,13 @@ export default {
this.$store.dispatch("openWebTabWindow", url)
return true
}
this.$Electron.registerMsgListener('browserWindowBlur', _ => {
this.$Electron.listener('browserWindowBlur', _ => {
this.$store.state.windowActive = false;
})
this.$Electron.registerMsgListener('browserWindowFocus', _ => {
this.$Electron.listener('browserWindowFocus', _ => {
this.$store.state.windowActive = true;
})
this.$Electron.registerMsgListener('systemThemeChanged', _ => {
this.$Electron.listener('systemThemeChanged', _ => {
this.autoTheme()
})
$A.bindScreenshotKey(this.$store.state.cacheKeyboard);

View File

@ -217,14 +217,17 @@ $A.syncDispatch = (action, data) => {
delete data.__sync__;
return false
}
$A.Electron?.sendMessage('syncDispatch', {
$A.Electron?.sendMessage('broadcastCommand', {
channel: 'syncDispatch',
payload: {
dispatchId,
action,
data,
}
});
return true
};
$A.Electron?.registerMsgListener('syncDispatch', async ({dispatchId: targetId, action, data}) => {
$A.Electron?.listener('syncDispatch', async ({dispatchId: targetId, action, data}) => {
if (dispatchId === targetId) {
return
}

View File

@ -70,7 +70,7 @@ export default {
//
if (this.$Electron) {
emitter.on('updateNotification', this.onUpdateShow);
this.$Electron.registerMsgListener('updateDownloaded', info => {
this.$Electron.listener('updateDownloaded', info => {
this.$store.state.clientNewVersion = info.version
this.updateVersion = info.version;
this.updateNote = info.releaseNotes || this.$L('没有更新描述。');

View File

@ -1208,12 +1208,12 @@ export default {
}
//
if (this.$Electron) {
this.$Electron.registerMsgListener('clickNotification', target => {
this.$Electron.listener('clickNotification', target => {
console.log("[Notification] B Click", target);
this.$Electron.sendMessage('mainWindowActive')
this.notificationClick(target)
})
this.$Electron.registerMsgListener('replyNotification', target => {
this.$Electron.listener('replyNotification', target => {
console.log("[Notification] B Reply", target);
this.notificationReply(target)
})

View File

@ -35,12 +35,12 @@ export default {
}
},
methods: {
saveSuccess(data) {
this.detail = data;
saveSuccess(payload) {
this.detail = payload;
if (this.$isSubElectron) {
$A.Electron.sendMessage('sendForwardMain', {
$A.Electron.sendMessage('broadcastCommand', {
channel: 'reportSaveSuccess',
data,
payload,
});
window.close();
}

View File

@ -12,5 +12,5 @@ export default new Vuex.Store({
state,
getters,
mutations,
actions,
actions
})