Commit e58c4d2da8898b7d5899788712c73b904e3f7350
feature(backup): work in progress
andre alves garzia committed on 5/21/2018, 12:03:21 AMParent: c0dd626b0d708d6baff34a5f1e8fb399bc0119cd
Files changed
app/page/settings.js | changed |
main.js | changed |
backup/html/backup.js | added |
backup/html/backup.mcss | added |
backup/index.js | added |
app/page/settings.js | ||
---|---|---|
@@ -16,17 +16,20 @@ | ||
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 | |
25 | 28 | exports.create = (api) => { |
26 | 29 | return nest('app.page.settings', settings) |
27 | 30 | |
28 | - function settings (location) { | |
31 | + function settings(location) { | |
29 | 32 | // RESET the app when the settings are changed |
30 | 33 | api.settings.obs.get('language')(() => { |
31 | 34 | console.log('language changed, resetting view') |
32 | 35 | |
@@ -40,8 +43,10 @@ | ||
40 | 43 | const webSharingMetricsOption = api.settings.obs.get('ticktack.websharemetrics') |
41 | 44 | const feed = api.keys.sync.id() |
42 | 45 | const strings = api.translations.sync.strings() |
43 | 46 | const currentLanguage = api.settings.sync.get('language') |
47 | + const exportIdentityButton = api.backup.html.exportIdentityButton() | |
48 | + const importIdentityButton = api.backup.html.importIdentityButton() | |
44 | 49 | |
45 | 50 | const editProfile = () => api.history.sync.push({ |
46 | 51 | page: 'userEdit', |
47 | 52 | feed, |
@@ -95,13 +100,21 @@ | ||
95 | 100 | ]), |
96 | 101 | h('section -version', [ |
97 | 102 | h('div.left', strings.settingsPage.section.version), |
98 | 103 | h('div.right', version) |
104 | + ]), | |
105 | + h('h1', ""), | |
106 | + h('section -backup', [ | |
107 | + h('div.left', 'Backup'), | |
108 | + h('div.right', [ | |
109 | + exportIdentityButton, | |
110 | + importIdentityButton | |
111 | + ]) | |
99 | 112 | ]) |
100 | 113 | ]) |
101 | 114 | ]) |
102 | 115 | |
103 | - function Language (lang) { | |
116 | + function Language(lang) { | |
104 | 117 | const selectLang = () => api.settings.sync.set({ language: lang }) |
105 | 118 | const className = currentLanguage === lang ? '-strong' : '' |
106 | 119 | |
107 | 120 | return h('Button -language', |
@@ -112,9 +125,9 @@ | ||
112 | 125 | strings.languages[lang] |
113 | 126 | ) |
114 | 127 | } |
115 | 128 | |
116 | - function Theme (theme) { | |
129 | + function Theme(theme) { | |
117 | 130 | const currentTheme = api.settings.obs.get('ticktack.theme') |
118 | 131 | const className = computed(currentTheme, t => t === theme ? '-strong' : '') |
119 | 132 | |
120 | 133 | return h('Button -language', |
@@ -125,9 +138,9 @@ | ||
125 | 138 | strings.themes[theme] |
126 | 139 | ) |
127 | 140 | } |
128 | 141 | |
129 | - function zoomButton (increment, symbol) { | |
142 | + function zoomButton(increment, symbol) { | |
130 | 143 | const { getCurrentWebContents } = electron.remote |
131 | 144 | return h('Button -zoom', |
132 | 145 | { |
133 | 146 | 'ev-click': () => { |
@@ -140,9 +153,9 @@ | ||
140 | 153 | symbol |
141 | 154 | ) |
142 | 155 | } |
143 | 156 | |
144 | - function webSharingOption (v, label) { | |
157 | + function webSharingOption(v, label) { | |
145 | 158 | let myOption = computed(webSharingMetricsOption, opt => opt === v) |
146 | 159 | |
147 | 160 | const selectWebSharingOption = () => { |
148 | 161 | webSharingMetricsOption.set(v) |
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