Skip to content

Commit

Permalink
fiddling with kierans scuttletron
Browse files Browse the repository at this point in the history
  • Loading branch information
ameba23 committed Jun 3, 2018
1 parent 5a7cb98 commit f747ea3
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 0 deletions.
31 changes: 31 additions & 0 deletions assets/base.html
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 = (...args) => {
localLog.apply(console, args)
remoteLog(...args)
}

console.error = (...args) => {
localError.apply(console, args)
remoteError(...args)
}

process.exit = electron.remote.app.quit
// redirect errors to stderr
window.addEventListener('error', (e) => {
e.preventDefault()
console.error(e.error.stack || 'Uncaught ' + e.error)
})
</script>
</body>
</html>
Binary file added assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

const Config = require('ssb-config/inject')
// const Config = require('ssb-config')
const ssbKeys = require('ssb-keys')
const Path = require('path')

const appName = "ssb" // <<< NOTE THIS IS YOUR DEFAULT IDENTITY

// const port = process.env.PORT || 8808
//
// const opts = {
// port: port
// }
const opts = null

const config = Config(appName, opts)
Object.assign(config, {
appName,
keys: ssbKeys.loadOrCreateSync(Path.join(config.path, 'secret')),

})

// config.remote = `net:127.0.0.1:${config.port}~shs:${config.keys.id.slice(1).replace('.ed25519', '')}`

module.exports = config


56 changes: 56 additions & 0 deletions src/lib/menu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const defaultMenu = require('electron-default-menu')

const {
app,
Menu,
shell
} = require('electron')

module.exports = function () {
var menu = defaultMenu(app, 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' }
]

var win = menu.find(x => x.label === 'Window')
win.submenu = [
{ role: 'minimize' },
{ role: 'zoom' },
{ role: 'close', label: 'Close Window', accelerator: 'CmdOrCtrl+Shift+W' },
{ type: 'separator' },
{
label: 'Close Tab',
accelerator: 'CmdOrCtrl+W',
click() {
windows.main.webContents.send('closeTab')
}
},
{
label: 'Select Next Tab',
accelerator: 'CmdOrCtrl+Shift+]',
click() {
windows.main.webContents.send('nextTab')
}
},
{
label: 'Select Previous Tab',
accelerator: 'CmdOrCtrl+Shift+[',
click() {
windows.main.webContents.send('previousTab')
}
},
{ type: 'separator' },
{ role: 'front' }
]

return Menu.setApplicationMenu(Menu.buildFromTemplate(menu))
}
38 changes: 38 additions & 0 deletions src/lib/window.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const extend = require('xtend')
const { app, BrowserWindow } = require('electron')

const Path = require('path')
const url = require('url')

module.exports = function (path, opts) {
var icon = process.platform !== 'darwin'
? Path.join(__dirname, '..', 'assets', 'icon.png')
: Path.join(__dirname, '..', 'assets', 'icon.icns')

var win = new BrowserWindow(
extend(opts, {
icon: icon
})
)

win.webContents.on('dom-ready', () => {
win.webContents.executeJavaScript(`
var electron = require('electron')
electron.webFrame.setZoomLevelLimits(1, 1)
var title = ${JSON.stringify(opts.title || 'Application')}
var head = document.documentElement.querySelector('head')
var element = document.createElement('title')
element.innerHTML = title
head.appendChild(element)
require(${JSON.stringify(path)})
`)
})

win.loadURL(url.format({
pathname: Path.join(__dirname, '..', '..','assets', 'base.html'),
protocol: 'file:',
slashes: true
}))

return win
}
18 changes: 18 additions & 0 deletions src/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const Server = require('scuttlebot')
const config = require('./config')

const fs = require('fs')
const Path = require('path')

// Install the plugin
Server
.use(require('scuttlebot/plugins/master')) // required
// .use(require('ssb-about'))
.use(require('ssb-private'))
// .use(require('ssb-backlinks')) // not required, just an example

// Start the server
const server = Server(config)

const manifest = server.getManifest()
fs.writeFileSync(Path.join(config.path, 'manifest.json'), JSON.stringify(manifest))

0 comments on commit f747ea3

Please sign in to comment.