summaryrefslogtreecommitdiffhomepage
path: root/app/lib/ipc-facade.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/lib/ipc-facade.js')
-rw-r--r--app/lib/ipc-facade.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/app/lib/ipc-facade.js b/app/lib/ipc-facade.js
index 89c29ce795..19daf71b97 100644
--- a/app/lib/ipc-facade.js
+++ b/app/lib/ipc-facade.js
@@ -18,6 +18,7 @@ const LocationSchema = object({
city: string,
});
+export type BackendState = 'secured' | 'unsecured';
export interface IpcFacade {
getAccountData(AccountNumber): Promise<AccountData>,
@@ -27,6 +28,8 @@ export interface IpcFacade {
disconnect(): Promise<void>,
getIp(): Promise<Ip>,
getLocation(): Promise<Location>,
+ getState(): Promise<BackendState>,
+ registerStateListener((BackendState) => void): void,
}
export class RealIpc implements IpcFacade {
@@ -93,4 +96,27 @@ export class RealIpc implements IpcFacade {
}
});
}
+
+ getState(): Promise<BackendState> {
+ return this._ipc.send('get_state')
+ .then(raw => {
+ return this._parseBackendState(raw);
+ });
+ }
+
+ _parseBackendState(raw: mixed): BackendState {
+ if (raw === 'secured' || raw === 'unsecured') {
+ return raw;
+ } else {
+ throw new InvalidReply(raw);
+ }
+ }
+
+ registerStateListener(listener: (BackendState) => void) {
+ this._ipc.on('new_state', (rawEvent) => {
+ const parsedEvent : BackendState = this._parseBackendState(rawEvent);
+
+ listener(parsedEvent);
+ });
+ }
}