Commit b42fccbaa67e2711ebbeb26092b463df381ba13a
working export identity and create new identity in ftu #122
andre alves garzia committed on 5/21/2018, 12:03:22 AMParent: 3fa3e23c4b756580c6cf49253941a9e7d55b9023
Files changed
backup/html/backup.js | changed |
ftu/app.js | changed |
index.js | changed |
translations/en.js | changed |
manifest.json | added |
backup/html/backup.js | ||
---|---|---|
@@ -18,19 +18,19 @@ | ||
18 | 18 | |
19 | 19 | exports.create = (api) => { |
20 | 20 | return nest('backup.html', { exportIdentityButton, importIdentityButton }) |
21 | 21 | |
22 | - let strings = api.translations.sync.strings() | |
22 | + function exportIdentityButton() { | |
23 | + const strings = api.translations.sync.strings() | |
23 | 24 | |
24 | - function exportIdentityButton() { | |
25 | 25 | let isOpen = Value(false) |
26 | 26 | let encryptionKeyRaw = Value('') |
27 | 27 | |
28 | 28 | let encryptionKeyInput = h('textarea#encryptionKey', { |
29 | 29 | style: { |
30 | 30 | width: '90%' |
31 | 31 | }, |
32 | - placeholder: 'Please enter password to protect export file', | |
32 | + placeholder: strings.backup.export.passwordPlaceholder, | |
33 | 33 | value: encryptionKeyRaw, |
34 | 34 | 'ev-input': () => encryptionKeyRaw.set(encryptionKeyInput.value), |
35 | 35 | }) |
36 | 36 | |
@@ -40,44 +40,46 @@ | ||
40 | 40 | } |
41 | 41 | }, |
42 | 42 | [ |
43 | 43 | 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]) | |
47 | 47 | ]), |
48 | 48 | h('div.form', [ |
49 | 49 | encryptionKeyInput |
50 | 50 | ]), |
51 | 51 | h('div.actions', [ |
52 | - h('Button', { 'ev-click': () => isOpen.set(false) }, 'Cancel'), | |
52 | + h('Button', { 'ev-click': () => isOpen.set(false) }, strings.backup.export.cancelAction), | |
53 | 53 | h('Button -primary', { |
54 | 54 | 'ev-click': () => { |
55 | 55 | dialog.showSaveDialog( |
56 | 56 | { |
57 | - title: 'Export Identity', | |
58 | - butttonLabel: 'Export Identity', | |
57 | + title: strings.backup.export.dialog.title, | |
58 | + butttonLabel: strings.backup.export.dialog.label, | |
59 | 59 | defaultPath: 'ticktack-identity.backup', |
60 | 60 | }, |
61 | 61 | (filename) => api.backup.async.exportIdentity( |
62 | 62 | resolve(encryptionKeyRaw), filename, () => isOpen.set(false) |
63 | 63 | ) |
64 | 64 | ) |
65 | 65 | } |
66 | - }, 'Export Identity') | |
66 | + }, strings.backup.export.exportAction) | |
67 | 67 | ]) |
68 | 68 | ]) |
69 | 69 | |
70 | 70 | let lb = api.app.html.lightbox(exportDialog, isOpen) |
71 | 71 | |
72 | 72 | 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), | |
74 | 74 | lb |
75 | 75 | ]) |
76 | 76 | } |
77 | 77 | |
78 | 78 | function importIdentityButton() { |
79 | + const strings = api.translations.sync.strings() | |
80 | + | |
79 | 81 | return h('div.backupKeys', [ |
80 | - h('Button -backup', 'Import Keys') | |
82 | + h('Button -backup', strings.backup.import.importAction) | |
81 | 83 | ]) |
82 | 84 | } |
83 | 85 | } |
ftu/app.js | ||
---|---|---|
@@ -1,7 +1,8 @@ | ||
1 | -const { h, Value } = require('mutant') | |
1 | +const { h, Value, when } = require('mutant') | |
2 | 2 | const nest = require('depnest') |
3 | 3 | const path = require('path') |
4 | +const fs = require('fs') | |
4 | 5 | const { remote } = require('electron') |
5 | 6 | const insertCss = require('insert-css') |
6 | 7 | const values = require('lodash/values') |
7 | 8 | const electron = require('electron') |
@@ -17,23 +18,31 @@ | ||
17 | 18 | exports.create = (api) => { |
18 | 19 | return nest({ |
19 | 20 | 'ftu.app': function app() { |
20 | 21 | |
22 | + const strings = api.translations.sync.strings() | |
23 | + | |
21 | 24 | const css = values(api.styles.css()).join('\n') |
22 | 25 | insertCss(css) |
23 | 26 | |
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 | + | |
24 | 36 | var app = h('App', [ |
25 | 37 | h('Header', [ |
26 | 38 | windowControls() |
27 | 39 | ]), |
28 | 40 | h('Page -ftu', [ |
29 | 41 | 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) | |
36 | 45 | ]) |
37 | 46 | ]) |
38 | 47 | ]) |
39 | 48 | |
@@ -43,9 +52,15 @@ | ||
43 | 52 | }) |
44 | 53 | |
45 | 54 | } |
46 | 55 | |
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 | + | |
48 | 63 | electron.ipcRenderer.send('create-new-identity') |
49 | 64 | } |
50 | 65 | |
51 | 66 | function windowControls() { |
index.js | ||
---|---|---|
@@ -55,8 +55,9 @@ | ||
55 | 55 | }) |
56 | 56 | |
57 | 57 | // wait until server has started before opening main window |
58 | 58 | electron.ipcMain.once('server-started', function (ev, config) { |
59 | + console.log("> Opening main window") | |
59 | 60 | openMainWindow() |
60 | 61 | }) |
61 | 62 | |
62 | 63 | electron.app.on('before-quit', function () { |
@@ -122,18 +123,22 @@ | ||
122 | 123 | windows.main.on('closed', function () { |
123 | 124 | windows.main = null |
124 | 125 | if (process.platform !== 'darwin') electron.app.quit() |
125 | 126 | }) |
127 | + | |
128 | + if (windows.ftu) { | |
129 | + windows.ftu.hide() | |
130 | + } | |
126 | 131 | } |
127 | 132 | } |
128 | 133 | |
129 | 134 | function openFTUWindow() { |
130 | - if (!windows.main) { | |
135 | + if (!windows.ftu) { | |
131 | 136 | var windowState = WindowState({ |
132 | 137 | defaultWidth: 1024, |
133 | 138 | defaultHeight: 768 |
134 | 139 | }) |
135 | - windows.main = openWindow(Path.join(__dirname, 'ftu', 'index.js'), { | |
140 | + windows.ftu = openWindow(Path.join(__dirname, 'ftu', 'index.js'), { | |
136 | 141 | minWidth: 800, |
137 | 142 | x: windowState.x, |
138 | 143 | y: windowState.y, |
139 | 144 | width: windowState.width, |
@@ -145,18 +150,18 @@ | ||
145 | 150 | show: true, |
146 | 151 | backgroundColor: '#EEE', |
147 | 152 | icon: './assets/icon.png' |
148 | 153 | }) |
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) { | |
152 | 157 | if (!quitting && process.platform === 'darwin') { |
153 | 158 | e.preventDefault() |
154 | - windows.main.hide() | |
159 | + windows.ftu.hide() | |
155 | 160 | } |
156 | 161 | }) |
157 | - windows.main.on('closed', function () { | |
158 | - windows.main = null | |
162 | + windows.ftu.on('closed', function () { | |
163 | + windows.ftu = null | |
159 | 164 | if (process.platform !== 'darwin') electron.app.quit() |
160 | 165 | }) |
161 | 166 | } |
162 | 167 | } |
translations/en.js | ||
---|---|---|
@@ -188,8 +188,34 @@ | ||
188 | 188 | prevMonth: 'Prev 30 days', |
189 | 189 | nextMonth: 'Next 30 days', |
190 | 190 | thirtyDays: '30 days' |
191 | 191 | }, |
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 | + }, | |
192 | 218 | languages: { |
193 | 219 | en: 'English', |
194 | 220 | zh: '中文' |
195 | 221 | } |
manifest.json | ||
---|---|---|
@@ -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