Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
feat: add live sites update
Browse files Browse the repository at this point in the history
  • Loading branch information
donskov committed Oct 6, 2020
1 parent ec3ce86 commit 8119999
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
8 changes: 5 additions & 3 deletions src/main/ipc_messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import container from './container';

const serverStorage = container.resolve(ServerStorage);

const sendToRenderers = (channel: string, data: any) => {
const sendToRenderers = (channel: string, data?: any) => {
const browserWindows = BrowserWindow.getAllWindows();

browserWindows.forEach((window) => {
Expand All @@ -32,8 +32,10 @@ const initServerEvents = () => {

event.returnValue = identities;
})
.on('ipc-identity-changed', () => {
sendToRenderers('ipc-2key-changed');
})
.on('ipc-2key-remove', async (event: IpcMainEvent, arg: any) => {

try {
const questionWindowResult = await windowsController.showQuestionWindow({
text: l10n.get('question.2key.remove', arg),
Expand All @@ -46,7 +48,7 @@ const initServerEvents = () => {

await serverStorage.removeIdentity(arg);

event.sender.send('ipc-2key-removed', arg);
event.sender.send('ipc-2key-changed');
}
} catch {
//
Expand Down
5 changes: 4 additions & 1 deletion src/main/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as crypto from 'crypto';
import { shell, app } from 'electron';
import { shell, app, ipcMain } from 'electron';
import { setEngine } from '2key-ratchet';
import * as wsServer from '@webcrypto-local/server';
import type { Cards } from '@webcrypto-local/cards';
Expand Down Expand Up @@ -232,6 +232,9 @@ export class Server {
})
.on('close', (e: any) => {
logger.info(`Close: ${e}`);
})
.on('identity_changed', () => {
ipcMain.emit('ipc-identity-changed');
});

this.server.listen('127.0.0.1:31337');
Expand Down
16 changes: 3 additions & 13 deletions src/renderer/containers/settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ class Root extends WindowProvider<IRootProps, IRootState> {
this.handleKeysListGet();
this.handleLoggingGet();

ipcRenderer.on('ipc-2key-removed', this.onKeyRemovedListener);
ipcRenderer.on('ipc-2key-changed', this.handleKeysListGet);
ipcRenderer.on('ipc-logging-status-changed', this.onLoggingChangedListener);
}

handleKeysListGet() {
handleKeysListGet = () => {
const list = ipcRenderer.sendSync('ipc-2key-list-get');

this.setState({
Expand All @@ -48,7 +48,7 @@ class Root extends WindowProvider<IRootProps, IRootState> {
isFetching: 'resolved',
},
});
}
};

handleLoggingGet() {
const status = ipcRenderer.sendSync('ipc-logging-status-get');
Expand All @@ -68,16 +68,6 @@ class Root extends WindowProvider<IRootProps, IRootState> {
});
};

onKeyRemovedListener = (_: IpcRendererEvent, origin: string) => {
this.setState((prevState) => ({
keys: {
...prevState.keys,
list: prevState.keys.list
.filter((key) => key.origin !== origin),
},
}));
};

onKeyRemove = (origin: string) => {
ipcRenderer.send('ipc-2key-remove', origin);
};
Expand Down

0 comments on commit 8119999

Please sign in to comment.