diff options
Diffstat (limited to 'app/lib')
| -rw-r--r-- | app/lib/backend.js | 30 | ||||
| -rw-r--r-- | app/lib/ipc-facade.js | 32 |
2 files changed, 52 insertions, 10 deletions
diff --git a/app/lib/backend.js b/app/lib/backend.js index f78d359926..da87deced4 100644 --- a/app/lib/backend.js +++ b/app/lib/backend.js @@ -139,6 +139,12 @@ export class Backend { log.error('Failed to fetch the location: ', e.message); } + try { + await this._fetchAllowLan(); + } catch(e) { + log.error('Failed to fetch the LAN sharing policy: ', e.message); + } + await this._fetchAccountHistory(); } @@ -339,8 +345,6 @@ export class Backend { } } - - async _fetchRelayLocations() { await this._ensureAuthenticated(); @@ -395,6 +399,28 @@ export class Backend { ); } + async setAllowLan(allowLan: boolean) { + try { + await this._ensureAuthenticated(); + await this._ipc.setAllowLan(allowLan); + + this._store.dispatch( + settingsActions.updateAllowLan(allowLan) + ); + } catch(e) { + log.error('Failed to change the LAN sharing policy: ', e.message); + } + } + + async _fetchAllowLan() { + await this._ensureAuthenticated(); + + const allowLan = await this._ipc.getAllowLan(); + this._store.dispatch( + settingsActions.updateAllowLan(allowLan) + ); + } + /** * 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 567a6ab8f1..b2676193ee 100644 --- a/app/lib/ipc-facade.js +++ b/app/lib/ipc-facade.js @@ -142,11 +142,13 @@ const RelayListSchema = object({ export interface IpcFacade { setConnectionString(string): void, getAccountData(AccountToken): Promise<AccountData>, + getRelayLocations(): Promise<RelayList>, getAccount(): Promise<?AccountToken>, setAccount(accountToken: ?AccountToken): Promise<void>, updateRelaySettings(RelaySettingsUpdate): Promise<void>, getRelaySettings(): Promise<RelaySettings>, - getRelayLocations(): Promise<RelayList>, + setAllowLan(boolean): Promise<void>, + getAllowLan(): Promise<boolean>, connect(): Promise<void>, disconnect(): Promise<void>, shutdown(): Promise<void>, @@ -186,6 +188,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); + } + } + getAccount(): Promise<?AccountToken> { return this._ipc.send('get_account') .then( raw => { @@ -223,13 +235,17 @@ 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); + setAllowLan(allowLan: boolean): Promise<void> { + return this._ipc.send('set_allow_lan', [allowLan]) + .then(this._ignoreResponse); + } + + async getAllowLan(): Promise<boolean> { + const raw = await this._ipc.send('get_allow_lan'); + if(typeof(raw) === 'boolean') { + return raw; + } else { + throw new InvalidReply(raw, 'Expected a boolean'); } } |
