Skip to content

Commit

Permalink
fix(tray): 🗑️ no need for tray-menu on context
Browse files Browse the repository at this point in the history
Signed-off-by: Nishant Arora <[email protected]>
  • Loading branch information
whizzzkid committed Aug 22, 2023
1 parent 4d5425a commit 8ec6d69
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
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
8 changes: 6 additions & 2 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}>}
*/
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

0 comments on commit 8ec6d69

Please sign in to comment.