Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ux): open Web UI at launch on Linux #1429

Merged
merged 4 commits into from
Apr 27, 2020
Merged
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
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