git ssb

2+

mixmix / ticktack



Commit 992639a1213cadc35e523df588f878128718bc5b

feature(backup): work in progress

andre alves garzia committed on 5/7/2018, 1:33:26 PM
Parent: 1b46fe809a87f906b19ab7dad059971d13730b4f

Files changed

app/index.jschanged
app/page/settings.jschanged
main.jschanged
backup/html/backup.jsadded
backup/html/backup.mcssadded
backup/index.jsadded
app/index.jsView
@@ -20,9 +20,9 @@
2020 sideNav: {
2121 addressBook: require('./html/sideNav/sideNavAddressBook'),
2222 discovery: require('./html/sideNav/sideNavDiscovery')
2323 },
24- warning: require('./html/warning'),
24+ warning: require('./html/warning')
2525 },
2626 obs: {
2727 pluginsOk: require('./obs/pluginsOk'),
2828 },
app/page/settings.jsView
@@ -16,9 +16,12 @@
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
@@ -30,23 +33,25 @@
3033
3134 exports.create = (api) => {
3235 return nest('app.page.settings', settings)
3336
34- function settings (location) {
37+ function settings(location) {
3538 // RESET the app when the settings are changed
3639 api.settings.obs.get('language')(() => {
3740 console.log('language changed, resetting view')
3841
3942 // clear history back to start page
4043 api.history.obs.store().set([
4144 { page: 'blogIndex' }
4245 ])
43- api.history.sync.push({page: 'settings'})
46+ api.history.sync.push({ page: 'settings' })
4447 })
4548
4649 const feed = api.keys.sync.id()
4750 const strings = api.translations.sync.strings()
4851 const currentLanguage = api.settings.sync.get('language')
52+ const exportIdentityButton = api.backup.html.exportIdentityButton()
53+ const importIdentityButton = api.backup.html.importIdentityButton()
4954
5055 const editProfile = () => api.history.sync.push({
5156 page: 'userEdit',
5257 feed,
@@ -83,18 +88,26 @@
8388 h('div.right', LANGUAGES.map(Language))
8489 ]),
8590 h('section -zoom', [
8691 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, '+')])
8893 ]),
8994 h('section -version', [
9095 h('div.left', strings.settingsPage.section.version),
9196 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+ ])
92105 ])
93106 ])
94107 ])
95108
96- function Language (lang) {
109+ function Language(lang) {
97110 const selectLang = () => api.settings.sync.set({ language: lang })
98111 const className = currentLanguage === lang ? '-strong' : ''
99112
100113 return h('Button -language',
@@ -105,9 +118,9 @@
105118 strings.languages[lang]
106119 )
107120 }
108121
109- function zoomButton (increment, symbol) {
122+ function zoomButton(increment, symbol) {
110123 const { getCurrentWebContents } = electron.remote
111124 return h('Button -zoom',
112125 {
113126 'ev-click': () => {
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