Skip to content
This repository has been archived by the owner on Jun 11, 2021. It is now read-only.

Commit

Permalink
Added closing of event listener
Browse files Browse the repository at this point in the history
Signed-off-by: French Ben <me+git@frenchben.com>
  • Loading branch information
FrenchBen committed Apr 11, 2016
1 parent b8495ee commit c36129f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
1 change: 1 addition & 0 deletions src/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ app.on('ready', function () {
return false;
});


if (os.platform() === 'win32') {
mainWindow.on('close', function () {
mainWindow.webContents.send('application:quitting');
Expand Down
4 changes: 3 additions & 1 deletion src/utils/ContainerUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ var ContainerUtil = {
var [dockerPort, portType] = key.split('/');
var localUrl = null;
var port = null;

if (value && value.length) {
port = value[0].HostPort;
}
if (ip === 'docker.local') {
ip = value[0].HostIp;
}
localUrl = (port) ? ip + ':' + port : ip + ':' + '<not set>';

res[dockerPort] = {
Expand Down
26 changes: 17 additions & 9 deletions src/utils/DockerUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export default {
host: null,
client: null,
placeholders: {},
streams: {},
stream: null,
eventStream: null,
activeContainerName: null,

setup (ip, name) {
Expand Down Expand Up @@ -377,7 +378,7 @@ export default {
},

active (name) {
this.detach();
this.detachLog();
this.activeContainerName = name;

if (name) {
Expand Down Expand Up @@ -431,9 +432,7 @@ export default {
return;
}

if (this.stream) {
this.detach();
}
this.detachLog()
this.stream = logStream;

let timeout = null;
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -491,6 +498,7 @@ export default {
this.fetchContainer(data.id);
}
});
this.eventStream = stream;
});
},

Expand Down

0 comments on commit c36129f

Please sign in to comment.