Files: 3fa3e23c4b756580c6cf49253941a9e7d55b9023 / backup / html / backup.js
2465 bytesRaw
1 | const nest = require('depnest') |
2 | const { h, computed, Value, resolve } = require('mutant') |
3 | const electron = require('electron') |
4 | const { dialog } = require('electron').remote; |
5 | const path = require('path') |
6 | const fs = require('fs') |
7 | |
8 | exports.gives = nest({ |
9 | 'backup.html': ['exportIdentityButton', 'importIdentityButton'] |
10 | }) |
11 | |
12 | exports.needs = nest({ |
13 | 'app.html.lightbox': 'first', |
14 | 'keys.sync.id': 'first', |
15 | 'translations.sync.strings': 'first', |
16 | 'backup.async.exportIdentity': 'first' |
17 | }) |
18 | |
19 | exports.create = (api) => { |
20 | return nest('backup.html', { exportIdentityButton, importIdentityButton }) |
21 | |
22 | let strings = api.translations.sync.strings() |
23 | |
24 | function exportIdentityButton() { |
25 | let isOpen = Value(false) |
26 | let encryptionKeyRaw = Value('') |
27 | |
28 | let encryptionKeyInput = h('textarea#encryptionKey', { |
29 | style: { |
30 | width: '90%' |
31 | }, |
32 | placeholder: 'Please enter password to protect export file', |
33 | value: encryptionKeyRaw, |
34 | 'ev-input': () => encryptionKeyRaw.set(encryptionKeyInput.value), |
35 | }) |
36 | |
37 | let exportDialog = h('div.dialog', { |
38 | style: { |
39 | 'text-align': 'left' |
40 | } |
41 | }, |
42 | [ |
43 | h('div.message', [ |
44 | h('h1', 'Export Identity'), |
45 | h('p', 'Please backup your private key file very carefully.'), |
46 | h('p', 'If your private key is hacked, all your private messages will be retrieved by third party, and your identity will be faked on the network') |
47 | ]), |
48 | h('div.form', [ |
49 | encryptionKeyInput |
50 | ]), |
51 | h('div.actions', [ |
52 | h('Button', { 'ev-click': () => isOpen.set(false) }, 'Cancel'), |
53 | h('Button -primary', { |
54 | 'ev-click': () => { |
55 | dialog.showSaveDialog( |
56 | { |
57 | title: 'Export Identity', |
58 | butttonLabel: 'Export Identity', |
59 | defaultPath: 'ticktack-identity.backup', |
60 | }, |
61 | (filename) => api.backup.async.exportIdentity( |
62 | resolve(encryptionKeyRaw), filename, () => isOpen.set(false) |
63 | ) |
64 | ) |
65 | } |
66 | }, 'Export Identity') |
67 | ]) |
68 | ]) |
69 | |
70 | let lb = api.app.html.lightbox(exportDialog, isOpen) |
71 | |
72 | return h('div.backupKeys', [ |
73 | h('Button -backup', { 'ev-click': () => isOpen.set(true) }, 'Export Keys'), |
74 | lb |
75 | ]) |
76 | } |
77 | |
78 | function importIdentityButton() { |
79 | return h('div.backupKeys', [ |
80 | h('Button -backup', 'Import Keys') |
81 | ]) |
82 | } |
83 | } |
84 |
Built with git-ssb-web