diff options
| author | Erik Larkö <erik@mullvad.net> | 2017-05-28 22:26:55 +0200 |
|---|---|---|
| committer | Erik Larkö <erik@mullvad.net> | 2017-06-09 02:59:53 +0200 |
| commit | 25b22eec3881b7f0c83b1de2db1544506cdcf0a1 (patch) | |
| tree | e7948b224e13a970397f278b4ad9ec301440692a | |
| parent | 2e49dd1a621f3aea5c92f69eaf3f6338bc0e8784 (diff) | |
| download | mullvadvpn-25b22eec3881b7f0c83b1de2db1544506cdcf0a1.tar.xz mullvadvpn-25b22eec3881b7f0c83b1de2db1544506cdcf0a1.zip | |
Remove all "any" types
| -rw-r--r-- | app/lib/ipc-facade.js | 16 | ||||
| -rw-r--r-- | app/lib/jsonrpc-ws-ipc.js | 34 |
2 files changed, 34 insertions, 16 deletions
diff --git a/app/lib/ipc-facade.js b/app/lib/ipc-facade.js index 57305e9cab..d3c5ba94ba 100644 --- a/app/lib/ipc-facade.js +++ b/app/lib/ipc-facade.js @@ -49,19 +49,27 @@ export class RealIpc implements IpcFacade { } setAccount(accountNumber: AccountNumber): Promise<void> { - return this._ipc.send('set_account', accountNumber); + return this._ipc.send('set_account', accountNumber) + .then(this._ignoreResponse); + } + + _ignoreResponse(response: mixed): void { + return; } setCountry(address: string): Promise<void> { - return this._ipc.send('set_country', address); + return this._ipc.send('set_country', address) + .then(this._ignoreResponse); } connect(): Promise<void> { - return this._ipc.send('connect'); + return this._ipc.send('connect') + .then(this._ignoreResponse); } disconnect(): Promise<void> { - return this._ipc.send('disconnect'); + return this._ipc.send('disconnect') + .then(this._ignoreResponse); } getIp(): Promise<Ip> { diff --git a/app/lib/jsonrpc-ws-ipc.js b/app/lib/jsonrpc-ws-ipc.js index b31e683635..89964cb48f 100644 --- a/app/lib/jsonrpc-ws-ipc.js +++ b/app/lib/jsonrpc-ws-ipc.js @@ -4,9 +4,9 @@ import jsonrpc from 'jsonrpc-lite'; import uuid from 'uuid'; import log from 'electron-log'; -export type UnansweredRequest<T, E> = { - resolve: (T) => void, - reject: (E) => void, +export type UnansweredRequest = { + resolve: (mixed) => void, + reject: (mixed) => void, timeout: number, } @@ -25,7 +25,7 @@ export type JsonRpcNotification = { method: string, params: { subscription: string, - result: any, + result: mixed, } } } @@ -33,7 +33,7 @@ export type JsonRpcSuccess = { type: 'success', payload: { id: string, - result: any, + result: mixed, } } export type JsonRpcMessage = JsonRpcError | JsonRpcNotification | JsonRpcSuccess; @@ -61,8 +61,8 @@ export default class Ipc { _connectionString: ?string; _onConnect: Array<{resolve: ()=>void}>; - _unansweredRequests: {[string]: UnansweredRequest<any, any>}; - _subscriptions: {[string]: (any) => void}; + _unansweredRequests: {[string]: UnansweredRequest}; + _subscriptions: {[string|number]: (mixed) => void}; _websocket: WebSocket; _backoff: ReconnectionBackoff; _websocketFactory: (string) => WebSocket; @@ -84,7 +84,7 @@ export default class Ipc { this._sendTimeoutMillis = millis; } - on(event: string, listener: (any) => void): Promise<*> { + on(event: string, listener: (mixed) => void): Promise<*> { // We're currently not actually using the event parameter. // This is because we aren't sure if the backend will use // one subscription per event or one subscription per @@ -92,10 +92,16 @@ export default class Ipc { log.info('Adding a listener to', event); return this.send('event_subscribe') - .then(subscriptionId => this._subscriptions[subscriptionId] = listener); + .then(subscriptionId => { + if (typeof subscriptionId === 'string' || typeof subscriptionId === 'number') { + this._subscriptions[subscriptionId] = listener; + } else { + throw new InvalidReply(subscriptionId); + } + }); } - send(action: string, ...data: Array<any>): Promise<any> { + send(action: string, ...data: Array<mixed>): Promise<mixed> { return this._getWebSocket() .then(ws => this._send(ws, action, data)) .catch(e => { @@ -207,8 +213,12 @@ export default class Ipc { }; this._websocket.onmessage = (evt) => { - const data: string = (evt.data: any); - this._onMessage(data); + const data = evt.data; + if (typeof data === 'string') { + this._onMessage(data); + } else { + log.error('Got invalid reply from the server', evt); + } }; this._websocket.onclose = () => { |
