Files: e82f383b2cc56a63e4afa6eb79a83f8b874713f6 / backup / html / backup.js
1693 bytesRaw
1 | const nest = require('depnest') |
2 | const { h, Value, computed } = require('mutant') |
3 | const { dialog } = require('electron').remote |
4 | |
5 | exports.gives = nest({ |
6 | 'backup.html': ['exportIdentityButton'] |
7 | }) |
8 | |
9 | exports.needs = nest({ |
10 | 'app.html.lightbox': 'first', |
11 | 'keys.sync.id': 'first', |
12 | 'translations.sync.strings': 'first', |
13 | 'backup.async.exportIdentity': 'first' |
14 | }) |
15 | |
16 | exports.create = (api) => { |
17 | return nest('backup.html.exportIdentityButton', () => { |
18 | const strings = api.translations.sync.strings() |
19 | |
20 | const exporting = Value() |
21 | const success = Value() |
22 | |
23 | function exportAction () { |
24 | exporting.set(true) |
25 | success.set() // the resets the tick if there are multiple backup exports done |
26 | |
27 | let feedFragment = api.keys.sync.id().slice(1, 6) |
28 | dialog.showSaveDialog( |
29 | { |
30 | title: strings.backup.export.dialog.title, |
31 | butttonLabel: strings.backup.export.dialog.label, |
32 | defaultPath: `ticktack-identity-${feedFragment}.backup` |
33 | }, |
34 | (filename) => api.backup.async.exportIdentity(filename, (err, res) => { |
35 | exporting.set(false) |
36 | if (err) { |
37 | console.error(err) |
38 | success.set(false) |
39 | } else { |
40 | console.log('exported') |
41 | success.set(true) |
42 | } |
43 | }) |
44 | ) |
45 | } |
46 | |
47 | return h('div.backupKeys', [ |
48 | h('Button -backup', { 'ev-click': exportAction }, strings.backup.export.exportAction), |
49 | computed([exporting, success], (exporting, success) => { |
50 | if (success === true) return h('i.fa.fa-check') |
51 | if (success === false) return h('i.fa.fa-times') |
52 | |
53 | if (exporting) return h('i.fa.fa-spinner.fa-pulse') |
54 | }) |
55 | ]) |
56 | }) |
57 | } |
58 |
Built with git-ssb-web