diff options
| -rw-r--r-- | app/lib/ipc-facade.js | 39 | ||||
| -rw-r--r-- | test/mocks/ipc.js | 4 |
2 files changed, 43 insertions, 0 deletions
diff --git a/app/lib/ipc-facade.js b/app/lib/ipc-facade.js index a4cf9bdc9f..2fa4212622 100644 --- a/app/lib/ipc-facade.js +++ b/app/lib/ipc-facade.js @@ -108,6 +108,34 @@ const RelaySettingsSchema = oneOf( }) ); +export type RelayList = { + countries: Array<RelayListCountry>, +}; + +export type RelayListCountry = { + name: string, + code: string, + cities: Array<RelayListCity>, +}; + +export type RelayListCity = { + name: string, + code: string, + position: [Number, Number], +}; + +const RelayListSchema = object({ + countries: arrayOf(object({ + name: string, + code: string, + cities: arrayOf(object({ + name: string, + code: string, + position: arrayOf(number), + })), + })), +}); + export interface IpcFacade { setConnectionString(string): void, @@ -116,6 +144,7 @@ export interface IpcFacade { setAccount(accountToken: ?AccountToken): Promise<void>, updateRelaySettings(RelaySettingsUpdate): Promise<void>, getRelaySettings(): Promise<RelaySettings>, + getRelayLocations(): Promise<RelayList>, connect(): Promise<void>, disconnect(): Promise<void>, shutdown(): Promise<void>, @@ -192,6 +221,16 @@ export class RealIpc implements IpcFacade { }); } + async getRelayLocations(): Promise<RelayList> { + const raw = await this._ipc.send('get_relay_locations'); + try { + const validated: any = validate(RelayListSchema, raw); + return (validated: RelayList); + } catch (e) { + throw new InvalidReply(raw, e); + } + } + connect(): Promise<void> { return this._ipc.send('connect') .then(this._ignoreResponse); diff --git a/test/mocks/ipc.js b/test/mocks/ipc.js index 59655c03ab..ede4bd37b7 100644 --- a/test/mocks/ipc.js +++ b/test/mocks/ipc.js @@ -42,6 +42,10 @@ export function newMockIpc() { }, }), + getRelayLocations: () => Promise.resolve({ + countries: [], + }), + connect: () => Promise.resolve(), disconnect: () => Promise.resolve(), |
