Skip to content

Commit

Permalink
Added bundled ssb server.
Browse files Browse the repository at this point in the history
  • Loading branch information
soapdog committed Jan 5, 2020
1 parent 7991fe5 commit d761549
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Version 0.0.5

- Will attempt to launch bundled `ssb-server` if it can't connect to one.

# Version 0.0.4

- Refactored the source code to Mithril.
Expand Down
9 changes: 8 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
const m = require("mithril");
const electron = require("electron")
const Navigation = require("./navigation");
const Welcome = require("./welcome");
const Backup = require("./backup");
const root = document.getElementById("root");


electron.ipcRenderer.on('server-started', (event, config) => {
console.log("server started")
m.route.set("/backup/connect")
})

m.route(root, "/welcome", {
"/welcome": {
render: (vnode) => {
Expand All @@ -16,4 +22,5 @@ m.route(root, "/welcome", {
return m(Navigation, m(Backup, vnode.attrs))
}
}
});
});

7 changes: 3 additions & 4 deletions background-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ const Path = require('path')
const electron = require('electron')
const Client = require('ssb-client')
const ssbKeys = require('ssb-keys')
const Config = require("ssb-config/inject")
const appName = process.env.ssb_appname || "ssb"
const config = Config(appName)

// pull config options out of depject
let config = require('./config')
console.log("config", config)

config = config.create().config.sync.load()

const createSbot = require('ssb-server')
.use(require('ssb-local'))
Expand Down
22 changes: 21 additions & 1 deletion backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

// dependencies needed...
const m = require("mithril")
const electron = require('electron')
const marked = require("marked")
const path = require("path")
const fs = require("fs")
Expand All @@ -33,6 +34,7 @@ const secretFile = path.join(config.path, "secret")
// script local variables used by multiple components...
let backup = {}
let sbot = false
let attemptedToStartBuiltinServer = false

/**
* MessageWithIndeterminateProgress
Expand Down Expand Up @@ -176,7 +178,11 @@ const connect = {
ssbClient(config, (err, server) => {
if (err) {
console.error("err", err)
m.route.set("/backup/servernotrunning")
if (attemptedToStartBuiltinServer) {
m.route.set("/backup/servernotrunning")
} else {
m.route.set("/backup/startserver")
}
} else {
sbot = server
backup.feed = sbot.id
Expand All @@ -191,6 +197,19 @@ const connect = {
}
}

const startserver = {
oncreate: function (vnode) {
attemptedToStartBuiltinServer = true
electron.ipcRenderer.send('start-server', config)

},
view: function (vnode) {
return m(MessageWithIndeterminateProgress, {
content: `Attempting to start SSB server...`
})
}
}

/**
* getdatafromserver - phase 4 of backup
*
Expand Down Expand Up @@ -412,6 +431,7 @@ const BackupView = {
start,
checkssbfolder,
connect,
startserver,
getdatafromserver,
summary,
saved,
Expand Down
24 changes: 20 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const debug = require('electron-debug')
const contextMenu = require('electron-context-menu')
const menu = require('./menu')
const appName = process.env.SSB_APPNAME || 'ssb'
const developmentMode = process.env.DEVELOPMENT_MODE == "true" || false
const os = require('os')
const fs = require('fs')
const CONFIG_FOLDER = path.join(os.homedir(), `.${appName}`)
Expand Down Expand Up @@ -37,15 +38,22 @@ let windows = {};

const createBackgroundWindow = async () => {
if (!windows.background) {
console.log("creating background window...")
const bgWin = new BrowserWindow({
title: "SSB Backup tool server",
show: false,
width: 150,
height: 150,
show: developmentMode,
width: 500,
height: 500,
webPreferences: { nodeIntegration: true }

});

bgWin.on('closed', () => {
// Dereference the window
// For multiple windows store them in an array
windows.background = undefined
});

await bgWin.loadFile(path.join(__dirname, 'background.html'))

return bgWin
Expand All @@ -63,7 +71,9 @@ const createMainWindow = async () => {

win.on('ready-to-show', () => {
win.show()
// win.closeDevTools()
if (!developmentMode) {
win.closeDevTools()
}
});

win.on('closed', () => {
Expand Down Expand Up @@ -111,5 +121,11 @@ app.on('window-all-closed', () => {

ipcMain.once('server-started', async (ev, config) => {
console.log("server started!")
windows.main.webContents.send('server-started', config)
})

ipcMain.once('start-server', async () => {
console.log("attempting to start server...")
windows.background = await createBackgroundWindow()
})
})();
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ssb-backup-tool",
"productName": "SSB Backup Tool",
"version": "0.0.4",
"version": "0.0.5",
"description": "A backup tool for the scuttleverse",
"license": "MIT",
"repository": "ssbc/ssb-backup-tool",
Expand All @@ -14,6 +14,7 @@
"scripts": {
"postinstall": "electron-builder install-app-deps",
"start": "cross-env ELECTRON_DISABLE_SECURITY_WARNINGS=true electron .",
"dev": "cross-env ELECTRON_DISABLE_SECURITY_WARNINGS=true DEVELOPMENT_MODE=true electron .",
"pack": "electron-builder --dir",
"dist": "electron-builder --macos --windows --linux ",
"release": "env-cmd electron-builder --windows --macos --linux --publish always",
Expand Down Expand Up @@ -71,8 +72,14 @@
"github"
],
"target": [
"nsis",
"zip"
{
"target": "nsis",
"arch": ["x64", "ia32"]
},
{
"target": "zip",
"arch": ["x64", "ia32", "arm64"]
}
]
},
"mac": {
Expand Down
9 changes: 9 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ $ npm install
$ npm start
```

### Run in development mode

```
$ npm install
$ npm run dev
```

In _development mode_ the development tools are visible and both the main window and the background window responsible for the bundled ssb-server are visible.

### Publish

```
Expand Down

0 comments on commit d761549

Please sign in to comment.