Skip to content

Commit 2525fe2

Browse files
committed
supports Flatpak browser based on @ygun's #151
1 parent 0f351f6 commit 2525fe2

File tree

2 files changed

+122
-2
lines changed

2 files changed

+122
-2
lines changed

linux/app/install.js

Lines changed: 111 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const dir = path.join(share, 'com.add0n.node');
4545
const name = 'com.add0n.node';
4646
const ids = require('./config.js').ids;
4747

48-
function manifest(root, type) {
48+
function manifest(root, type, executable = path.join(dir, 'run.sh')) {
4949
console.log(' -> Creating a directory at', root);
5050
return new Promise((resolve, reject) => {
5151
exists(root, e => {
@@ -62,7 +62,7 @@ function manifest(root, type) {
6262
fs.writeFile(path.join(root, name + '.json'), `{
6363
"name": "${name}",
6464
"description": "Node Host for Native Messaging",
65-
"path": "${path.join(dir, 'run.sh')}",
65+
"path": "${executable}",
6666
"type": "stdio",
6767
${origins}
6868
}`, e => {
@@ -166,10 +166,119 @@ async function firefox() {
166166
}
167167
}
168168

169+
// Flatpak browser support
170+
const FLATPAK_BROWSERS = {
171+
// Chromium-based browsers
172+
'com.google.Chrome': {
173+
path: 'config/google-chrome/NativeMessagingHosts',
174+
type: 'chrome',
175+
name: 'Google Chrome (Flatpak)'
176+
},
177+
'org.chromium.Chromium': {
178+
path: 'config/chromium/NativeMessagingHosts',
179+
type: 'chrome',
180+
name: 'Chromium (Flatpak)'
181+
},
182+
'com.opera.Opera': {
183+
path: 'config/google-chrome/NativeMessagingHosts',
184+
type: 'chrome',
185+
name: 'Opera (Flatpak)'
186+
},
187+
'com.brave.Browser': {
188+
path: 'config/BraveSoftware/Brave-Browser/NativeMessagingHosts',
189+
type: 'chrome',
190+
name: 'Brave (Flatpak)'
191+
},
192+
'com.microsoft.Edge': {
193+
path: 'config/microsoftedge/NativeMessagingHosts',
194+
type: 'chrome',
195+
name: 'Microsoft Edge (Flatpak)'
196+
},
197+
'com.vivaldi.Vivaldi': {
198+
path: 'config/vivaldi/NativeMessagingHosts',
199+
type: 'chrome',
200+
name: 'Vivaldi (Flatpak)'
201+
},
202+
// Firefox-based browsers
203+
'org.mozilla.firefox': {
204+
path: '.mozilla/native-messaging-hosts',
205+
type: 'firefox',
206+
name: 'Firefox (Flatpak)'
207+
},
208+
'io.gitlab.librewolf-community': {
209+
path: '.librewolf/native-messaging-hosts',
210+
type: 'firefox',
211+
name: 'LibreWolf (Flatpak)'
212+
}
213+
};
214+
215+
function getInstalledFlatpaks() {
216+
const {execSync} = require('child_process');
217+
try {
218+
const output = execSync('/usr/bin/flatpak list --app --columns=application', {encoding: 'utf8'});
219+
return output.trim().split('\n').filter(line => line.length > 0);
220+
}
221+
catch (e) {
222+
// flatpak not installed or no apps
223+
return [];
224+
}
225+
}
226+
227+
async function flatpak() {
228+
const installed = getInstalledFlatpaks();
229+
let count = 0;
230+
231+
for (const appId of installed) {
232+
const browser = FLATPAK_BROWSERS[appId];
233+
if (browser) {
234+
// Check if we should install for this browser type
235+
if ((browser.type === 'chrome' && ids.chrome.length) ||
236+
(browser.type === 'firefox' && ids.firefox.length)) {
237+
try {
238+
const manifestPath = path.join(
239+
process.env.HOME,
240+
'.var/app',
241+
appId,
242+
browser.path
243+
);
244+
245+
// write wrapper
246+
const run = `#!/bin/sh
247+
248+
flatpak-spawn --host sh -c '
249+
cd ${dir}/ || exit 1
250+
exec ./run.sh
251+
'`;
252+
const exe = path.join(manifestPath, `${name}.sh`);
253+
await new Promise((resolve, reject) => fs.writeFile(exe, run, e => {
254+
if (e) {
255+
return reject(e);
256+
}
257+
fs.chmodSync(exe, '0755');
258+
resolve();
259+
}));
260+
261+
await manifest(manifestPath, browser.type, exe);
262+
console.log(` -> ${browser.name} is supported`);
263+
count++;
264+
}
265+
catch (e) {
266+
console.error(` -> Warning: Failed to install manifest for ${browser.name}:`, e.message);
267+
}
268+
}
269+
}
270+
}
271+
272+
if (count > 0) {
273+
console.log(` -> Installed manifests for ${count} Flatpak browser(s)`);
274+
}
275+
}
276+
169277
(async () => {
170278
try {
171279
await chrome();
172280
await firefox();
281+
await flatpak();
173282
await application();
174283
console.log(' => Native Host is installed in', dir);
175284
console.log('\n\n>>> host is ready <<<\n\n');

linux/uninstall.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ echo " -> Removing manifest file for Tor"
1818
rm -f ~/.tor-browser/app/Browser/TorBrowser/Data/Browser/.mozilla/native-messaging-hosts/com.add0n.node.json
1919
echo " -> Removing manifest file for Thunderbird"
2020
rm -f ~/.thunderbird/native-messaging-hosts/com.add0n.node.json
21+
22+
echo " -> Removing manifest files for Flatpak browsers"
23+
rm -f ~/.var/app/com.opera.Opera/config/google-chrome/NativeMessagingHosts/com.add0n.node.json
24+
rm -f ~/.var/app/com.google.Chrome/config/google-chrome/NativeMessagingHosts/com.add0n.node.json
25+
rm -f ~/.var/app/org.chromium.Chromium/config/chromium/NativeMessagingHosts/com.add0n.node.json
26+
rm -f ~/.var/app/com.brave.Browser/config/BraveSoftware/Brave-Browser/NativeMessagingHosts/com.add0n.node.json
27+
rm -f ~/.var/app/com.microsoft.Edge/config/microsoftedge/NativeMessagingHosts/com.add0n.node.json
28+
rm -f ~/.var/app/com.vivaldi.Vivaldi/config/vivaldi/NativeMessagingHosts/com.add0n.node.json
29+
rm -f ~/.var/app/org.mozilla.firefox/.mozilla/native-messaging-hosts/com.add0n.node.json
30+
rm -f ~/.var/app/io.gitlab.librewolf-community/.librewolf/native-messaging-hosts/com.add0n.node.json
31+
2132
echo " -> Removing executables"
2233
rm -f -r ~/.config/com.add0n.node
2334

0 commit comments

Comments
 (0)