git ssb

2+

mixmix / ticktack



Commit 3fa3e23c4b756580c6cf49253941a9e7d55b9023

implemented sequence export

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

Files changed

backup/async/exportIdentity.jschanged
backup/html/backup.jschanged
index.jschanged
ftu/app.jsadded
ftu/app.mcssadded
ftu/index.jsadded
backup/async/exportIdentity.jsView
@@ -1,5 +1,6 @@
11 const nest = require('depnest')
2+const { onceTrue } = require('mutant')
23 const path = require('path')
34 const fs = require('fs')
45 const os = require('os')
56 const homedir = os.homedir()
@@ -9,8 +10,14 @@
910
1011
1112 exports.gives = nest('backup.async.exportIdentity')
1213
14+
15+exports.needs = nest({
16+ 'keys.sync.id': 'first',
17+ 'sbot.obs.connection': 'first'
18+})
19+
1320 exports.create = function (api) {
1421 return nest('backup.async.exportIdentity', (password, filename, cb) => {
1522 if ("undefined" == typeof filename) {
1623 cb()
@@ -20,19 +27,28 @@
2027
2128 let peers = JSON.parse(fs.readFileSync(peersFile))
2229 let secret = fs.readFileSync(secretFile, "utf8")
2330
31+ onceTrue(api.sbot.obs.connection, sbot => {
2432
25- let data = {
26- exportDate: new Date(),
27- latestSequence: "",
28- peers: peers,
29- secret: secret
30- }
33+ let feedId = api.keys.sync.id()
3134
32- fs.writeFileSync(filename, JSON.stringify(data), "utf8")
35+ sbot.latestSequence(feedId, (err, sequence) => {
3336
34- cb()
37+ if (err) throw err
38+
39+ let data = {
40+ exportDate: new Date(),
41+ latestSequence: sequence,
42+ peers: peers,
43+ secret: secret
44+ }
45+
46+ fs.writeFileSync(filename, JSON.stringify(data), "utf8")
47+
48+ cb()
49+ })
50+ })
3551 }
3652 return true
3753 })
3854 }
backup/html/backup.jsView
@@ -18,9 +18,8 @@
1818
1919 exports.create = (api) => {
2020 return nest('backup.html', { exportIdentityButton, importIdentityButton })
2121
22- let feed = api.keys.sync.id()
2322 let strings = api.translations.sync.strings()
2423
2524 function exportIdentityButton() {
2625 let isOpen = Value(false)
index.jsView
@@ -3,8 +3,15 @@
33 var electron = require('electron')
44 var Menu = electron.Menu
55 var Path = require('path')
66
7+// FTU needs
8+const fs = require('fs')
9+const Config = require('ssb-config/inject')
10+const appName = process.env.ssb_appname || 'ssb'
11+const config = Config(appName)
12+const isInstalled = fs.existsSync(Path.join(config.path, 'secret'))
13+
714 var windows = {}
815 var quitting = false
916
1017 electron.app.on('ready', () => {
@@ -32,10 +39,22 @@
3239 }
3340
3441 Menu.setApplicationMenu(Menu.buildFromTemplate(menu))
3542
36- startBackgroundProcess()
43+ // TODO: FTU must happen before this part.
44+ if (!isInstalled) {
45+ console.log('Ticktack or SSB not installed, run FTU')
46+ openFTUWindow()
47+ } else {
48+ startBackgroundProcess()
49+ }
3750
51+ // FTU told app to create new identity, so proceed as normal
52+ electron.ipcMain.once('create-new-identity', function (ev) {
53+ console.log('create new identity')
54+ startBackgroundProcess()
55+ })
56+
3857 // wait until server has started before opening main window
3958 electron.ipcMain.once('server-started', function (ev, config) {
4059 openMainWindow()
4160 })
@@ -46,14 +65,14 @@
4665
4766 // allow inspecting of background process
4867 electron.ipcMain.on('open-background-devtools', function (ev, config) {
4968 if (windows.background) {
50- windows.background.webContents.openDevTools({detach: true})
69+ windows.background.webContents.openDevTools({ detach: true })
5170 }
5271 })
5372 })
5473
55-function startBackgroundProcess () {
74+function startBackgroundProcess() {
5675 if (!windows.background) {
5776 windows.background = openWindow(Path.join(__dirname, 'background-process.js'), {
5877 connect: false,
5978 center: true,
@@ -71,9 +90,9 @@
7190 })
7291 }
7392 }
7493
75-function openMainWindow () {
94+function openMainWindow() {
7695 if (!windows.main) {
7796 var windowState = WindowState({
7897 defaultWidth: 1024,
7998 defaultHeight: 768
@@ -106,9 +125,44 @@
106125 })
107126 }
108127 }
109128
110-function openWindow (path, opts) {
129+function openFTUWindow() {
130+ if (!windows.main) {
131+ var windowState = WindowState({
132+ defaultWidth: 1024,
133+ defaultHeight: 768
134+ })
135+ windows.main = openWindow(Path.join(__dirname, 'ftu', 'index.js'), {
136+ minWidth: 800,
137+ x: windowState.x,
138+ y: windowState.y,
139+ width: windowState.width,
140+ height: windowState.height,
141+ autoHideMenuBar: true,
142+ title: 'Ticktack',
143+ frame: false,
144+ titleBarStyle: 'hidden',
145+ show: true,
146+ backgroundColor: '#EEE',
147+ icon: './assets/icon.png'
148+ })
149+ windowState.manage(windows.main)
150+ windows.main.setSheetOffset(40)
151+ windows.main.on('close', function (e) {
152+ if (!quitting && process.platform === 'darwin') {
153+ e.preventDefault()
154+ windows.main.hide()
155+ }
156+ })
157+ windows.main.on('closed', function () {
158+ windows.main = null
159+ if (process.platform !== 'darwin') electron.app.quit()
160+ })
161+ }
162+}
163+
164+function openWindow(path, opts) {
111165 var window = new electron.BrowserWindow(opts)
112166 window.webContents.on('dom-ready', function () {
113167 window.webContents.executeJavaScript(`
114168 var electron = require('electron')
ftu/app.jsView
@@ -1,0 +1,81 @@
1+const { h, Value } = require('mutant')
2+const nest = require('depnest')
3+const path = require('path')
4+const { remote } = require('electron')
5+const insertCss = require('insert-css')
6+const values = require('lodash/values')
7+const electron = require('electron')
8+
9+
10+exports.gives = nest('ftu.app')
11+
12+exports.needs = nest({
13+ 'styles.css': 'reduce',
14+ 'translations.sync.strings': 'first'
15+})
16+
17+exports.create = (api) => {
18+ return nest({
19+ 'ftu.app': function app() {
20+
21+ const css = values(api.styles.css()).join('\n')
22+ insertCss(css)
23+
24+ var app = h('App', [
25+ h('Header', [
26+ windowControls()
27+ ]),
28+ h('Page -ftu', [
29+ 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+ ])
36+ ])
37+ ])
38+ ])
39+
40+ return app
41+ }
42+
43+ })
44+
45+}
46+
47+function actionCreateNewOne() {
48+ electron.ipcRenderer.send('create-new-identity')
49+}
50+
51+function windowControls() {
52+ if (process.platform === 'darwin') return
53+
54+ const window = remote.getCurrentWindow()
55+ const minimize = () => window.minimize()
56+ const maximize = () => {
57+ if (!window.isMaximized()) window.maximize()
58+ else window.unmaximize()
59+ }
60+ const close = () => window.close()
61+
62+ return h('div.window-controls', [
63+ h('img.min', {
64+ src: assetPath('minimize.png'),
65+ 'ev-click': minimize
66+ }),
67+ h('img.max', {
68+ src: assetPath('maximize.png'),
69+ 'ev-click': maximize
70+ }),
71+ h('img.close', {
72+ src: assetPath('close.png'),
73+ 'ev-click': close
74+ })
75+ ])
76+}
77+
78+
79+function assetPath(name) {
80+ return path.join(__dirname, '../assets', name)
81+}
ftu/app.mcssView
@@ -1,0 +1,56 @@
1+App {
2+ overflow: hidden
3+ position: fixed
4+ top: 0
5+ bottom: 0
6+ right: 0
7+ left: 0
8+}
9+
10+Page -ftu {
11+ margin-top: 0
12+ height: calc(100%)
13+
14+ div.content {
15+ section {
16+ display: flex
17+ align-content: center
18+
19+ div {
20+ padding: .5rem
21+
22+ display: flex
23+ align-items: center
24+ }
25+
26+ div.left {
27+ flex-basis: 40%
28+ justify-content: flex-end
29+ }
30+ div.right {
31+ flex-basis: 60%
32+ justify-content: flex-start
33+ }
34+ }
35+ }
36+}
37+
38+Header {
39+ div.window-controls {
40+ position: fixed
41+ right: 0
42+ z-index: 100
43+
44+ display: flex
45+
46+ img {
47+ padding: .5rem
48+ cursor: pointer
49+ :hover {
50+ filter: drop-shadow(rgba(255, 255, 255, .5) 0 0 2px)
51+ }
52+ }
53+ }
54+}
55+
56+
ftu/index.jsView
@@ -1,0 +1,29 @@
1+const combine = require('depject')
2+const entry = require('depject/entry')
3+const nest = require('depnest')
4+
5+
6+// polyfills
7+require('setimmediate')
8+
9+// add inspect right click menu
10+require('../context-menu')
11+
12+// from more specialized to more general
13+const sockets = combine(
14+ // need some modules first
15+ {
16+ styles: require('../styles'),
17+ settings: require('patch-settings'),
18+ translations: require('../translations/sync')
19+ },
20+ {
21+ app: require('./app')
22+ }
23+)
24+
25+const api = entry(sockets, nest({
26+ 'ftu.app': 'first'
27+}))
28+
29+document.body.appendChild(api.ftu.app())

Built with git-ssb-web