Skip to content

Commit

Permalink
Supporting open-in-opera and open-in-edge for Chrome browser
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-portmen committed Dec 8, 2016
1 parent 102cd84 commit d1376e0
Show file tree
Hide file tree
Showing 12 changed files with 336 additions and 218 deletions.
14 changes: 14 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

exports.ids = {
chrome: [
'lmeddoobegbaiopohmpmmobpnpjifpii', // open in Firefox (Chrome)
'agaecbnjediafcdopcfidcdiponjlmnk', // open in Explorer (Chrome)

This comment has been minimized.

Copy link
@williamcasto1970
'hhalgjmpmjelidhhjldondajffjbcmcg', // open in Firefox (Opera)
'poibpkhpegdblnblbkcppknekhkhmmlp', // open in Edge (Chrome)
'amojccmdnkdlcjcplmkijeenigbhfbpd', // open in Opera (Chrome)
],
firefox: [
'{5610edea-88c1-4370-b93d-86aa131971d1}', // open in Explorer
]
};
9 changes: 5 additions & 4 deletions host.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var spawn = require('child_process').spawn;

var config = {
version: '0.1.0',
version: '0.1.3',
isWin: /^win/.test(process.platform)
};

Expand All @@ -19,7 +19,7 @@ function observe (msg, push, done) {
done();
}
else if (msg.cmd === 'spawn') {
let sp = spawn(msg.command, msg.arguments);
let sp = spawn(msg.command, msg.arguments || [], msg.properties || {});
sp.stdout.on('data', stdout => push({stdout}));
sp.stderr.on('data', stderr => push({stderr}));
sp.on('close', (code) => {
Expand All @@ -28,7 +28,7 @@ function observe (msg, push, done) {
});
}
else if (msg.cmd === 'exec') {
let sp = spawn(msg.command, msg.arguments);
let sp = spawn(msg.command, msg.arguments || [], msg.properties || {});
let stderr = '', stdout = '';
sp.stdout.on('data', data => stdout += data);
sp.stderr.on('data', data => stderr += data);
Expand All @@ -50,7 +50,8 @@ function observe (msg, push, done) {
else {
push({
error: 'cmd is unknown',
cmd: msg.cmd
cmd: msg.cmd,
code: 1000
});
done();
}
Expand Down
119 changes: 0 additions & 119 deletions install-linux.js

This file was deleted.

91 changes: 0 additions & 91 deletions install-windows.js

This file was deleted.

1 change: 1 addition & 0 deletions linux/app/config.js
1 change: 0 additions & 1 deletion linux/app/install.js

This file was deleted.

112 changes: 112 additions & 0 deletions linux/app/install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
'use strict';

var fs = require('fs');
var path = require('path');

function exists (directory, callback) {
let root = '/';
let dirs = directory.split('/');
function one () {
root = path.join(root, dirs.shift());
fs.stat(root, (e) => {
if (!e && dirs.length) {
one();
}
else if (e && e.code === 'ENOENT') {
fs.mkdir(root, (e) => {
if (e) {
callback(e);
}
else if (dirs.length) {
one();
}
else {
callback();
}
});
}
else {
callback(e);
}
});
}
one();
}

var dir = path.join('/usr/share', 'com.add0n.node');
var name = 'com.add0n.node';
var ids = require('./config.js').ids;

function manifest (root, type, callback) {
exists(root, (e) => {
if (e) {
throw e;
}
let origins;
if (type === 'chrome') {
origins = '"allowed_origins": ' + JSON.stringify(ids.chrome.map(id => 'chrome-extension://' + id + '/'));
}
else {
origins = '"allowed_extensions": ' + JSON.stringify(ids.firefox);
}
fs.writeFile(path.join(root, name + '.json'), `{
"name": "${name}",
"description": "Node Host for Native Messaging",
"path": "${path.join(dir, 'run.sh')}",
"type": "stdio",
${origins}
}`, (e) => {
if (e) {
throw e;
}
callback();
});

});
}
function application (callback) {
exists(dir, (e) => {
if (e) {
throw e;
}
let isNode = process.argv[2] !== '--add_node';
let run = isNode ? `#!/bin/bash\n${process.argv[2]} host.js` : '#!/bin/bash\n./node host.js';
fs.writeFile(path.join(dir, 'run.sh'), run, (e) => {
if (e) {
throw e;
}
fs.chmodSync(path.join(dir, 'run.sh'), '0755');
if (!isNode) {
fs.createReadStream('../node').pipe(fs.createWriteStream(path.join(dir, 'node')));
fs.chmodSync(path.join(dir, 'node'), '0755');
}
fs.createReadStream('host.js').pipe(fs.createWriteStream(path.join(dir, 'host.js')));
fs.createReadStream('messaging.js').pipe(fs.createWriteStream(path.join(dir, 'messaging.js')));
callback();
});
});
}
function chrome (callback) {
if (ids.chrome.length) {
manifest('/etc/opt/chrome/native-messaging-hosts', 'chrome', callback);
console.error('Chrome Browser is supported');
}
else {
callback();
}
}
function firefox (callback) {
if (ids.firefox.length) {
manifest('/usr/lib/mozilla/native-messaging-hosts', 'firefox', callback);
console.error('Firefox Browser is supported');
}
else {
callback();
}
}
chrome(() => firefox(() => {
application(() => {
console.error('Native Host is installed in', dir);
console.error('>> Application is ready to use <<');
});
}));
1 change: 1 addition & 0 deletions mac/app/config.js
1 change: 0 additions & 1 deletion mac/app/install.js

This file was deleted.

Loading

0 comments on commit d1376e0

Please sign in to comment.