diff --git a/src/app.js b/src/app.js index aa8307f96..644f36610 100644 --- a/src/app.js +++ b/src/app.js @@ -66,8 +66,14 @@ setupUtil.setup().then(() => { throw err; }); + ipcRenderer.on('application:quitting', () => { + docker.detachEvent(); if (localStorage.getItem('settings.closeVMOnQuit') === 'true') { machine.stop(); } }); + +window.onbeforeunload = function () { + docker.detachEvent(); +}; diff --git a/src/browser.js b/src/browser.js index 3c4c58445..50beae7e6 100644 --- a/src/browser.js +++ b/src/browser.js @@ -47,6 +47,7 @@ app.on('ready', function () { return false; }); + if (os.platform() === 'win32') { mainWindow.on('close', function () { mainWindow.webContents.send('application:quitting'); diff --git a/src/utils/ContainerUtil.js b/src/utils/ContainerUtil.js index 2a9496a6e..a19576970 100644 --- a/src/utils/ContainerUtil.js +++ b/src/utils/ContainerUtil.js @@ -33,7 +33,6 @@ var ContainerUtil = { var [dockerPort, portType] = key.split('/'); var localUrl = null; var port = null; - if (value && value.length) { port = value[0].HostPort; } diff --git a/src/utils/DockerUtil.js b/src/utils/DockerUtil.js index 194279193..d7cee5c17 100644 --- a/src/utils/DockerUtil.js +++ b/src/utils/DockerUtil.js @@ -19,7 +19,8 @@ export default { host: null, client: null, placeholders: {}, - streams: {}, + stream: null, + eventStream: null, activeContainerName: null, setup (ip, name) { @@ -377,7 +378,7 @@ export default { }, active (name) { - this.detach(); + this.detachLog(); this.activeContainerName = name; if (name) { @@ -431,9 +432,7 @@ export default { return; } - if (this.stream) { - this.detach(); - } + this.detachLog() this.stream = logStream; let timeout = null; @@ -452,14 +451,22 @@ export default { }); }, - detach () { + detachLog() { if (this.stream) { this.stream.destroy(); this.stream = null; } }, + detachEvent() { + if (this.eventStream) { + this.eventStream.destroy(); + this.eventStream = null; + } + }, + listen () { + this.detachEvent() this.client.getEvents((error, stream) => { if (error || !stream) { // TODO: Add app-wide error handler @@ -474,13 +481,13 @@ export default { if (data.status === 'destroy') { containerServerActions.destroyed({id: data.id}); - this.detach(data.id); + this.detachLog() } else if (data.status === 'kill') { containerServerActions.kill({id: data.id}); - this.detach(data.id); + this.detachLog() } else if (data.status === 'stop') { containerServerActions.stopped({id: data.id}); - this.detach(data.id); + this.detachLog() } else if (data.status === 'create') { this.logs(); this.fetchContainer(data.id); @@ -491,6 +498,7 @@ export default { this.fetchContainer(data.id); } }); + this.eventStream = stream; }); },