Skip to content

Commit 09f862d

Browse files
gideonairexCMCDragonkai
authored andcommitted
chore: secrets refactor, add system tray actions, add peers view and misc.
updates, add misc. views and functionality
1 parent 849be10 commit 09f862d

32 files changed

+21185
-25022
lines changed

nix/default.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ let
6464
in
6565

6666
stdenv.mkDerivation rec {
67-
pname = "polykey";
67+
pname = "polykey-gui";
6868
version = "0.0.1";
6969
name = "${pname}-${version}";
7070

@@ -136,7 +136,7 @@ stdenv.mkDerivation rec {
136136
mv "$PWD/node_modules" "$out/lib/"
137137
declare target="$(readlink -f "$out/lib/node_modules")"
138138
ln -s -T "$target/js-polykey/bin/polykey" "$out/bin/pk"
139-
ln -s -T "$target/js-polykey/bin/polykey" "$out/bin/polykey-cli"
139+
ln -s -T "$target/js-polykey/bin/polykey" "$out/bin/polykey"
140140
rm -r "$out/lib/node_modules"
141141
142142
ln -s -t "$out/bin" "$out_elec_exe"

nix/generated/node-packages.nix

Lines changed: 2118 additions & 3376 deletions
Large diffs are not rendered by default.

package-lock.json

Lines changed: 17896 additions & 20576 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,15 @@
2828
"test": "jest"
2929
},
3030
"dependencies": {
31-
"@matrixai/pagination": "^0.1.0",
32-
"@matrixai/polykey": "^0.0.22",
33-
"async-mutex": "^0.2.4",
31+
"@matrixai/polykey": "^0.0.23",
3432
"balm-ui": "^9.0.0-rc.4",
35-
"buffer-json": "^2.0.0",
36-
"core-js": "^3.6.5",
37-
"protobufjs": "^6.10.1",
38-
"readable-stream": "^3.6.0",
39-
"scrypt-js": "^3.0.1",
40-
"source-map-support": "^0.5.19",
4133
"vue": "^3.0.2",
4234
"vue-router": "^4.0.0-0",
4335
"vuex": "^4.0.0-0"
4436
},
4537
"devDependencies": {
46-
"@fortawesome/fontawesome-free": "^5.13.1",
4738
"@types/jest": "^25.0.0",
4839
"@types/node": "^13.13.1",
49-
"@types/oauth2orize": "^1.8.8",
5040
"@typescript-eslint/eslint-plugin": "^3.7.1",
5141
"@typescript-eslint/parser": "^4.0.1",
5242
"@vue/cli": "^4.5.8",
@@ -60,7 +50,6 @@
6050
"concurrently": "^5.3.0",
6151
"cross-env": "^7.0.2",
6252
"css-loader": "^4.3.0",
63-
"deepmerge": "^4.2.2",
6453
"electron-builder": "^22.9.1",
6554
"electron-packager": "^15.0.0",
6655
"eslint": "^7.6.0",
@@ -70,16 +59,13 @@
7059
"eslint-plugin-promise": "^4.2.1",
7160
"eslint-plugin-standard": "^4.0.1",
7261
"eslint-plugin-vue": "^7.0.0-0",
73-
"fibers": "^5.0.0",
7462
"file-loader": "^6.1.0",
7563
"html-webpack-plugin": "^4.5.0",
7664
"jest": "^25.0.0",
7765
"mini-css-extract-plugin": "^1.2.0",
78-
"node-sass": "^4.12.0",
7966
"npm-run-all": "^4.1.5",
8067
"prettier": "^1.19.1",
8168
"rimraf": "^3.0.2",
82-
"serve": "^11.3.2",
8369
"storybook": "^5.3.19",
8470
"ts-loader": "^8.0.7",
8571
"ts-node": "^8.8.2",

src/main/index.ts

Lines changed: 62 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
2-
import url from 'url';
31
import path from 'path';
2+
import { promisifyGrpc } from './utils';
3+
import setHandlers, { polykeyPath } from './setHandlers'
4+
import * as pb from '@matrixai/polykey/proto/compiled/Agent_pb';
45
import { app, BrowserWindow, Menu, Tray, shell } from "electron";
5-
import setHandlers from './setHandlers'
6+
import { PolykeyAgent } from '@matrixai/polykey';
67

78
setHandlers()
89

910
const isDevelopment = process.env.NODE_ENV !== 'production'
1011

1112
// global reference to mainWindow (necessary to prevent window from being garbage collected)
12-
let mainWindow
13+
let mainWindow: BrowserWindow | null
1314

1415
// Make tray
15-
let tray
16+
let tray: Tray
1617

1718
function createWindow() {
1819
// Create the browser window.
@@ -39,46 +40,71 @@ function createWindow() {
3940
shell.openExternal(url);
4041
});
4142

42-
// window.on('minimize', function (event) {
43-
// event.preventDefault()
44-
// mainWindow.hide()
45-
// })
43+
window.on('minimize', function (event) {
44+
event.preventDefault()
45+
mainWindow?.hide()
46+
})
4647

47-
window.webContents.openDevTools()
48+
if (isDevelopment) {
49+
window.webContents.openDevTools()
50+
}
4851
return window
4952
}
5053

51-
// function createTray() {
52-
// const logoPath = path.join(__static, 'logo.png')
53-
54-
// tray = new Tray(logoPath)
55-
56-
// const contextMenu = Menu.buildFromTemplate([
57-
// {
58-
// label: 'Show App', click: function () {
59-
// mainWindow = createWindow()
60-
// mainWindow.show()
61-
// }
62-
// },
63-
// {
64-
// label: 'Quit', click: function () {
65-
// app.quit()
66-
// }
67-
// }
68-
// ])
69-
70-
// tray.setContextMenu(contextMenu)
71-
// }
72-
73-
app.on("ready", () => {
54+
function createTray() {
55+
const logoPath = path.join(__static, 'logo.png')
56+
57+
tray = new Tray(logoPath)
58+
59+
const contextMenu = Menu.buildFromTemplate([
60+
{
61+
label: 'Show App', click: () => {
62+
if (mainWindow === null) {
63+
mainWindow = createWindow()
64+
mainWindow.show()
65+
} else {
66+
mainWindow.show()
67+
mainWindow.focus()
68+
}
69+
}
70+
},
71+
{
72+
label: 'Kill Agent', click: async () => {
73+
// kill polykey-agent process
74+
try {
75+
const client = PolykeyAgent.connectToAgent(polykeyPath);
76+
const successful = await promisifyGrpc(client.stopAgent.bind(client))(new pb.EmptyMessage)
77+
if (successful) {
78+
console.log('agent has been stopped');
79+
} else {
80+
console.log('agent could not be stopped');
81+
}
82+
} catch (error) {
83+
console.log('agent could not be stopped');
84+
}
85+
app.quit()
86+
tray.destroy()
87+
}
88+
},
89+
{
90+
label: 'Quit App', click: () => {
91+
app.quit()
92+
tray.destroy()
93+
}
94+
}
95+
])
96+
97+
tray.setContextMenu(contextMenu)
98+
}
99+
100+
app.on('ready', () => {
74101
mainWindow = createWindow()
75102

76-
// createTray()
103+
createTray()
77104
});
78105

79-
80106
//quit the app once closed
81-
app.on("window-all-closed", function () {
107+
app.on("window-all-closed", async () => {
82108
if (process.platform != "darwin") {
83109
app.quit();
84110
}

src/main/setHandlers.ts

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import os from 'os';
2-
import { ipcMain } from 'electron';
3-
import { PolykeyAgent } from '@matrixai/polykey';
2+
import { ipcMain, clipboard } from 'electron';
3+
import { promisifyGrpc } from './utils';
4+
import { PolykeyAgent, PeerInfo } from '@matrixai/polykey';
45
import * as pb from '@matrixai/polykey/proto/compiled/Agent_pb';
56
import { AgentClient } from '@matrixai/polykey/proto/compiled/Agent_grpc_pb';
6-
import { promisifyGrpc } from './utils';
77

88
let polykeyPath: string = resolveTilde('~/.polykey')
99
let client: AgentClient;
@@ -12,7 +12,7 @@ async function getAgentClient(failOnNotInitialized: boolean = true) {
1212
// make sure agent is running
1313
console.log(polykeyPath);
1414

15-
const x = await PolykeyAgent.startAgent(polykeyPath, false, failOnNotInitialized);
15+
await PolykeyAgent.startAgent(polykeyPath, false, failOnNotInitialized);
1616

1717
client = PolykeyAgent.connectToAgent(polykeyPath);
1818

@@ -32,6 +32,19 @@ function resolveTilde(filePath: string) {
3232
}
3333

3434
async function setHandlers() {
35+
///////////////////////
36+
// Clipboard control //
37+
///////////////////////
38+
ipcMain.handle('ClipboardCopy', async (event, secretContent: string) => {
39+
clipboard.writeText(secretContent)
40+
setTimeout(() => {
41+
if (clipboard.readText() == secretContent) {
42+
clipboard.clear()
43+
clipboard.writeText('')
44+
}
45+
}, 30000)
46+
});
47+
3548
///////////////////
3649
// agent control //
3750
///////////////////
@@ -60,6 +73,7 @@ async function setHandlers() {
6073
});
6174

6275
ipcMain.handle('agent-restart', async (event, request) => {
76+
const client = PolykeyAgent.connectToAgent(polykeyPath);
6377
await promisifyGrpc(client.stopAgent.bind(client))(new pb.EmptyMessage());
6478
const pid = <number>await PolykeyAgent.startAgent(polykeyPath);
6579
await getAgentClient();
@@ -79,6 +93,29 @@ async function setHandlers() {
7993
return res.serializeBinary();
8094
});
8195

96+
ipcMain.handle('AddPeerB64', async (event, b64String) => {
97+
if (!client) {
98+
await getAgentClient();
99+
}
100+
const {
101+
publicKey,
102+
rootCertificate,
103+
peerAddress,
104+
apiAddress
105+
} = PeerInfo.parseB64(b64String)
106+
const request = new pb.PeerInfoMessage
107+
request.setPublicKey(publicKey)
108+
request.setRootCertificate(rootCertificate)
109+
if (peerAddress) {
110+
request.setPeerAddress(peerAddress.toString())
111+
}
112+
if (apiAddress) {
113+
request.setApiAddress(apiAddress.toString())
114+
}
115+
const res = (await promisifyGrpc(client.addPeer.bind(client))(request)) as pb.BooleanMessage;
116+
return res.serializeBinary();
117+
});
118+
82119
ipcMain.handle('DecryptFile', async (event, request) => {
83120
if (!client) {
84121
await getAgentClient();
@@ -300,15 +337,10 @@ async function setHandlers() {
300337
});
301338

302339
ipcMain.handle('NewNode', async (event, request) => {
303-
if (!client) {
304-
await getAgentClient(false);
305-
}
306-
console.log('heyyyyy2');
340+
await getAgentClient(false);
307341
const res = (await promisifyGrpc(client.newNode.bind(client))(
308342
pb.NewNodeMessage.deserializeBinary(request),
309343
)) as pb.BooleanMessage;
310-
console.log('heyyyyy3');
311-
console.log(res);
312344
return res.serializeBinary();
313345
});
314346

@@ -376,7 +408,7 @@ async function setHandlers() {
376408
if (!client) {
377409
await getAgentClient();
378410
}
379-
const res = (await promisifyGrpc(client.revokeOAuthToken.bind(client))(
411+
const res = (await promisifyGrpc(client.scanVaultNames.bind(client))(
380412
pb.StringMessage.deserializeBinary(request),
381413
)) as pb.BooleanMessage;
382414
return res.serializeBinary();
@@ -462,3 +494,4 @@ async function setHandlers() {
462494
}
463495

464496
export default setHandlers;
497+
export { polykeyPath }
Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
import Vue from "vue";
2-
import path from 'path';
3-
import Vuetify from "vuetify";
4-
import 'vuetify/dist/vuetify.min.css';
5-
import "@fortawesome/fontawesome-free/css/all.css"; // Ensure you are using css-loader
6-
import MatrixAIIcon from "./MatrixAIIcon.vue";
1+
// import Vue from "vue";
2+
// import path from 'path';
3+
// import Vuetify from "vuetify";
4+
// import 'vuetify/dist/vuetify.min.css';
5+
// import "@fortawesome/fontawesome-free/css/all.css"; // Ensure you are using css-loader
6+
// import MatrixAIIcon from "./MatrixAIIcon.vue";
77

8-
Vue.use(Vuetify);
8+
// Vue.use(Vuetify);
99

10-
export default new Vuetify({
11-
theme: {
12-
themes: {
13-
light: {
14-
primary: "#02243E",
15-
secondary: "#00CBD8"
16-
},
17-
dark: {
18-
primary: '#1976D2',
19-
secondary: '#424242',
20-
accent: '#82B1FF',
21-
error: '#FF5252',
22-
info: '#2196F3',
23-
success: '#4CAF50',
24-
warning: '#FFC107',
25-
}
26-
}
27-
},
28-
icons: {
29-
iconfont: "fa",
30-
values: {
31-
MatrixAIIcon: {
32-
component: MatrixAIIcon
33-
}
34-
}
35-
}
36-
});
10+
// export default new Vuetify({
11+
// theme: {
12+
// themes: {
13+
// light: {
14+
// primary: "#02243E",
15+
// secondary: "#00CBD8"
16+
// },
17+
// dark: {
18+
// primary: '#1976D2',
19+
// secondary: '#424242',
20+
// accent: '#82B1FF',
21+
// error: '#FF5252',
22+
// info: '#2196F3',
23+
// success: '#4CAF50',
24+
// warning: '#FFC107',
25+
// }
26+
// }
27+
// },
28+
// icons: {
29+
// iconfont: "fa",
30+
// values: {
31+
// MatrixAIIcon: {
32+
// component: MatrixAIIcon
33+
// }
34+
// }
35+
// }
36+
// });

0 commit comments

Comments
 (0)