summaryrefslogtreecommitdiffhomepage
path: root/gui/src
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2019-03-28 16:46:43 +0100
committerAndrej Mihajlov <and@mullvad.net>2019-03-28 16:46:43 +0100
commitc399cbe64ee2744d5917074e0b203cd353942403 (patch)
tree71ccb73f47d6f50219c9974835a2718a8e4349e8 /gui/src
parent58de89db26d7360783060cee0130a439b0f0c8da (diff)
downloadmullvadvpn-c399cbe64ee2744d5917074e0b203cd353942403.tar.xz
mullvadvpn-c399cbe64ee2744d5917074e0b203cd353942403.zip
Handle relay_list events in GUI
Diffstat (limited to 'gui/src')
-rw-r--r--gui/src/main/daemon-rpc.ts3
-rw-r--r--gui/src/main/index.ts29
-rw-r--r--gui/src/shared/daemon-rpc-types.ts5
3 files changed, 9 insertions, 28 deletions
diff --git a/gui/src/main/daemon-rpc.ts b/gui/src/main/daemon-rpc.ts
index 4464db6688..7897aba7c9 100644
--- a/gui/src/main/daemon-rpc.ts
+++ b/gui/src/main/daemon-rpc.ts
@@ -303,6 +303,9 @@ const daemonEventSchema = oneOf(
object({
settings: settingsSchema,
}),
+ object({
+ relay_list: relayListSchema,
+ }),
);
export class ResponseParseError extends Error {
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts
index d8b558ddcb..6080c80af2 100644
--- a/gui/src/main/index.ts
+++ b/gui/src/main/index.ts
@@ -28,7 +28,6 @@ import ReconnectionBackoff from './reconnection-backoff';
import TrayIconController, { TrayIconType } from './tray-icon-controller';
import WindowController from './window-controller';
-const RELAY_LIST_UPDATE_INTERVAL = 60 * 60 * 1000;
const VERSION_UPDATE_INTERVAL = 24 * 60 * 60 * 1000;
const DAEMON_RPC_PATH =
@@ -96,7 +95,6 @@ class ApplicationMain {
private lastDisconnectedLocation?: ILocation;
private relays: IRelayList = { countries: [] };
- private relaysInterval?: NodeJS.Timeout;
private currentVersion: ICurrentAppVersionInfo = {
daemon: '',
@@ -417,7 +415,6 @@ class ApplicationMain {
this.fetchLatestVersion();
// start periodic updates
- this.startRelaysPeriodicUpdates();
this.startLatestVersionPeriodicUpdates();
// notify user about inconsistent version
@@ -447,7 +444,6 @@ class ApplicationMain {
this.connectedToDaemon = false;
// stop periodic updates
- this.stopRelaysPeriodicUpdates();
this.stopLatestVersionPeriodicUpdates();
// notify renderer process
@@ -498,6 +494,8 @@ class ApplicationMain {
this.setTunnelState(daemonEvent.stateTransition);
} else if ('settings' in daemonEvent) {
this.setSettings(daemonEvent.settings);
+ } else if ('relayList' in daemonEvent) {
+ this.setRelays(daemonEvent.relayList, this.settings.relaySettings);
}
},
(error: Error) => {
@@ -605,29 +603,6 @@ class ApplicationMain {
};
}
- private startRelaysPeriodicUpdates() {
- log.debug('Start relays periodic updates');
-
- const handler = async () => {
- try {
- this.setRelays(await this.daemonRpc.getRelayLocations(), this.settings.relaySettings);
- } catch (error) {
- log.error(`Failed to fetch relay locations: ${error.message}`);
- }
- };
-
- this.relaysInterval = global.setInterval(handler, RELAY_LIST_UPDATE_INTERVAL);
- }
-
- private stopRelaysPeriodicUpdates() {
- if (this.relaysInterval) {
- clearInterval(this.relaysInterval);
- this.relaysInterval = undefined;
-
- log.debug('Stop relays periodic updates');
- }
- }
-
private setDaemonVersion(daemonVersion: string) {
const guiVersion = app.getVersion().replace('.0', '');
const versionInfo = {
diff --git a/gui/src/shared/daemon-rpc-types.ts b/gui/src/shared/daemon-rpc-types.ts
index a3080b7590..6b29ddd764 100644
--- a/gui/src/shared/daemon-rpc-types.ts
+++ b/gui/src/shared/daemon-rpc-types.ts
@@ -41,7 +41,10 @@ export interface ITunnelEndpoint {
tunnel: TunnelType;
}
-export type DaemonEvent = { stateTransition: TunnelStateTransition } | { settings: ISettings };
+export type DaemonEvent =
+ | { stateTransition: TunnelStateTransition }
+ | { settings: ISettings }
+ | { relayList: IRelayList };
export type TunnelStateTransition =
| { state: 'disconnected' }