mirror of
https://github.com/dbgate/dbgate
synced 2024-11-23 00:43:10 +00:00
fixed object destroyed error
This commit is contained in:
parent
df743e8ade
commit
30b054dbec
@ -336,10 +336,10 @@ function createWindow() {
|
||||
// )
|
||||
// );
|
||||
const main = api.getMainModule();
|
||||
main.initializeElectronSender(mainWindow.webContents);
|
||||
main.useAllControllers(null, electron);
|
||||
apiLoaded = true;
|
||||
}
|
||||
main.setElectronSender(mainWindow.webContents);
|
||||
|
||||
loadMainWindow();
|
||||
|
||||
@ -349,6 +349,7 @@ function createWindow() {
|
||||
// in an array if your app supports multi windows, this is the time
|
||||
// when you should delete the corresponding element.
|
||||
mainWindow = null;
|
||||
main.setElectronSender(null);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -155,8 +155,8 @@ function useAllControllers(app, electron) {
|
||||
useController(app, electron, '/apps', apps);
|
||||
}
|
||||
|
||||
function initializeElectronSender(electronSender) {
|
||||
function setElectronSender(electronSender) {
|
||||
socket.setElectronSender(electronSender);
|
||||
}
|
||||
|
||||
module.exports = { start, useAllControllers, initializeElectronSender, configController: config };
|
||||
module.exports = { start, useAllControllers, setElectronSender, configController: config };
|
||||
|
@ -1,6 +1,6 @@
|
||||
let sseResponse = null;
|
||||
let electronSender = null;
|
||||
let init = '';
|
||||
let init = [];
|
||||
|
||||
module.exports = {
|
||||
setSseResponse(value) {
|
||||
@ -12,15 +12,25 @@ module.exports = {
|
||||
},
|
||||
emit(message, data) {
|
||||
if (electronSender) {
|
||||
if (init.length > 0) {
|
||||
for (const item of init) {
|
||||
electronSender.send(item.message, item.data == null ? null : item.data);
|
||||
}
|
||||
init = [];
|
||||
}
|
||||
electronSender.send(message, data == null ? null : data);
|
||||
} else if (sseResponse) {
|
||||
if (init) {
|
||||
sseResponse.write(init);
|
||||
init = '';
|
||||
if (init.length > 0) {
|
||||
for (const item of init) {
|
||||
sseResponse.write(
|
||||
`event: ${item.message}\ndata: ${JSON.stringify(item.data == null ? null : item.data)}\n\n`
|
||||
);
|
||||
}
|
||||
init = [];
|
||||
}
|
||||
sseResponse.write(`event: ${message}\ndata: ${JSON.stringify(data == null ? null : data)}\n\n`);
|
||||
} else {
|
||||
init += sseResponse;
|
||||
init.push([{ message, data }]);
|
||||
}
|
||||
},
|
||||
emitChanged(key) {
|
||||
|
Loading…
Reference in New Issue
Block a user