sbot/app/index.js

63 lines
2.0 KiB
JavaScript
Raw Normal View History

2015-08-04 11:54:30 +11:00
var app = require('app')
2015-06-25 02:41:17 +11:00
var Menu = require('menu')
var path = require('path')
var http = require('http')
2015-08-14 07:43:51 +11:00
var fs = require('fs')
2015-06-25 13:23:27 +11:00
2015-08-04 11:54:30 +11:00
var windows = require('./lib/windows')
var config = require('ssb-config/inject')(process.env.ssb_appname)
2015-08-04 11:54:30 +11:00
var ssbKeys = require('ssb-keys')
var createSbot = require('scuttlebot')
.use(require('scuttlebot/plugins/master'))
.use(require('scuttlebot/plugins/gossip'))
.use(require('scuttlebot/plugins/friends'))
.use(require('scuttlebot/plugins/replicate'))
.use(require('scuttlebot/plugins/blobs'))
.use(require('scuttlebot/plugins/invite'))
.use(require('scuttlebot/plugins/block'))
.use(require('scuttlebot/plugins/logging'))
2015-08-05 04:13:17 +11:00
.use(require('scuttlebot/plugins/private'))
.use(require('../api'))
2015-06-25 02:41:17 +11:00
2015-08-04 11:54:30 +11:00
config.keys = ssbKeys.loadOrCreateSync(path.join(config.path, 'secret'))
if(config.keys.curve === 'k256')
throw new Error('k256 curves are no longer supported,'+
'please delete' + path.join(config.path, 'secret'))
2015-06-25 02:41:17 +11:00
2015-08-04 11:54:30 +11:00
app.on('ready', function () {
2015-06-25 02:41:17 +11:00
// start sbot
2015-08-04 11:54:30 +11:00
var rebuild = false
var sbot = createSbot(config)
2015-08-14 07:43:51 +11:00
// write manifest file
fs.writeFileSync(
path.join(config.path, 'manifest.json'),
JSON.stringify(sbot.getManifest(), null, 2)
)
2015-08-04 11:54:30 +11:00
// setup blob and file serving
var blobs = require('./lib/blobs')(sbot, { blobs_dir: path.join(config.path, 'blobs'), checkout_dir: app.getPath('userDesktop') })
http.createServer(blobs.server({ serveFiles: false })).listen(7777)
http.createServer(blobs.server({ serveFiles: true })).listen(7778)
2015-06-25 13:42:31 +11:00
2015-08-04 11:54:30 +11:00
// open main window
var mainWindow = windows.open(
'file://' + path.join(__dirname, '../ui/main.html'),
2015-08-04 11:54:30 +11:00
sbot,
blobs,
{ width: 1030, height: 720 }
)
require('./lib/menu')(mainWindow)
// mainWindow.openDevTools()
// setup menu
// Menu.setApplicationMenu(Menu.buildFromTemplate([{
// label: 'Window',
// submenu: [
// // { label: 'Open Web App', click: onopen },
// { label: 'Quit', click: onquit }
// ]
// }]))
2015-06-25 02:41:17 +11:00
});