Browse Source

add new-window intercept behavior

Paul Frazee 5 years ago
parent
commit
8c48c4000e
2 changed files with 17 additions and 1 deletions
  1. 17
    0
      app/index.js
  2. 0
    1
      app/lib/ext-protocol.js

+ 17
- 0
app/index.js View File

@@ -1,10 +1,12 @@
1 1
 var app = require('app')
2
+var path = require('path')
2 3
 var Tray = require('tray')
3 4
 var Menu = require('menu')
4 5
 var shell = require('shell')
5 6
 var BrowserWindow = require('browser-window')
6 7
 
7 8
 var config = require('ssb-config') 
9
+var toPath = require('multiblob/util').toPath
8 10
 
9 11
 // Report crashes to our server.
10 12
 //require('crash-reporter').start();
@@ -13,6 +15,8 @@ var tray
13 15
 var mainWindow
14 16
 
15 17
 app.on('ready', function ready () {
18
+  var blobs_dir = path.join(config.path, 'blobs')
19
+
16 20
   // start sbot
17 21
   require('scuttlebot').init(config, function (err, sbot) {
18 22
     // register protocols
@@ -21,8 +25,21 @@ app.on('ready', function ready () {
21 25
     // open the web app
22 26
     mainWindow = new BrowserWindow({width: 1000, height: 720})
23 27
     mainWindow.loadUrl('file://' + __dirname + '/index.html')
28
+    mainWindow.webContents.on('new-window', onNewWindow)
24 29
     mainWindow.on('closed', function() { mainWindow = null })
25 30
 
31
+    function onNewWindow (e, url) {
32
+      e.preventDefault() // hell naw
33
+      if (url.indexOf('ext:') === 0) {
34
+        // open the file
35
+        var id = url.split(':')[1]
36
+        shell.openItem(toPath(blobs_dir, id))
37
+      } else {
38
+        // open in the browser
39
+        shell.openExternal(url)
40
+      }
41
+    }
42
+
26 43
     // setup menu
27 44
     // Menu.setApplicationMenu(Menu.buildFromTemplate([{
28 45
     //   label: 'Window',

+ 0
- 1
app/lib/ext-protocol.js View File

@@ -7,7 +7,6 @@ module.exports = function (config) {
7 7
   return function (request) {
8 8
     var id = request.url.split(':')[1]
9 9
     if (request.method == 'GET' && id) {
10
-      console.log('loading', id, toPath(dir, id))
11 10
       return new protocol.RequestFileJob(toPath(dir, id))
12 11
     }
13 12
   }

Loading…
Cancel
Save