Commit 992639a1213cadc35e523df588f878128718bc5b
feature(backup): work in progress
andre alves garzia committed on 5/7/2018, 1:33:26 PMParent: 1b46fe809a87f906b19ab7dad059971d13730b4f
Files changed
app/index.js | changed |
app/page/settings.js | changed |
main.js | changed |
backup/html/backup.js | added |
backup/html/backup.mcss | added |
backup/index.js | added |
app/index.js | ||
---|---|---|
@@ -20,9 +20,9 @@ | ||
20 | 20 | sideNav: { |
21 | 21 | addressBook: require('./html/sideNav/sideNavAddressBook'), |
22 | 22 | discovery: require('./html/sideNav/sideNavDiscovery') |
23 | 23 | }, |
24 | - warning: require('./html/warning'), | |
24 | + warning: require('./html/warning') | |
25 | 25 | }, |
26 | 26 | obs: { |
27 | 27 | pluginsOk: require('./obs/pluginsOk'), |
28 | 28 | }, |
app/page/settings.js | ||
---|---|---|
@@ -16,9 +16,12 @@ | ||
16 | 16 | 'message.html.markdown': 'first', |
17 | 17 | 'settings.sync.get': 'first', |
18 | 18 | 'settings.sync.set': 'first', |
19 | 19 | 'settings.obs.get': 'first', |
20 | - 'translations.sync.strings': 'first' | |
20 | + 'translations.sync.strings': 'first', | |
21 | + 'backup.html.exportIdentityButton': 'first', | |
22 | + 'backup.html.importIdentityButton': 'first' | |
23 | + | |
21 | 24 | }) |
22 | 25 | |
23 | 26 | const LANGUAGES = ['zh', 'en'] |
24 | 27 | |
@@ -30,23 +33,25 @@ | ||
30 | 33 | |
31 | 34 | exports.create = (api) => { |
32 | 35 | return nest('app.page.settings', settings) |
33 | 36 | |
34 | - function settings (location) { | |
37 | + function settings(location) { | |
35 | 38 | // RESET the app when the settings are changed |
36 | 39 | api.settings.obs.get('language')(() => { |
37 | 40 | console.log('language changed, resetting view') |
38 | 41 | |
39 | 42 | // clear history back to start page |
40 | 43 | api.history.obs.store().set([ |
41 | 44 | { page: 'blogIndex' } |
42 | 45 | ]) |
43 | - api.history.sync.push({page: 'settings'}) | |
46 | + api.history.sync.push({ page: 'settings' }) | |
44 | 47 | }) |
45 | 48 | |
46 | 49 | const feed = api.keys.sync.id() |
47 | 50 | const strings = api.translations.sync.strings() |
48 | 51 | const currentLanguage = api.settings.sync.get('language') |
52 | + const exportIdentityButton = api.backup.html.exportIdentityButton() | |
53 | + const importIdentityButton = api.backup.html.importIdentityButton() | |
49 | 54 | |
50 | 55 | const editProfile = () => api.history.sync.push({ |
51 | 56 | page: 'userEdit', |
52 | 57 | feed, |
@@ -83,18 +88,26 @@ | ||
83 | 88 | h('div.right', LANGUAGES.map(Language)) |
84 | 89 | ]), |
85 | 90 | h('section -zoom', [ |
86 | 91 | h('div.left', strings.settingsPage.section.zoom), |
87 | - h('div.right', [ zoomButton(-0.1, '-'), zoomButton(+0.1, '+') ]) | |
92 | + h('div.right', [zoomButton(-0.1, '-'), zoomButton(+0.1, '+')]) | |
88 | 93 | ]), |
89 | 94 | h('section -version', [ |
90 | 95 | h('div.left', strings.settingsPage.section.version), |
91 | 96 | h('div.right', version) |
97 | + ]), | |
98 | + h('h1', ""), | |
99 | + h('section -backup', [ | |
100 | + h('div.left', 'Backup'), | |
101 | + h('div.right', [ | |
102 | + exportIdentityButton, | |
103 | + importIdentityButton | |
104 | + ]) | |
92 | 105 | ]) |
93 | 106 | ]) |
94 | 107 | ]) |
95 | 108 | |
96 | - function Language (lang) { | |
109 | + function Language(lang) { | |
97 | 110 | const selectLang = () => api.settings.sync.set({ language: lang }) |
98 | 111 | const className = currentLanguage === lang ? '-strong' : '' |
99 | 112 | |
100 | 113 | return h('Button -language', |
@@ -105,9 +118,9 @@ | ||
105 | 118 | strings.languages[lang] |
106 | 119 | ) |
107 | 120 | } |
108 | 121 | |
109 | - function zoomButton (increment, symbol) { | |
122 | + function zoomButton(increment, symbol) { | |
110 | 123 | const { getCurrentWebContents } = electron.remote |
111 | 124 | return h('Button -zoom', |
112 | 125 | { |
113 | 126 | 'ev-click': () => { |
main.js | ||
---|---|---|
@@ -29,9 +29,10 @@ | ||
29 | 29 | router: require('./router'), |
30 | 30 | styles: require('./styles'), |
31 | 31 | state: require('./state/obs'), |
32 | 32 | unread: require('./unread'), |
33 | - channel: require('./channel') | |
33 | + channel: require('./channel'), | |
34 | + backup: require('./backup') | |
34 | 35 | }, |
35 | 36 | { |
36 | 37 | profile: require('patch-profile'), |
37 | 38 | drafts: require('patch-drafts'), |
backup/html/backup.js | ||
---|---|---|
@@ -1,0 +1,62 @@ | ||
1 | +const nest = require('depnest') | |
2 | +const { h, computed, Value } = require('mutant') | |
3 | +const electron = require('electron') | |
4 | +const path = require('path') | |
5 | +const fs = require('fs') | |
6 | + | |
7 | +exports.gives = nest({ | |
8 | + 'backup.html': ['exportIdentityButton', 'importIdentityButton'] | |
9 | +}) | |
10 | + | |
11 | +exports.needs = nest({ | |
12 | + 'app.html.lightbox': 'first', | |
13 | + 'keys.sync.id': 'first', | |
14 | + 'translations.sync.strings': 'first' | |
15 | +}) | |
16 | + | |
17 | +exports.create = (api) => { | |
18 | + return nest('backup.html', { exportIdentityButton, importIdentityButton }) | |
19 | + | |
20 | + let feed = api.keys.sync.id() | |
21 | + let strings = api.translations.sync.strings() | |
22 | + | |
23 | + function exportIdentityButton() { | |
24 | + let isOpen = Value(false) | |
25 | + let encryptionKeyRaw = Value('') | |
26 | + let msg = "Your identity is represented by an ed25519 key pair. Please backup your private key file very carefully. 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" | |
27 | + let encryptionKeyInput = h('textarea#encryptionKey', { | |
28 | + style: { | |
29 | + width: '90%' | |
30 | + }, | |
31 | + placeholder: 'Please enter password to protect export file', | |
32 | + value: encryptionKeyRaw, | |
33 | + 'ev-input': () => encryptionKeyRaw.set(encryptionKeyInput.value), | |
34 | + }) | |
35 | + | |
36 | + let dialog = h('div.dialog', [ | |
37 | + h('div.message', [ | |
38 | + h('p', msg), | |
39 | + ]), | |
40 | + h('div.form', [ | |
41 | + encryptionKeyInput | |
42 | + ]), | |
43 | + h('div.actions', [ | |
44 | + h('Button', { 'ev-click': () => isOpen.set(false) }, 'Cancel'), | |
45 | + h('Button -primary', { 'ev-click': () => exportKey(resolve(encryptionKeyRaw), () => isOpen.set(false)) }, 'Export Keys') | |
46 | + ]) | |
47 | + ]) | |
48 | + | |
49 | + let lb = api.app.html.lightbox(dialog, isOpen) | |
50 | + | |
51 | + return h('div.backupKeys', [ | |
52 | + h('Button -backup', { 'ev-click': () => isOpen.set(true) }, 'Export Keys'), | |
53 | + lb | |
54 | + ]) | |
55 | + } | |
56 | + | |
57 | + function importIdentityButton() { | |
58 | + return h('div.backupKeys', [ | |
59 | + h('Button -backup', 'Import Keys') | |
60 | + ]) | |
61 | + } | |
62 | +} |
Built with git-ssb-web