-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial work on standalone sbot and custom ports / data directory
- Loading branch information
Showing
8 changed files
with
5,033 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head></head> | ||
<body> | ||
<script> | ||
// redirect console to main process | ||
var electron = require('electron') | ||
var localLog = console.log | ||
var localError = console.error | ||
var remoteLog = electron.remote.getGlobal('console').log | ||
var remoteError = electron.remote.getGlobal('console').error | ||
|
||
console.log = function (...args) { | ||
localLog.apply(console, args) | ||
remoteLog(...args) | ||
} | ||
|
||
console.error = function (...args) { | ||
localError.apply(console, args) | ||
remoteError(...args) | ||
} | ||
|
||
process.exit = electron.remote.app.quit | ||
// redirect errors to stderr | ||
window.addEventListener('error', function (e) { | ||
e.preventDefault() | ||
console.error(e.error.stack || 'Uncaught ' + e.error) | ||
}) | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
var fs = require('fs') | ||
var Path = require('path') | ||
var electron = require('electron') | ||
|
||
var createSbot = require('scuttlebot') | ||
.use(require('scuttlebot/plugins/master')) | ||
.use(require('scuttlebot/plugins/gossip')) | ||
.use(require('scuttlebot/plugins/replicate')) | ||
.use(require('ssb-friends')) | ||
.use(require('ssb-blobs')) | ||
.use(require('ssb-backlinks')) | ||
.use(require('ssb-private')) | ||
.use(require('scuttlebot/plugins/invite')) | ||
.use(require('scuttlebot/plugins/local')) | ||
.use(require('scuttlebot/plugins/logging')) | ||
.use(require('ssb-query')) | ||
.use(require('ssb-about')) | ||
.use(require('ssb-contacts')) | ||
// .use(require('ssb-ebt')) | ||
.use(require('ssb-ws')) | ||
|
||
// pull config options out of depject | ||
var config = require('./config').create().config.sync.load() | ||
|
||
var sbot = createSbot(config) | ||
var manifest = sbot.getManifest() | ||
fs.writeFileSync(Path.join(config.path, 'manifest.json'), JSON.stringify(manifest)) | ||
electron.ipcRenderer.send('server-started') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const Config = require('ssb-config/inject') | ||
const nest = require('depnest') | ||
const ssbKeys = require('ssb-keys') | ||
const Path = require('path') | ||
|
||
const appName = 'ticktack-ssb' | ||
const opts = { | ||
port: 43750, | ||
blobsPort: 43751, | ||
ws: { | ||
port: 43751 | ||
} | ||
} | ||
|
||
exports.gives = nest('config.sync.load') | ||
exports.create = (api) => { | ||
var config | ||
return nest('config.sync.load', () => { | ||
if (!config) { | ||
config = Config(process.env.ssb_appname || appName, opts) | ||
config.keys = ssbKeys.loadOrCreateSync(Path.join(config.path, 'secret')) | ||
|
||
// HACK: fix offline on windows by specifying 127.0.0.1 instead of localhost (default) | ||
config.remote = `net:127.0.0.1:${config.port}~shs:${config.keys.id.slice(1).replace('.ed25519', '')}` | ||
} | ||
return config | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
var defaultMenu = require('electron-default-menu') | ||
var WindowState = require('electron-window-state') | ||
var electron = require('electron') | ||
var Menu = electron.Menu | ||
var Path = require('path') | ||
|
||
var windows = {} | ||
var quitting = false | ||
|
||
electron.app.on('ready', () => { | ||
var menu = defaultMenu(electron.app, electron.shell) | ||
var view = menu.find(x => x.label === 'View') | ||
view.submenu = [ | ||
{ role: 'reload' }, | ||
{ role: 'toggledevtools' }, | ||
{ type: 'separator' }, | ||
{ role: 'resetzoom' }, | ||
{ role: 'zoomin' }, | ||
{ role: 'zoomout' }, | ||
{ type: 'separator' }, | ||
{ role: 'togglefullscreen' } | ||
] | ||
if (process.platform === 'darwin') { | ||
var win = menu.find(x => x.label === 'Window') | ||
win.submenu = [ | ||
{ role: 'minimize' }, | ||
{ role: 'zoom' }, | ||
{ role: 'close', label: 'Close' }, | ||
{ type: 'separator' }, | ||
{ role: 'front' } | ||
] | ||
} | ||
|
||
Menu.setApplicationMenu(Menu.buildFromTemplate(menu)) | ||
|
||
startBackgroundProcess() | ||
|
||
// wait until server has started before opening main window | ||
electron.ipcMain.once('server-started', function (ev, config) { | ||
openMainWindow() | ||
}) | ||
|
||
electron.app.on('before-quit', function () { | ||
quitting = true | ||
}) | ||
|
||
// allow inspecting of background process | ||
electron.ipcMain.on('open-background-devtools', function (ev, config) { | ||
if (windows.background) { | ||
windows.background.webContents.openDevTools({detach: true}) | ||
} | ||
}) | ||
}) | ||
|
||
function startBackgroundProcess () { | ||
if (!windows.background) { | ||
windows.background = openWindow(Path.join(__dirname, 'background-process.js'), { | ||
connect: false, | ||
center: true, | ||
fullscreen: false, | ||
fullscreenable: false, | ||
height: 150, | ||
maximizable: false, | ||
minimizable: false, | ||
resizable: false, | ||
show: false, | ||
skipTaskbar: true, | ||
title: 'ticktack-server', | ||
useContentSize: true, | ||
width: 150 | ||
}) | ||
} | ||
} | ||
|
||
function openMainWindow () { | ||
if (!windows.main) { | ||
var windowState = WindowState({ | ||
defaultWidth: 1024, | ||
defaultHeight: 768 | ||
}) | ||
windows.main = openWindow(Path.join(__dirname, 'main.js'), { | ||
minWidth: 800, | ||
x: windowState.x, | ||
y: windowState.y, | ||
width: windowState.width, | ||
height: windowState.height, | ||
autoHideMenuBar: true, | ||
title: 'Ticktack', | ||
show: true, | ||
backgroundColor: '#EEE', | ||
icon: './assets/icon.png' | ||
}) | ||
windowState.manage(windows.main) | ||
windows.main.setSheetOffset(40) | ||
windows.main.on('close', function (e) { | ||
if (!quitting && process.platform === 'darwin') { | ||
e.preventDefault() | ||
windows.main.hide() | ||
} | ||
}) | ||
windows.main.on('closed', function () { | ||
windows.main = null | ||
if (process.platform !== 'darwin') electron.app.quit() | ||
}) | ||
} | ||
} | ||
|
||
function openWindow (path, opts) { | ||
var window = new electron.BrowserWindow(opts) | ||
window.webContents.on('dom-ready', function () { | ||
window.webContents.executeJavaScript(` | ||
var electron = require('electron') | ||
var h = require('mutant/h') | ||
electron.webFrame.setZoomLevelLimits(1, 1) | ||
var title = ${JSON.stringify(opts.title || 'Ticktack')} | ||
document.documentElement.querySelector('head').appendChild( | ||
h('title', title) | ||
) | ||
require(${JSON.stringify(path)}) | ||
`) | ||
}) | ||
|
||
window.webContents.on('will-navigate', function (e, url) { | ||
e.preventDefault() | ||
electron.shell.openExternal(url) | ||
}) | ||
|
||
window.webContents.on('new-window', function (e, url) { | ||
e.preventDefault() | ||
electron.shell.openExternal(url) | ||
}) | ||
|
||
window.loadURL('file://' + Path.join(__dirname, 'assets', 'base.html')) | ||
return window | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.