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

added launch at startup functionality #1753

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions app/bg/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
// =
Expand Down Expand Up @@ -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 = {
Expand All @@ -149,6 +154,7 @@ export const WEBAPI = {
getProfile,
checkForUpdates,
restartBrowser,
setRunOnStartup,

getSetting,
getSettings,
Expand All @@ -167,7 +173,6 @@ export const WEBAPI = {
readFile,

convertDat,

getResourceContentType,
getCertificate,

Expand Down Expand Up @@ -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"
}
Expand Down Expand Up @@ -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)
}
}
1 change: 1 addition & 0 deletions app/bg/dbs/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions app/bg/web-apis/manifests/internal/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default {
getProfile: 'promise',
checkForUpdates: 'promise',
restartBrowser: 'sync',
setRunOnStartup: 'promise',

getSettings: 'promise',
getSetting: 'promise',
Expand All @@ -14,7 +15,7 @@ export default {
setupDefaultProfile: 'promise',
migrate08to09: 'promise',
setStartPageBackgroundImage: 'promise',

getDefaultProtocolSettings: 'promise',
setAsDefaultProtocolClient: 'promise',
removeAsDefaultProtocolClient: 'promise',
Expand All @@ -34,7 +35,6 @@ export default {

getResourceContentType: 'sync',
getCertificate: 'promise',

executeSidebarCommand: 'promise',
executeShellWindowCommand: 'promise',
toggleSiteInfo: 'promise',
Expand Down
1 change: 1 addition & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
40 changes: 31 additions & 9 deletions app/userland/settings/js/views/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,24 +262,37 @@ class GeneralSettingsView extends LitElement {
renderRunBackgroundSettings () {
return html`
<div class="section on-startup">
<h2 id="on-startup">Background</h2>
<h2 id="on-startup">Background & Startup</h2>

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

<div class="radio-item">
<input type="checkbox" id="runBackground"
?checked=${this.settings.run_background == 1}
@change=${this.onRunBackgroundToggle} />
<label for="runBackground">
Let Beaker run in the background
</label>
<div>
<div class="radio-item">
<input type="checkbox" id="runBackground"
?checked=${this.settings.run_background == 1}
@change=${this.onRunBackgroundToggle} />
<label for="runBackground">
Let Beaker run in the background
</label>
</div>
<div>
<div class="radio-item">
<input type="checkbox" id="onStart"
?checked=${this.settings.launch_on_startup == 1}
@change=${this.onLaunchOnStartupToggle} />
<label for=onStart">
Launch Beaker on computer startup
</label>
</div>
</div>
</div>
</div>
`
}



renderNewTabSettings () {
return html`
<div class="section new-tab">
Expand Down Expand Up @@ -337,6 +350,8 @@ class GeneralSettingsView extends LitElement {
`
}



renderDefaultZoomSettings () {
const opt = (v, label) => html`
<option value=${v} ?selected=${v === this.settings.default_zoom}>${label}</option>
Expand Down Expand Up @@ -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)
Expand Down