diff --git a/app/bg/browser.js b/app/bg/browser.js index 0fb5cc1ab8..3350ece385 100644 --- a/app/bg/browser.js +++ b/app/bg/browser.js @@ -26,6 +26,7 @@ import { getEnvVar } from './lib/env' import * as hyperDaemon from './hyper/daemon' import * as bookmarks from './filesystem/bookmarks' import { setupDefaultProfile, getProfile, getDriveIdent } from './filesystem/index' +const AutoLaunch = require('auto-launch'); // constants // = @@ -139,6 +140,10 @@ export async function setup () { }) cb(request.errorCode) }) + + // Ensure run on startup is set correctly + const runOnStartup = getSetting('launch_on_startup') + await setRunOnStartup(runOnStartup) } export const WEBAPI = { @@ -149,6 +154,7 @@ export const WEBAPI = { getProfile, checkForUpdates, restartBrowser, + setRunOnStartup, getSetting, getSettings, @@ -167,7 +173,6 @@ export const WEBAPI = { readFile, convertDat, - getResourceContentType, getCertificate, @@ -739,7 +744,7 @@ async function focusPage () { async function executeJavaScriptInPage (js) { return getSenderTab(this.sender).webContents.executeJavaScript(js, true) - .catch(err => { + .catch(err => { if (err.toString().includes('Script failed to execute')) { throw "Injected script failed to execute" } @@ -876,3 +881,37 @@ function onCompleted (details) { set(details.responseHeaders['content-type']) } } + +async function setRunOnStartup (desiredState) { + if (IS_LINUX) { + const autoLauncher = new AutoLaunch({ + name: 'Beaker', + path: process.execPath + }) + const currentState = await autoLauncher.isEnabled() + if (currentState !== desiredState) { + if (desiredState === true){ + await autoLauncher.enable() + } else { + await autoLauncher.disable() + } + } + return + } + //using setLoginItems + const opts = {} + if (process.platform !== 'darwin') { + // mac + opts.path = path.resolve(path.dirname(process.execPath), '..', 'Update.exe') + opts.args = [ + '--processStart', `"${path.basename(process.execPath)}"`, + '--process-start-args', `"--hidden"` + ] + } + const currentState = app.getLoginItemSettings(opts) + + if (currentState !== desiredState) { + opts.openAtLogin = desiredState + app.setLoginItemSettings(opts) + } +} diff --git a/app/bg/dbs/settings.js b/app/bg/dbs/settings.js index f1dfc78e90..bd0b7e7855 100644 --- a/app/bg/dbs/settings.js +++ b/app/bg/dbs/settings.js @@ -41,6 +41,7 @@ export const setup = async function (opts) { new_tabs_in_foreground: 0, run_background: 1, default_zoom: 0, + launch_on_startup: 0, start_page_background_image: '', workspace_default_path: path.join(opts.homePath, 'Sites'), default_dat_ignore: '.git\n.dat\nnode_modules\n*.log\n**/.DS_Store\nThumbs.db\n', diff --git a/app/bg/web-apis/manifests/internal/browser.js b/app/bg/web-apis/manifests/internal/browser.js index 8500077546..9b9e9a0704 100644 --- a/app/bg/web-apis/manifests/internal/browser.js +++ b/app/bg/web-apis/manifests/internal/browser.js @@ -6,6 +6,7 @@ export default { getProfile: 'promise', checkForUpdates: 'promise', restartBrowser: 'sync', + setRunOnStartup: 'promise', getSettings: 'promise', getSetting: 'promise', @@ -14,7 +15,7 @@ export default { setupDefaultProfile: 'promise', migrate08to09: 'promise', setStartPageBackgroundImage: 'promise', - + getDefaultProtocolSettings: 'promise', setAsDefaultProtocolClient: 'promise', removeAsDefaultProtocolClient: 'promise', @@ -34,7 +35,6 @@ export default { getResourceContentType: 'sync', getCertificate: 'promise', - executeSidebarCommand: 'promise', executeShellWindowCommand: 'promise', toggleSiteInfo: 'promise', diff --git a/app/package.json b/app/package.json index d16dc583d7..16aec98c5a 100644 --- a/app/package.json +++ b/app/package.json @@ -12,6 +12,7 @@ "@beaker/library-tools": "^1.0.0", "ajv": "^6.10.2", "anymatch": "^2.0.0", + "auto-launch": "^5.0.5", "await-lock": "^1.2.1", "base32.js": "^0.1.0", "beaker-error-constants": "^1.4.0", diff --git a/app/userland/settings/js/views/general.js b/app/userland/settings/js/views/general.js index 6756bb7ad3..8051fa547c 100644 --- a/app/userland/settings/js/views/general.js +++ b/app/userland/settings/js/views/general.js @@ -262,24 +262,37 @@ class GeneralSettingsView extends LitElement { renderRunBackgroundSettings () { return html`
-

Background

+

Background & Startup

Running in the background helps keep your data online even if you're not using Beaker.

- -
- - +
+
+ + +
+
+
+ + +
+
` } + + renderNewTabSettings () { return html`
@@ -337,6 +350,8 @@ class GeneralSettingsView extends LitElement { ` } + + renderDefaultZoomSettings () { const opt = (v, label) => html` @@ -495,6 +510,13 @@ class GeneralSettingsView extends LitElement { toast.create('Setting updated') } + async onLaunchOnStartupToggle (e) { + const desiredState = e.target.checked + beaker.browser.setSetting('launch_on_startup', desiredState?1:0) + await beaker.browser.setRunOnStartup(desiredState) + toast.create('Setting updated') + } + onNewTabChange (e) { this.settings.new_tab = e.target.value beaker.browser.setSetting('new_tab', this.settings.new_tab)