Skip to content

Commit

Permalink
feat(ux): open Web UI at launch on Linux (#1429)
Browse files Browse the repository at this point in the history
Closes #1153
  • Loading branch information
hacdias authored Apr 27, 2020
1 parent 9ec73bb commit f6691c7
Show file tree
Hide file tree
Showing 3 changed files with 28 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 @@ -219,6 +219,7 @@
"openNodeSettings": "Open Node Settings",
"appPreferences": "App Preferences",
"launchOnStartup": "Launch at Login",
"openWebUIAtLaunch": "Open Web UI at Launch",
"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.openWebUIAtLaunch'),
buildCheckbox(IPFS_PATH_KEY, 'settings.ipfsCommandLineTools'),
buildCheckbox(SCREENSHOT_KEY, 'settings.takeScreenshotShortcut'),
buildCheckbox(DOWNLOAD_KEY, 'settings.downloadHashShortcut'),
Expand Down
24 changes: 24 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 = 'openWebUIAtLaunch'

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

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

module.exports = async function (ctx) {
if (store.get(CONFIG_KEY, null) === null) {
// First time running this. If it's not macOS, nor Windows,
// enable opening ipfs-webui at app launch.
// This is the best we can do to mitigate Tray issues on Linux:
// https://github.com/ipfs-shipyard/ipfs-desktop/issues/1153
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 +147,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 f6691c7

Please sign in to comment.