-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrenderer.js
75 lines (65 loc) · 2.13 KB
/
renderer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// All of the Node.js APIs are available in this process.
const shell = require('electron').shell;
const remote = require('electron').remote;
const safeApp = require('@maidsafe/safe-node-app');
const ipcRenderer = require('electron').ipcRenderer;
const isDevMode = process.execPath.match(/[\\/]electron/);
const app = remote.app;
const cwd = process.cwd();
const electronExt = process.platform === 'win32' ? '.cmd' : '';
const appInfo = {
id: 'net.safe.app.base.mock',
name: 'SAFE app base',
vendor: 'MaidSafe Ltd.',
customExecPath: isDevMode ? [`${process.execPath}`, `${app.getAppPath()}`] : [app.getPath('exe')]
}
// OSX: Add bundle for electron in dev mode
if (isDevMode && process.platform === 'darwin') {
appInfo.bundle = 'com.github.electron';
}
const containers = {
_public: [
'Read',
'Insert',
'Update',
'Delete',
'ManagePermissions'
],
_publicNames: [
'Read',
'Insert',
'Update',
'Delete',
'ManagePermissions'
]
};
const listenForAuthReponse = async (event, response) =>
{
const app = await safeApp.fromAuthUri(appInfo, response, null, { forceUseMock: true });
const mData = await app.mutableData.newRandomPublic(15001);
console.log(mData);
return;
};
ipcRenderer.on('auth-response', listenForAuthReponse);
const parseUrl = (url) => (
(url.indexOf('safe-auth://') === -1) ? url.replace('safe-auth:', 'safe-auth://') : url
);
const init = async ( ) =>
{
const app = await safeApp.initialiseApp(appInfo, null, { forceUseMock: true } );
const authUri = await app.auth.genAuthUri(containers, {own_container: false});
// const mdName = await app.crypto.sha3Hash('1010101010101');
// const permissions = [
// {
// typeTag: 15001,
// name: mdName,
// perms: ['Insert']
// }
// ];
// const shareMDataReqUri = await app.auth.genShareMDataUri(permissions);
shell.openExternal(authUri.uri);
};
init();
// let auth = safeApp.initializeApp(appInfo).then(app => app.auth.loginForTest()).then(console.log);