summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorErik Larkö <erik@mullvad.net>2017-10-20 09:55:11 +0200
committerErik Larkö <erik@mullvad.net>2017-10-20 09:55:11 +0200
commite53e809b9b674e70dc1f540ed25076ca5bc6fae2 (patch)
tree802cbd373b0c29ed33c65dbe2cbc0157c739e16b
parent610343f0ae029aa810e6e6bcedc8a69226397eb2 (diff)
parent8ab14bad27343bd1ab74e6de29ff8de157cad3e3 (diff)
downloadmullvadvpn-e53e809b9b674e70dc1f540ed25076ca5bc6fae2.tar.xz
mullvadvpn-e53e809b9b674e70dc1f540ed25076ca5bc6fae2.zip
Merge branch 'shutdown-on-close'
-rw-r--r--app/app.js9
-rw-r--r--app/lib/backend.js7
-rw-r--r--app/lib/ipc-facade.js6
-rw-r--r--app/main.js4
-rw-r--r--test/mocks/ipc.js72
5 files changed, 56 insertions, 42 deletions
diff --git a/app/app.js b/app/app.js
index c0682343c3..c07f267617 100644
--- a/app/app.js
+++ b/app/app.js
@@ -34,9 +34,12 @@ ipcRenderer.on('backend-info', (_event, args) => {
}
});
});
-ipcRenderer.on('disconnect', () => {
- log.info('Been told by the node process to disconnect');
- backend.disconnect();
+ipcRenderer.on('shutdown', () => {
+ log.info('Been told by the node process to shutdown');
+ backend.shutdown()
+ .catch( e => {
+ log.warn('Unable to shut down the backend', e.message);
+ });
});
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
diff --git a/app/lib/backend.js b/app/lib/backend.js
index b7f3f3e489..b210e65e85 100644
--- a/app/lib/backend.js
+++ b/app/lib/backend.js
@@ -299,6 +299,13 @@ export class Backend {
});
}
+ shutdown(): Promise<void> {
+ return this._ensureAuthenticated()
+ .then( () => {
+ return this._ipc.shutdown();
+ });
+ }
+
/**
* Start reachability monitoring for online/offline detection
* This is currently done via HTML5 APIs but will be replaced later
diff --git a/app/lib/ipc-facade.js b/app/lib/ipc-facade.js
index c2938ae8f1..8939e82823 100644
--- a/app/lib/ipc-facade.js
+++ b/app/lib/ipc-facade.js
@@ -40,6 +40,7 @@ export interface IpcFacade {
setCustomRelay(RelayEndpoint): Promise<void>,
connect(): Promise<void>,
disconnect(): Promise<void>,
+ shutdown(): Promise<void>,
getIp(): Promise<Ip>,
getLocation(): Promise<Location>,
getState(): Promise<BackendState>,
@@ -109,6 +110,11 @@ export class RealIpc implements IpcFacade {
.then(this._ignoreResponse);
}
+ shutdown(): Promise<void> {
+ return this._ipc.send('shutdown')
+ .then(this._ignoreResponse);
+ }
+
getIp(): Promise<Ip> {
return this._ipc.send('get_ip')
.then(raw => {
diff --git a/app/main.js b/app/main.js
index f39e5dc429..cc47a57cb2 100644
--- a/app/main.js
+++ b/app/main.js
@@ -96,8 +96,8 @@ const appDelegate = {
window.loadURL('file://' + path.join(__dirname, 'index.html'));
window.on('close', () => {
- log.debug('The browser window is closing, disconnecting the tunnel...');
- window.webContents.send('disconnect');
+ log.debug('The browser window is closing, shutting down the tunnel...');
+ window.webContents.send('shutdown');
});
// create tray icon on macOS
diff --git a/test/mocks/ipc.js b/test/mocks/ipc.js
index 5b337ebbc9..c02eb20de4 100644
--- a/test/mocks/ipc.js
+++ b/test/mocks/ipc.js
@@ -18,55 +18,53 @@ export function newMockIpc() {
const mockIpc: IpcFacade & MockIpc = {
setConnectionString: (_str: string) => {},
- getAccountData: (accountToken) => {
- return new Promise(r => r({
- accountToken: accountToken,
- expiry: '',
- }));
- },
- getAccount: () => {
- return new Promise(r => r('1111'));
- },
- setAccount: () => {
- return new Promise(r => r());
- },
- setCustomRelay: () => {
- return new Promise(r => r());
- },
- connect: () => {
- return new Promise(r => r());
- },
- disconnect: () => {
- return new Promise(r => r());
- },
- getIp: () => {
- return new Promise(r => r('1.2.3.4'));
- },
- getLocation: () => {
- return new Promise(r => r({
- city: '',
- country: '',
- latlong: [0, 0],
- }));
- },
- getState: () => {
- return new Promise(r => r({
- state: 'unsecured',
- target_state:'unsecured',
- }));
- },
+
+ getAccountData: (accountToken) => Promise.resolve({
+ accountToken: accountToken,
+ expiry: '',
+ }),
+
+ getAccount: () => Promise.resolve('1111'),
+
+ setAccount: () => Promise.resolve(),
+
+ setCustomRelay: () => Promise.resolve(),
+
+ connect: () => Promise.resolve(),
+
+ disconnect: () => Promise.resolve(),
+
+ shutdown: () => Promise.resolve(),
+
+ getIp: () => Promise.resolve('1.2.3.4'),
+
+ getLocation: () => Promise.resolve({
+ city: '',
+ country: '',
+ latlong: [0, 0],
+ }),
+
+ getState: () => Promise.resolve({
+ state: 'unsecured',
+ target_state:'unsecured',
+ }),
+
registerStateListener: (listener: (BackendState) => void) => {
stateListeners.push(listener);
},
+
sendNewState: (state: BackendState) => {
for(const l of stateListeners) {
l(state);
}
},
+
authenticate: (_secret: string) => Promise.resolve(),
+
setCloseConnectionHandler: (listener: () => void) => {
connectionCloseListeners.push(listener);
},
+
killWebSocket: () => {
for(const l of connectionCloseListeners) {
l();