Skip to content

Commit

Permalink
feat: open web ui on startup
Browse files Browse the repository at this point in the history
Adds the option to open Web UI automatically on startup.
This is enabled by default when the OS is neither Windows,
nor macOS to help users that do not have a tray icon.

License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
  • Loading branch information
hacdias committed Apr 24, 2020
1 parent dfad823 commit 0abf507
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions assets/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@
"openNodeSettings": "Open Node Settings",
"appPreferences": "App Preferences",
"launchOnStartup": "Launch at Login",
"launchWebUIOnStartup": "Launch Web UI on Startup",
"ipfsCommandLineTools": "Command Line Tools",
"takeScreenshotShortcut": "Global Screenshot Shortcut",
"downloadHashShortcut": "Global Download Shortcut",
Expand Down
3 changes: 3 additions & 0 deletions src/tray.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ const { CONFIG_KEY: DOWNLOAD_KEY, SHORTCUT: DOWNLOAD_SHORTCUT, downloadCid } = r
const { CONFIG_KEY: AUTO_LAUNCH_KEY, isSupported: supportsLaunchAtLogin } = require('./auto-launch')
const { CONFIG_KEY: IPFS_PATH_KEY } = require('./ipfs-on-path')
const { CONFIG_KEY: NPM_IPFS_KEY } = require('./npm-on-ipfs')
const { CONFIG_KEY: AUTO_LAUNCH_WEBUI_KEY } = require('./webui')

const CONFIG_KEYS = [
AUTO_LAUNCH_KEY,
AUTO_LAUNCH_WEBUI_KEY,
IPFS_PATH_KEY,
NPM_IPFS_KEY,
SCREENSHOT_KEY,
Expand Down Expand Up @@ -118,6 +120,7 @@ function buildMenu (ctx) {
enabled: false
},
buildCheckbox(AUTO_LAUNCH_KEY, 'settings.launchOnStartup'),
buildCheckbox(AUTO_LAUNCH_WEBUI_KEY, 'settings.launchWebUIOnStartup'),
buildCheckbox(IPFS_PATH_KEY, 'settings.ipfsCommandLineTools'),
buildCheckbox(SCREENSHOT_KEY, 'settings.takeScreenshotShortcut'),
buildCheckbox(DOWNLOAD_KEY, 'settings.downloadHashShortcut'),
Expand Down
22 changes: 22 additions & 0 deletions src/webui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ const os = require('os')
const openExternal = require('./open-external')
const logger = require('../common/logger')
const store = require('../common/store')
const { IS_MAC, IS_WIN } = require('../common/consts')
const dock = require('../utils/dock')
const { VERSION } = require('../common/consts')
const createToggler = require('../utils/create-toggler')

serve({ scheme: 'webui', directory: join(__dirname, '../../assets/webui') })

const CONFIG_KEY = 'webuiAtLogin'

const createWindow = () => {
const dimensions = screen.getPrimaryDisplay()

Expand Down Expand Up @@ -72,6 +76,17 @@ const apiOrigin = (apiMultiaddr) => {
}

module.exports = async function (ctx) {
// First time running this. If it's not macOS, nor Windows,
// enable launching web ui at login.
if (store.get(CONFIG_KEY, null) === null) {
store.set(CONFIG_KEY, !IS_MAC && !IS_WIN)
}

createToggler(CONFIG_KEY, async ({ newValue }) => {
store.set(CONFIG_KEY, newValue)
return true
})

openExternal()

const window = createWindow(ctx)
Expand Down Expand Up @@ -130,10 +145,17 @@ module.exports = async function (ctx) {
return new Promise(resolve => {
window.once('ready-to-show', () => {
logger.info('[web ui] window ready')

if (store.get(CONFIG_KEY)) {
ctx.launchWebUI('/')
}

resolve()
})

updateLanguage()
window.loadURL(url.toString())
})
}

module.exports.CONFIG_KEY = CONFIG_KEY

0 comments on commit 0abf507

Please sign in to comment.