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

fix(tray): 🔧 Fix setter for tray-menu #2594

Merged
merged 4 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const pDefer = require('p-defer')
const logger = require('./common/logger')

/**
* @typedef {'tray-menu' | 'tray' | 'tray-menu-state' | 'tray.update-menu' | 'countlyDeviceId' | 'manualCheckForUpdates' | 'startIpfs' | 'stopIpfs' | 'restartIpfs' | 'getIpfsd' | 'launchWebUI' | 'webui' | 'splashScreen'} ContextProperties
* @typedef { 'tray' | 'tray-menu-state' | 'tray.update-menu' | 'countlyDeviceId' | 'manualCheckForUpdates' | 'startIpfs' | 'stopIpfs' | 'restartIpfs' | 'getIpfsd' | 'launchWebUI' | 'webui' | 'splashScreen'} ContextProperties
*/

/**
Expand Down
10 changes: 7 additions & 3 deletions src/tray.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ function buildCheckbox (key, label) {
// they natively work as soon as the menu opens. They don't work like that on Windows
// or other OSes and must be registered globally. They still collide with global
// accelerator. Please see ../utils/setup-global-shortcut.js for more info.
/**
*
* @returns {Promise<Omit<Electron.Menu, 'getMenuItemById'> & {getMenuItemById: (id: string) => Electron.MenuItem}>}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this ugly type is only to satisfy the method calls downstream which want getMenuItemById to not return null

*/
async function buildMenu () {
const ctx = getCtx()
const restartIpfs = ctx.getFn('restartIpfs')
Expand All @@ -40,6 +44,7 @@ async function buildMenu () {
const launchWebUI = ctx.getFn('launchWebUI')
const manualCheckForUpdates = ctx.getFn('manualCheckForUpdates')

// @ts-ignore
return Menu.buildFromTemplate([
// @ts-ignore
...[
Expand Down Expand Up @@ -259,7 +264,6 @@ const setupMenu = async () => {
const ctx = getCtx()
const updateMenu = ctx.getFn('tray.update-menu')
const menu = await buildMenu()
ctx.setProp('tray-menu', menu)

tray.setContextMenu(menu)
tray.setToolTip('IPFS Desktop')
Expand Down Expand Up @@ -309,7 +313,7 @@ module.exports = async function () {
const ctx = getCtx()
const { status, gcRunning, isUpdating } = await ctx.getProp('tray-menu-state')
const errored = status === STATUS.STARTING_FAILED || status === STATUS.STOPPING_FAILED
const menu = await ctx.getProp('tray-menu')
const menu = await buildMenu()

menu.getMenuItemById('ipfsIsStarting').visible = status === STATUS.STARTING_STARTED && !gcRunning && !isUpdating
menu.getMenuItemById('ipfsIsRunning').visible = status === STATUS.STARTING_FINISHED && !gcRunning && !isUpdating
Expand Down Expand Up @@ -396,7 +400,7 @@ module.exports = async function () {
})

ipcMain.on(ipcMainEvents.CONFIG_UPDATED, () => { updateMenu() })
ipcMain.on(ipcMainEvents.LANG_UPDATED, async () => { await setupMenu() })
ipcMain.on(ipcMainEvents.LANG_UPDATED, () => { updateMenu() })

nativeTheme.on('updated', () => {
updateMenu()
Expand Down