Skip to content

Commit d1376e0

Browse files
committed
Supporting open-in-opera and open-in-edge for Chrome browser
1 parent 102cd84 commit d1376e0

File tree

12 files changed

+336
-218
lines changed

12 files changed

+336
-218
lines changed

config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
exports.ids = {
4+
chrome: [
5+
'lmeddoobegbaiopohmpmmobpnpjifpii', // open in Firefox (Chrome)
6+
'agaecbnjediafcdopcfidcdiponjlmnk', // open in Explorer (Chrome)
7+
'hhalgjmpmjelidhhjldondajffjbcmcg', // open in Firefox (Opera)
8+
'poibpkhpegdblnblbkcppknekhkhmmlp', // open in Edge (Chrome)
9+
'amojccmdnkdlcjcplmkijeenigbhfbpd', // open in Opera (Chrome)
10+
],
11+
firefox: [
12+
'{5610edea-88c1-4370-b93d-86aa131971d1}', // open in Explorer
13+
]
14+
};

host.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
var spawn = require('child_process').spawn;
44

55
var config = {
6-
version: '0.1.0',
6+
version: '0.1.3',
77
isWin: /^win/.test(process.platform)
88
};
99

@@ -19,7 +19,7 @@ function observe (msg, push, done) {
1919
done();
2020
}
2121
else if (msg.cmd === 'spawn') {
22-
let sp = spawn(msg.command, msg.arguments);
22+
let sp = spawn(msg.command, msg.arguments || [], msg.properties || {});
2323
sp.stdout.on('data', stdout => push({stdout}));
2424
sp.stderr.on('data', stderr => push({stderr}));
2525
sp.on('close', (code) => {
@@ -28,7 +28,7 @@ function observe (msg, push, done) {
2828
});
2929
}
3030
else if (msg.cmd === 'exec') {
31-
let sp = spawn(msg.command, msg.arguments);
31+
let sp = spawn(msg.command, msg.arguments || [], msg.properties || {});
3232
let stderr = '', stdout = '';
3333
sp.stdout.on('data', data => stdout += data);
3434
sp.stderr.on('data', data => stderr += data);
@@ -50,7 +50,8 @@ function observe (msg, push, done) {
5050
else {
5151
push({
5252
error: 'cmd is unknown',
53-
cmd: msg.cmd
53+
cmd: msg.cmd,
54+
code: 1000
5455
});
5556
done();
5657
}

install-linux.js

Lines changed: 0 additions & 119 deletions
This file was deleted.

install-windows.js

Lines changed: 0 additions & 91 deletions
This file was deleted.

linux/app/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../config.js

linux/app/install.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

linux/app/install.js

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
'use strict';
2+
3+
var fs = require('fs');
4+
var path = require('path');
5+
6+
function exists (directory, callback) {
7+
let root = '/';
8+
let dirs = directory.split('/');
9+
function one () {
10+
root = path.join(root, dirs.shift());
11+
fs.stat(root, (e) => {
12+
if (!e && dirs.length) {
13+
one();
14+
}
15+
else if (e && e.code === 'ENOENT') {
16+
fs.mkdir(root, (e) => {
17+
if (e) {
18+
callback(e);
19+
}
20+
else if (dirs.length) {
21+
one();
22+
}
23+
else {
24+
callback();
25+
}
26+
});
27+
}
28+
else {
29+
callback(e);
30+
}
31+
});
32+
}
33+
one();
34+
}
35+
36+
var dir = path.join('/usr/share', 'com.add0n.node');
37+
var name = 'com.add0n.node';
38+
var ids = require('./config.js').ids;
39+
40+
function manifest (root, type, callback) {
41+
exists(root, (e) => {
42+
if (e) {
43+
throw e;
44+
}
45+
let origins;
46+
if (type === 'chrome') {
47+
origins = '"allowed_origins": ' + JSON.stringify(ids.chrome.map(id => 'chrome-extension://' + id + '/'));
48+
}
49+
else {
50+
origins = '"allowed_extensions": ' + JSON.stringify(ids.firefox);
51+
}
52+
fs.writeFile(path.join(root, name + '.json'), `{
53+
"name": "${name}",
54+
"description": "Node Host for Native Messaging",
55+
"path": "${path.join(dir, 'run.sh')}",
56+
"type": "stdio",
57+
${origins}
58+
}`, (e) => {
59+
if (e) {
60+
throw e;
61+
}
62+
callback();
63+
});
64+
65+
});
66+
}
67+
function application (callback) {
68+
exists(dir, (e) => {
69+
if (e) {
70+
throw e;
71+
}
72+
let isNode = process.argv[2] !== '--add_node';
73+
let run = isNode ? `#!/bin/bash\n${process.argv[2]} host.js` : '#!/bin/bash\n./node host.js';
74+
fs.writeFile(path.join(dir, 'run.sh'), run, (e) => {
75+
if (e) {
76+
throw e;
77+
}
78+
fs.chmodSync(path.join(dir, 'run.sh'), '0755');
79+
if (!isNode) {
80+
fs.createReadStream('../node').pipe(fs.createWriteStream(path.join(dir, 'node')));
81+
fs.chmodSync(path.join(dir, 'node'), '0755');
82+
}
83+
fs.createReadStream('host.js').pipe(fs.createWriteStream(path.join(dir, 'host.js')));
84+
fs.createReadStream('messaging.js').pipe(fs.createWriteStream(path.join(dir, 'messaging.js')));
85+
callback();
86+
});
87+
});
88+
}
89+
function chrome (callback) {
90+
if (ids.chrome.length) {
91+
manifest('/etc/opt/chrome/native-messaging-hosts', 'chrome', callback);
92+
console.error('Chrome Browser is supported');
93+
}
94+
else {
95+
callback();
96+
}
97+
}
98+
function firefox (callback) {
99+
if (ids.firefox.length) {
100+
manifest('/usr/lib/mozilla/native-messaging-hosts', 'firefox', callback);
101+
console.error('Firefox Browser is supported');
102+
}
103+
else {
104+
callback();
105+
}
106+
}
107+
chrome(() => firefox(() => {
108+
application(() => {
109+
console.error('Native Host is installed in', dir);
110+
console.error('>> Application is ready to use <<');
111+
});
112+
}));

mac/app/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../config.js

mac/app/install.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)