Commit 79c10b336a5d261d0c19aedbef677d2a5d332ff3
portably openn links
Dominic Tarr committed on 6/24/2016, 10:20:23 PMParent: 82eeb2f00af985004afbb6a3ac6fe9b2f9a64eef
Files changed
modules/tabs.js | changed |
modules/tabs.js | ||
---|---|---|
@@ -2,9 +2,8 @@ | ||
2 | 2 | var h = require('hyperscript') |
3 | 3 | var pull = require('pull-stream') |
4 | 4 | var u = require('../util') |
5 | 5 | |
6 | - | |
7 | 6 | function ancestor (el) { |
8 | 7 | if(!el) return |
9 | 8 | if(el.tagName !== 'A') return ancestor(el.parentElement) |
10 | 9 | return el |
@@ -12,8 +11,23 @@ | ||
12 | 11 | |
13 | 12 | var plugs = require('../plugs') |
14 | 13 | var screen_view = plugs.first(exports.screen_view = []) |
15 | 14 | |
15 | +function openExternal (url) { | |
16 | + var _r = require //fool browserify | |
17 | + | |
18 | + //electron@1 | |
19 | + try {return _r('electron').shell.openExternal(url) } | |
20 | + catch (err) { } | |
21 | + | |
22 | + //electron@0 | |
23 | + try { return _r('shell').openExternal(url) } | |
24 | + catch (err) { } | |
25 | + | |
26 | + //browser | |
27 | + window.open(url, '_blank') | |
28 | +} | |
29 | + | |
16 | 30 | exports.message_render = [] |
17 | 31 | |
18 | 32 | exports.app = function () { |
19 | 33 | var tabs = Tabs() |
@@ -21,15 +35,9 @@ | ||
21 | 35 | |
22 | 36 | var saved |
23 | 37 | try { saved = JSON.parse(localStorage.openTabs) } |
24 | 38 | catch (_) { saved = ['/public', '/private'] } |
25 | - | |
26 | -// var public = screen_view('/public') | |
27 | -// if(public) tabs.add('public', public, true) | |
28 | -// | |
29 | -// var private = screen_view('/private') | |
30 | -// if(private) tabs.add('private', private, true) | |
31 | -// | |
39 | + | |
32 | 40 | saved.forEach(function (path) { |
33 | 41 | var el = screen_view(path) |
34 | 42 | if(el) tabs.add(path, el, true) |
35 | 43 | }) |
@@ -45,10 +53,9 @@ | ||
45 | 53 | ev.stopPropagation() |
46 | 54 | |
47 | 55 | //open external links. |
48 | 56 | //this ought to be made into something more runcible |
49 | -// if(/^https?/.test(link.href)) | |
50 | -// return require('electron').shell.openExternal(link.href) | |
57 | + if(/^https?/.test(link.href)) return openExternal(link.href) | |
51 | 58 | |
52 | 59 | if(tabs.has(path)) return tabs.select(path) |
53 | 60 | |
54 | 61 | var el = screen_view(path) |
@@ -61,4 +68,14 @@ | ||
61 | 68 | return tabs |
62 | 69 | } |
63 | 70 | |
64 | 71 | |
72 | + | |
73 | + | |
74 | + | |
75 | + | |
76 | + | |
77 | + | |
78 | + | |
79 | + | |
80 | + | |
81 | + |
Built with git-ssb-web