From 0abf507efb76ad84f6fca8c2cdf944976e1016bf Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Mon, 20 Apr 2020 09:16:26 +0100 Subject: [PATCH] feat: open web ui on startup 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 --- assets/locales/en.json | 1 + src/tray.js | 3 +++ src/webui/index.js | 22 ++++++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/assets/locales/en.json b/assets/locales/en.json index 5e79a532f..0303ae5d3 100644 --- a/assets/locales/en.json +++ b/assets/locales/en.json @@ -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", diff --git a/src/tray.js b/src/tray.js index 48874b802..4e1595663 100644 --- a/src/tray.js +++ b/src/tray.js @@ -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, @@ -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'), diff --git a/src/webui/index.js b/src/webui/index.js index b3a7b31ac..21a7dde90 100644 --- a/src/webui/index.js +++ b/src/webui/index.js @@ -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() @@ -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) @@ -130,6 +145,11 @@ 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() }) @@ -137,3 +157,5 @@ module.exports = async function (ctx) { window.loadURL(url.toString()) }) } + +module.exports.CONFIG_KEY = CONFIG_KEY