git ssb

2+

mixmix / ticktack



Commit b42fccbaa67e2711ebbeb26092b463df381ba13a

working export identity and create new identity in ftu #122

andre alves garzia committed on 5/21/2018, 12:03:22 AM
Parent: 3fa3e23c4b756580c6cf49253941a9e7d55b9023

Files changed

backup/html/backup.jschanged
ftu/app.jschanged
index.jschanged
translations/en.jschanged
manifest.jsonadded
backup/html/backup.jsView
@@ -18,19 +18,19 @@
1818
1919 exports.create = (api) => {
2020 return nest('backup.html', { exportIdentityButton, importIdentityButton })
2121
22- let strings = api.translations.sync.strings()
22+ function exportIdentityButton() {
23+ const strings = api.translations.sync.strings()
2324
24- function exportIdentityButton() {
2525 let isOpen = Value(false)
2626 let encryptionKeyRaw = Value('')
2727
2828 let encryptionKeyInput = h('textarea#encryptionKey', {
2929 style: {
3030 width: '90%'
3131 },
32- placeholder: 'Please enter password to protect export file',
32+ placeholder: strings.backup.export.passwordPlaceholder,
3333 value: encryptionKeyRaw,
3434 'ev-input': () => encryptionKeyRaw.set(encryptionKeyInput.value),
3535 })
3636
@@ -40,44 +40,46 @@
4040 }
4141 },
4242 [
4343 h('div.message', [
44- h('h1', 'Export Identity'),
45- h('p', 'Please backup your private key file very carefully.'),
46- h('p', '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')
44+ h('h1', strings.backup.export.header),
45+ h('p', strings.backup.export.message[0]),
46+ h('p', strings.backup.export.message[1])
4747 ]),
4848 h('div.form', [
4949 encryptionKeyInput
5050 ]),
5151 h('div.actions', [
52- h('Button', { 'ev-click': () => isOpen.set(false) }, 'Cancel'),
52+ h('Button', { 'ev-click': () => isOpen.set(false) }, strings.backup.export.cancelAction),
5353 h('Button -primary', {
5454 'ev-click': () => {
5555 dialog.showSaveDialog(
5656 {
57- title: 'Export Identity',
58- butttonLabel: 'Export Identity',
57+ title: strings.backup.export.dialog.title,
58+ butttonLabel: strings.backup.export.dialog.label,
5959 defaultPath: 'ticktack-identity.backup',
6060 },
6161 (filename) => api.backup.async.exportIdentity(
6262 resolve(encryptionKeyRaw), filename, () => isOpen.set(false)
6363 )
6464 )
6565 }
66- }, 'Export Identity')
66+ }, strings.backup.export.exportAction)
6767 ])
6868 ])
6969
7070 let lb = api.app.html.lightbox(exportDialog, isOpen)
7171
7272 return h('div.backupKeys', [
73- h('Button -backup', { 'ev-click': () => isOpen.set(true) }, 'Export Keys'),
73+ h('Button -backup', { 'ev-click': () => isOpen.set(true) }, strings.backup.export.exportAction),
7474 lb
7575 ])
7676 }
7777
7878 function importIdentityButton() {
79+ const strings = api.translations.sync.strings()
80+
7981 return h('div.backupKeys', [
80- h('Button -backup', 'Import Keys')
82+ h('Button -backup', strings.backup.import.importAction)
8183 ])
8284 }
8385 }
ftu/app.jsView
@@ -1,7 +1,8 @@
1-const { h, Value } = require('mutant')
1+const { h, Value, when } = require('mutant')
22 const nest = require('depnest')
33 const path = require('path')
4+const fs = require('fs')
45 const { remote } = require('electron')
56 const insertCss = require('insert-css')
67 const values = require('lodash/values')
78 const electron = require('electron')
@@ -17,23 +18,31 @@
1718 exports.create = (api) => {
1819 return nest({
1920 'ftu.app': function app() {
2021
22+ const strings = api.translations.sync.strings()
23+
2124 const css = values(api.styles.css()).join('\n')
2225 insertCss(css)
2326
27+ var isBusy = Value(false)
28+
29+ var actionButtons = h('section', [
30+ h('div.left', h('Button', strings.backup.ftu.importAction)),
31+ h('div.right', h('Button', { 'ev-click': () => actionCreateNewOne(isBusy) }, strings.backup.ftu.createAction))
32+ ])
33+
34+ var busyMessage = h('p', strings.backup.ftu.busyMessage)
35+
2436 var app = h('App', [
2537 h('Header', [
2638 windowControls()
2739 ]),
2840 h('Page -ftu', [
2941 h('div.content', [
30- h('h1', 'Welcome to Ticktack'),
31- h('p', 'Do you want to create a new identity or import one?'),
32- h('section', [
33- h('div.left', h('Button', 'Import identity')),
34- h('div.right', h('Button', { 'ev-click': () => actionCreateNewOne() }, 'Create a new one'))
35- ])
42+ h('h1', strings.backup.ftu.welcomeHeader),
43+ h('p', strings.backup.ftu.welcomeMessage),
44+ when(isBusy, busyMessage, actionButtons)
3645 ])
3746 ])
3847 ])
3948
@@ -43,9 +52,15 @@
4352 })
4453
4554 }
4655
47-function actionCreateNewOne() {
56+function actionCreateNewOne(isBusy) {
57+ isBusy.set(true)
58+ const config = require('../config').create().config.sync.load()
59+ const manifest = JSON.parse(fs.readFileSync(path.join(__dirname, "../manifest.json")))
60+ fs.writeFileSync(path.join(config.path, 'manifest.json'), JSON.stringify(manifest))
61+
62+
4863 electron.ipcRenderer.send('create-new-identity')
4964 }
5065
5166 function windowControls() {
index.jsView
@@ -55,8 +55,9 @@
5555 })
5656
5757 // wait until server has started before opening main window
5858 electron.ipcMain.once('server-started', function (ev, config) {
59+ console.log("> Opening main window")
5960 openMainWindow()
6061 })
6162
6263 electron.app.on('before-quit', function () {
@@ -122,18 +123,22 @@
122123 windows.main.on('closed', function () {
123124 windows.main = null
124125 if (process.platform !== 'darwin') electron.app.quit()
125126 })
127+
128+ if (windows.ftu) {
129+ windows.ftu.hide()
130+ }
126131 }
127132 }
128133
129134 function openFTUWindow() {
130- if (!windows.main) {
135+ if (!windows.ftu) {
131136 var windowState = WindowState({
132137 defaultWidth: 1024,
133138 defaultHeight: 768
134139 })
135- windows.main = openWindow(Path.join(__dirname, 'ftu', 'index.js'), {
140+ windows.ftu = openWindow(Path.join(__dirname, 'ftu', 'index.js'), {
136141 minWidth: 800,
137142 x: windowState.x,
138143 y: windowState.y,
139144 width: windowState.width,
@@ -145,18 +150,18 @@
145150 show: true,
146151 backgroundColor: '#EEE',
147152 icon: './assets/icon.png'
148153 })
149- windowState.manage(windows.main)
150- windows.main.setSheetOffset(40)
151- windows.main.on('close', function (e) {
154+ windowState.manage(windows.ftu)
155+ windows.ftu.setSheetOffset(40)
156+ windows.ftu.on('close', function (e) {
152157 if (!quitting && process.platform === 'darwin') {
153158 e.preventDefault()
154- windows.main.hide()
159+ windows.ftu.hide()
155160 }
156161 })
157- windows.main.on('closed', function () {
158- windows.main = null
162+ windows.ftu.on('closed', function () {
163+ windows.ftu = null
159164 if (process.platform !== 'darwin') electron.app.quit()
160165 })
161166 }
162167 }
translations/en.jsView
@@ -188,8 +188,34 @@
188188 prevMonth: 'Prev 30 days',
189189 nextMonth: 'Next 30 days',
190190 thirtyDays: '30 days'
191191 },
192+ backup: {
193+ ftu: {
194+ importAction: 'Import identity',
195+ createAction: 'Create new identity',
196+ busyMessage: 'Processing...',
197+ welcomeHeader: 'Welcome to Ticktack',
198+ welcomeMessage: 'Do you want to create a new identity or import one?'
199+ },
200+ export: {
201+ header: 'Export identity',
202+ message: [
203+ 'Please backup your private key file very carefully.',
204+ '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'
205+ ],
206+ passwordPlaceholder: 'Please enter password to protect export file',
207+ cancelAction: 'Cancel',
208+ exportAction: 'Export Identity',
209+ dialog: {
210+ label: 'Export Identity',
211+ title: 'Export Identity'
212+ }
213+ },
214+ import: {
215+ importAction: 'Import Identity'
216+ }
217+ },
192218 languages: {
193219 en: 'English',
194220 zh: '中文'
195221 }
manifest.jsonView
@@ -1,0 +1,1 @@
1+{"auth":"async","address":"sync","manifest":"sync","get":"async","createFeedStream":"source","createLogStream":"source","messagesByType":"source","createHistoryStream":"source","createUserStream":"source","links":"source","relatedMessages":"async","add":"async","publish":"async","getAddress":"sync","getLatest":"async","latest":"source","latestSequence":"async","whoami":"sync","progress":"sync","status":"sync","getVectorClock":"async","seq":"async","usage":"sync","clock":"async","gossip":{"peers":"sync","add":"sync","remove":"sync","ping":"duplex","connect":"async","changes":"source","reconnect":"sync","enable":"sync","disable":"sync"},"replicate":{"changes":"source","upto":"source","request":"sync"},"friends":{"get":"async","createFriendStream":"source","stream":"source","hops":"async"},"blobs":{"get":"source","getSlice":"source","add":"sink","rm":"async","ls":"source","has":"async","size":"async","meta":"async","want":"async","push":"async","changes":"source","createWants":"source"},"backlinks":{"read":"source"},"private":{"publish":"async","unbox":"sync","read":"source"},"invite":{"create":"async","accept":"async","use":"async"},"query":{"read":"source","dump":"source"},"about":{"stream":"source","get":"async"},"ws":{"getAddress":"sync"},"channel":{"get":"async","stream":"source","subscriptions":"async","reduce":"sync"},"blogStats":{"get":"async","read":"source","readBlogs":"source","getBlogs":"async","readComments":"source","readLikes":"source"}}

Built with git-ssb-web