add new-window intercept behavior
This commit is contained in:
parent
8a0c9db0fd
commit
8c48c4000e
17
app/index.js
17
app/index.js
@ -1,10 +1,12 @@
|
|||||||
var app = require('app')
|
var app = require('app')
|
||||||
|
var path = require('path')
|
||||||
var Tray = require('tray')
|
var Tray = require('tray')
|
||||||
var Menu = require('menu')
|
var Menu = require('menu')
|
||||||
var shell = require('shell')
|
var shell = require('shell')
|
||||||
var BrowserWindow = require('browser-window')
|
var BrowserWindow = require('browser-window')
|
||||||
|
|
||||||
var config = require('ssb-config')
|
var config = require('ssb-config')
|
||||||
|
var toPath = require('multiblob/util').toPath
|
||||||
|
|
||||||
// Report crashes to our server.
|
// Report crashes to our server.
|
||||||
//require('crash-reporter').start();
|
//require('crash-reporter').start();
|
||||||
@ -13,6 +15,8 @@ var tray
|
|||||||
var mainWindow
|
var mainWindow
|
||||||
|
|
||||||
app.on('ready', function ready () {
|
app.on('ready', function ready () {
|
||||||
|
var blobs_dir = path.join(config.path, 'blobs')
|
||||||
|
|
||||||
// start sbot
|
// start sbot
|
||||||
require('scuttlebot').init(config, function (err, sbot) {
|
require('scuttlebot').init(config, function (err, sbot) {
|
||||||
// register protocols
|
// register protocols
|
||||||
@ -21,8 +25,21 @@ app.on('ready', function ready () {
|
|||||||
// open the web app
|
// open the web app
|
||||||
mainWindow = new BrowserWindow({width: 1000, height: 720})
|
mainWindow = new BrowserWindow({width: 1000, height: 720})
|
||||||
mainWindow.loadUrl('file://' + __dirname + '/index.html')
|
mainWindow.loadUrl('file://' + __dirname + '/index.html')
|
||||||
|
mainWindow.webContents.on('new-window', onNewWindow)
|
||||||
mainWindow.on('closed', function() { mainWindow = null })
|
mainWindow.on('closed', function() { mainWindow = null })
|
||||||
|
|
||||||
|
function onNewWindow (e, url) {
|
||||||
|
e.preventDefault() // hell naw
|
||||||
|
if (url.indexOf('ext:') === 0) {
|
||||||
|
// open the file
|
||||||
|
var id = url.split(':')[1]
|
||||||
|
shell.openItem(toPath(blobs_dir, id))
|
||||||
|
} else {
|
||||||
|
// open in the browser
|
||||||
|
shell.openExternal(url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// setup menu
|
// setup menu
|
||||||
// Menu.setApplicationMenu(Menu.buildFromTemplate([{
|
// Menu.setApplicationMenu(Menu.buildFromTemplate([{
|
||||||
// label: 'Window',
|
// label: 'Window',
|
||||||
|
@ -7,7 +7,6 @@ module.exports = function (config) {
|
|||||||
return function (request) {
|
return function (request) {
|
||||||
var id = request.url.split(':')[1]
|
var id = request.url.split(':')[1]
|
||||||
if (request.method == 'GET' && id) {
|
if (request.method == 'GET' && id) {
|
||||||
console.log('loading', id, toPath(dir, id))
|
|
||||||
return new protocol.RequestFileJob(toPath(dir, id))
|
return new protocol.RequestFileJob(toPath(dir, id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user