Skip to content

Commit d5b1401

Browse files
gideonairexCMCDragonkai
authored andcommitted
feature: udpate store
1 parent fb500ea commit d5b1401

File tree

13 files changed

+277
-37
lines changed

13 files changed

+277
-37
lines changed

.prettierrc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
2-
"semi": true,
3-
"trailingComma": "all",
2+
"semi": false,
43
"singleQuote": true,
54
"printWidth": 120,
65
"tabWidth": 2
7-
}
6+
}

src/main/setHandlers.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,16 @@ async function setHandlers() {
376376
return res.serializeBinary();
377377
});
378378

379+
ipcMain.handle('RegisterNode', async (event, request) => {
380+
if (!client) {
381+
await getAgentClient();
382+
}
383+
const res = (await promisifyGrpc(client.registerNode.bind(client))(
384+
pb.StringMessage.deserializeBinary(request),
385+
)) as pb.BooleanMessage;
386+
return res.serializeBinary();
387+
});
388+
379389
ipcMain.handle('RevokeOAuthToken', async (event, request) => {
380390
if (!client) {
381391
await getAgentClient();

src/renderer/App.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<template>
22
<div style="background: LightGrey;">
33
<div class="demo-container">
4+
<Alert />
45
<!-- Drawer -->
56
<Drawer />
67
<!-- Content -->
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const polykeyClient = {
2+
listKeys: () => {
3+
return ['some-key']
4+
},
5+
listPeers: () => {
6+
return ['some-peer']
7+
},
8+
listSecrets: (vaultName: string) => {
9+
return ['some-secret']
10+
},
11+
listVaults: () => {
12+
return ['some-vault']
13+
},
14+
deleteKey: (keyName: string) => {
15+
return true
16+
},
17+
getPrimaryKeyPair: (includePrivateKey: boolean) => {
18+
return {
19+
public: 'public key',
20+
private: 'private key'
21+
}
22+
},
23+
updateSecret: (vaultName: string, secretName: string, secretContent: Buffer) => {
24+
return true
25+
},
26+
newVault: (vaultName: string) => {
27+
return true
28+
},
29+
createSecret: (vaultName: string, secretName: string, secretContent: Buffer) => {
30+
return true
31+
},
32+
getSecret: (vaultName: string, secretName: string) => {
33+
return Buffer.from('some secret content')
34+
},
35+
getKey: (keyName: string) => {
36+
return 'key content'
37+
},
38+
getAgentStatus: () => {
39+
return 'online'
40+
},
41+
unlockNode: (passphrase: string) => {
42+
return true
43+
},
44+
deleteVault: (vaultName: string) => {
45+
return true
46+
},
47+
deriveKey: (keyName: string, keyContent: string) => {
48+
return true
49+
},
50+
deleteSecret: (vaultName: string, secretName: string) => {
51+
return true
52+
}
53+
}
54+
55+
export { polykeyClient }

src/renderer/store/PolykeyClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,9 @@ class PolykeyClient {
238238
);
239239
return res.getB();
240240
}
241-
static async RegisterNode(polykeyPath: string): Promise<boolean> {
241+
static async RegisterNode(passphrase: string): Promise<boolean> {
242242
const encodedRequest = new pb.StringMessage();
243-
encodedRequest.setS(polykeyPath);
243+
encodedRequest.setS(passphrase);
244244
const res = pb.BooleanMessage.deserializeBinary(
245245
await ipcRenderer.invoke('RegisterNode', encodedRequest.serializeBinary()),
246246
);

src/renderer/store/modules/Alert.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
export default {
22
namespaced: true,
33
state: {
4-
visible: false
4+
visible: false,
5+
color: 'success'
56
},
67
actions: {
7-
toggle: (context) => {
8-
context.commit('toggle')
8+
toggleAlert: function(
9+
context,
10+
props: { visible: boolean; type: 'success' | 'warning' | 'error' | 'info'; message?: string }
11+
) {
12+
context.commit('setVisible', props)
913
}
1014
},
1115
mutations: {
12-
toggle: (state) => {
13-
state.visible = !state.visible
16+
setVisible: function(
17+
state,
18+
{ visible, type, message }: { visible: boolean; type: 'success' | 'warning' | 'error' | 'info'; message?: string }
19+
): void {
20+
state.visible = visible
21+
state.color = type
22+
state.message = message ?? ''
1423
}
15-
},
16-
getters: {}
24+
}
1725
}
1826
// import { VuexModule, Module, Mutation, Action } from 'vuex-module-decorators'
1927

@@ -34,4 +42,4 @@ export default {
3442
// }
3543
// }
3644

37-
// export default Alert
45+
// export default Alert

src/renderer/store/modules/Configuration.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
export default {
22
namespaced: true,
3-
state: {},
4-
actions: {},
5-
mutations: {},
6-
getters: {}
3+
state: {
4+
activeNodePath: '~/.polykey',
5+
nodePathList: []
6+
},
7+
actions: {
8+
selectNodePath: function(context, activeNodePath) {
9+
context.commit('selectNodePath', activeNodePath)
10+
},
11+
loadNodePathList: function(context) {
12+
context.commit('loadNodePathList')
13+
}
14+
},
15+
mutations: {
16+
selectNodePath: function(state, activeNodePath) {
17+
state.activeNodePath = activeNodePath
18+
},
19+
loadNodePathList: function(state) {
20+
state.nodePathList = [state.activeNodePath]
21+
}
22+
}
723
}
824
// import store from '@/store'
925
// import { getModule, Module, MutationAction, VuexModule } from 'vuex-module-decorators'
@@ -31,4 +47,3 @@ export default {
3147

3248
// export default Configuration
3349
// export { getConfiguration }
34-

src/renderer/store/modules/ConfirmationDialog.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
11
export default {
22
namespaced: true,
3-
state: {},
4-
actions: {},
5-
mutations: {},
6-
getters: {}
3+
state: {
4+
isOpen: false,
5+
confirmed: false
6+
},
7+
actions: {
8+
toggleOpen: function({ commit, state }, isOpen) {
9+
commit('setOpen', isOpen ?? !state.isOpen)
10+
},
11+
confirm: function({ commit, state }) {
12+
commit('setConfirmed', !state.confirm)
13+
}
14+
},
15+
mutations: {
16+
setOpen: function(state, open) {
17+
state.open = open
18+
},
19+
setConfirmed: function(state, confirmed) {
20+
state.confirmed = confirmed
21+
state.isOpen = false
22+
}
23+
}
724
}
825
// import { VuexModule, Module, Mutation, Action } from 'vuex-module-decorators'
926

src/renderer/store/modules/Drawer.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
11
export default {
22
namespaced: true,
3-
state: {},
4-
actions: {},
5-
mutations: {},
3+
state: {
4+
isOpen: false,
5+
selectedRoute: '/'
6+
},
7+
actions: {
8+
toggleDrawer: function({ commit, state }, isOpen?: boolean) {
9+
commit('setDrawer', isOpen ?? !state.isOpen)
10+
},
11+
selectRoute: function({ commit }, route: string) {
12+
commit('setSelectedRoute', route)
13+
}
14+
},
15+
mutations: {
16+
setDrawer: function(state, open) {
17+
state.open = open
18+
},
19+
setSelectedRoute: function(state, route) {
20+
state.selectedRoute = route
21+
}
22+
},
623
getters: {}
724
}
825
// import { VuexModule, Module, Mutation, Action } from 'vuex-module-decorators'

src/renderer/store/modules/Keys.ts

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,50 @@
1+
import { polykeyClient } from '@/store/PolyKeyClientMock'
2+
13
export default {
24
namespaced: true,
3-
state: {},
4-
actions: {},
5-
mutations: {},
5+
state: {
6+
publicKey: '',
7+
privateKey: '',
8+
keyNames: [],
9+
selectedKeyName: '',
10+
selectedKeyContent: ''
11+
},
12+
actions: {
13+
loadKeyNames: async function({ commit }) {
14+
const keyNames = await polykeyClient.listKeys()
15+
commit('loadKeyNames', keyNames)
16+
},
17+
deleteKey: async function({ commit, state }, keyName) {
18+
const successful = await polykeyClient.deleteKey(keyName)
19+
if (successful) {
20+
const keyNames = await polykeyClient.listKeys()
21+
return commit('loadKeyNames', keyNames)
22+
} else {
23+
return commit('loadKeyNames', state.keyNames)
24+
}
25+
},
26+
loadKeyPair: async function({ commit }) {
27+
const keyPair = await polykeyClient.getPrimaryKeyPair(true)
28+
commit('loadKeyPair', { publicKey: keyPair.public, privateKey: keyPair.private })
29+
},
30+
selectKey: async function({ commit }, keyName: string) {
31+
const keyContent = await polykeyClient.getKey(keyName)
32+
commit('selectKey', { selectedKeyName: keyName, selectedKeyContent: keyContent })
33+
}
34+
},
35+
mutations: {
36+
loadKeyNames: function(state, keyNames) {
37+
state.keyNames = keyNames
38+
},
39+
loadKeyPair: function(state, { publicKey, privateKey }: { publicKey: string; privateKey: string }) {
40+
state.publicKey = publicKey
41+
state.privateKey = privateKey
42+
},
43+
selectKey: function(state, { selectedKeyName, selectedKeyContent }) {
44+
state.selectedKeyName = selectedKeyName
45+
state.selectedKeyContent = selectedKeyContent
46+
}
47+
},
648
getters: {}
749
}
850
// import { polykeyClient } from '@/store'

0 commit comments

Comments
 (0)