git ssb

2+

mixmix / ticktack



Commit e58c4d2da8898b7d5899788712c73b904e3f7350

feature(backup): work in progress

andre alves garzia committed on 5/21/2018, 12:03:21 AM
Parent: c0dd626b0d708d6baff34a5f1e8fb399bc0119cd

Files changed

app/page/settings.jschanged
main.jschanged
backup/html/backup.jsadded
backup/html/backup.mcssadded
backup/index.jsadded
app/page/settings.jsView
@@ -16,17 +16,20 @@
1616 'message.html.markdown': 'first',
1717 'settings.sync.get': 'first',
1818 'settings.sync.set': 'first',
1919 '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+
2124 })
2225
2326 const LANGUAGES = ['zh', 'en']
2427
2528 exports.create = (api) => {
2629 return nest('app.page.settings', settings)
2730
28- function settings (location) {
31+ function settings(location) {
2932 // RESET the app when the settings are changed
3033 api.settings.obs.get('language')(() => {
3134 console.log('language changed, resetting view')
3235
@@ -40,8 +43,10 @@
4043 const webSharingMetricsOption = api.settings.obs.get('ticktack.websharemetrics')
4144 const feed = api.keys.sync.id()
4245 const strings = api.translations.sync.strings()
4346 const currentLanguage = api.settings.sync.get('language')
47+ const exportIdentityButton = api.backup.html.exportIdentityButton()
48+ const importIdentityButton = api.backup.html.importIdentityButton()
4449
4550 const editProfile = () => api.history.sync.push({
4651 page: 'userEdit',
4752 feed,
@@ -95,13 +100,21 @@
95100 ]),
96101 h('section -version', [
97102 h('div.left', strings.settingsPage.section.version),
98103 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+ ])
99112 ])
100113 ])
101114 ])
102115
103- function Language (lang) {
116+ function Language(lang) {
104117 const selectLang = () => api.settings.sync.set({ language: lang })
105118 const className = currentLanguage === lang ? '-strong' : ''
106119
107120 return h('Button -language',
@@ -112,9 +125,9 @@
112125 strings.languages[lang]
113126 )
114127 }
115128
116- function Theme (theme) {
129+ function Theme(theme) {
117130 const currentTheme = api.settings.obs.get('ticktack.theme')
118131 const className = computed(currentTheme, t => t === theme ? '-strong' : '')
119132
120133 return h('Button -language',
@@ -125,9 +138,9 @@
125138 strings.themes[theme]
126139 )
127140 }
128141
129- function zoomButton (increment, symbol) {
142+ function zoomButton(increment, symbol) {
130143 const { getCurrentWebContents } = electron.remote
131144 return h('Button -zoom',
132145 {
133146 'ev-click': () => {
@@ -140,9 +153,9 @@
140153 symbol
141154 )
142155 }
143156
144- function webSharingOption (v, label) {
157+ function webSharingOption(v, label) {
145158 let myOption = computed(webSharingMetricsOption, opt => opt === v)
146159
147160 const selectWebSharingOption = () => {
148161 webSharingMetricsOption.set(v)
main.jsView
@@ -29,9 +29,10 @@
2929 router: require('./router'),
3030 styles: require('./styles'),
3131 state: require('./state/obs'),
3232 unread: require('./unread'),
33- channel: require('./channel')
33+ channel: require('./channel'),
34+ backup: require('./backup')
3435 },
3536 {
3637 profile: require('patch-profile'),
3738 drafts: require('patch-drafts'),
backup/html/backup.jsView
@@ -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+}
backup/html/backup.mcssView
@@ -1,0 +1,14 @@
1+Button -backup {
2+ margin-right: 1rem
3+}
4+
5+textarea#encryptionKey {
6+ $fontBasic
7+
8+ padding: 1rem
9+ border-radius: 1rem
10+ $borderSubtle
11+ margin-bottom: .5rem
12+
13+ outline: none
14+}
backup/index.jsView
@@ -1,0 +1,5 @@
1+module.exports = {
2+ html: {
3+ backup: require('./html/backup')
4+ }
5+}

Built with git-ssb-web