From 8c48c4000e3aab5889dbfbc32e8bc45cc83be783 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Wed, 24 Jun 2015 21:42:31 -0500 Subject: [PATCH] add new-window intercept behavior --- app/index.js | 17 +++++++++++++++++ app/lib/ext-protocol.js | 1 - 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/index.js b/app/index.js index f82eb41..3fcb0ba 100644 --- a/app/index.js +++ b/app/index.js @@ -1,10 +1,12 @@ var app = require('app') +var path = require('path') var Tray = require('tray') var Menu = require('menu') var shell = require('shell') var BrowserWindow = require('browser-window') var config = require('ssb-config') +var toPath = require('multiblob/util').toPath // Report crashes to our server. //require('crash-reporter').start(); @@ -13,6 +15,8 @@ var tray var mainWindow app.on('ready', function ready () { + var blobs_dir = path.join(config.path, 'blobs') + // start sbot require('scuttlebot').init(config, function (err, sbot) { // register protocols @@ -21,8 +25,21 @@ app.on('ready', function ready () { // open the web app mainWindow = new BrowserWindow({width: 1000, height: 720}) mainWindow.loadUrl('file://' + __dirname + '/index.html') + mainWindow.webContents.on('new-window', onNewWindow) 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 // Menu.setApplicationMenu(Menu.buildFromTemplate([{ // label: 'Window', diff --git a/app/lib/ext-protocol.js b/app/lib/ext-protocol.js index a07d99c..4740396 100644 --- a/app/lib/ext-protocol.js +++ b/app/lib/ext-protocol.js @@ -7,7 +7,6 @@ module.exports = function (config) { return function (request) { var id = request.url.split(':')[1] if (request.method == 'GET' && id) { - console.log('loading', id, toPath(dir, id)) return new protocol.RequestFileJob(toPath(dir, id)) } }