Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Commit

Permalink
Support setting Beaker as the default browser in Linux (close #915)
Browse files Browse the repository at this point in the history
  • Loading branch information
pfrazee committed Apr 2, 2018
1 parent 40022e8 commit ce18a59
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions app/background-process/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import slugify from 'slugify'
import jetpack from 'fs-jetpack'
import emitStream from 'emit-stream'
import EventEmitter from 'events'
const exec = require('util').promisify(require('child_process').exec)
var debug = require('debug')('beaker')
import * as settingsDb from './dbs/settings'
import {open as openUrl} from './open-url'
Expand All @@ -20,6 +21,7 @@ import {

const IS_FROM_SOURCE = (process.defaultApp || /node_modules[\\/]electron[\\/]/.test(process.execPath))
const IS_LINUX = !(/^win/.test(process.platform)) && process.platform !== 'darwin'
const DOT_DESKTOP_FILENAME = 'appimagekit-beaker-browser.desktop'
const isBrowserUpdatesSupported = !(IS_LINUX || IS_FROM_SOURCE) // linux is temporarily not supported

// how long between scheduled auto updates?
Expand Down Expand Up @@ -185,14 +187,39 @@ export function setStartPageBackgroundImage (srcPath, appendCurrentDir) {
})
}

export function getDefaultProtocolSettings () {
export async function getDefaultProtocolSettings () {
if (IS_LINUX) {
// HACK
// xdb-settings doesnt currently handle apps that you can't `which`
// we can just use xdg-mime directly instead
// see https://github.com/beakerbrowser/beaker/issues/915
// -prf
let [httpHandler, datHandler] = await Promise.all([
exec('xdg-mime query default "x-scheme-handler/http"'),
exec('xdg-mime query default "x-scheme-handler/dat"')
])
return {
http: (httpHandler||'').trim() === DOT_DESKTOP_FILENAME,
dat: (datHandler||'').trim() === DOT_DESKTOP_FILENAME
}
}

return Promise.resolve(['http', 'dat'].reduce((res, x) => {
res[x] = app.isDefaultProtocolClient(x)
return res
}, {}))
}

export function setAsDefaultProtocolClient (protocol) {
export async function setAsDefaultProtocolClient (protocol) {
if (IS_LINUX) {
// HACK
// xdb-settings doesnt currently handle apps that you can't `which`
// we can just use xdg-mime directly instead
// see https://github.com/beakerbrowser/beaker/issues/915
// -prf
await exec(`xdg-mime default ${DOT_DESKTOP_FILENAME} "x-scheme-handler/${protocol}"`)
return true
}
return Promise.resolve(app.setAsDefaultProtocolClient(protocol))
}

Expand Down

0 comments on commit ce18a59

Please sign in to comment.