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

Added closing of event listener #1623

Merged
merged 1 commit into from
Apr 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 0 additions & 1 deletion src/utils/ContainerUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
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