Skip to content

Commit

Permalink
fix(tray): 🔧 Fix setter for tray-menu (#2594)
Browse files Browse the repository at this point in the history
* fix(tray): 🔧 Fix setter for tray-menu

Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>

* fix(tray): 🗑️ no need for tray-menu on context

Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>

* fix(tray): ✏️ fix ts-expect-error

Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>

* fix(translation): removing a cyclic call

Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>

---------

Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
  • Loading branch information
whizzzkid committed Aug 22, 2023
1 parent 87449b2 commit 7d680e3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 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
1 change: 0 additions & 1 deletion src/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,5 @@ module.exports = async function () {
store.safeSet('language', lang)

await i18n.changeLanguage(lang)
ipcMain.emit(ipcMainEvents.LANG_UPDATED, lang)
})
}
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}>}
*/
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-expect-error
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

0 comments on commit 7d680e3

Please sign in to comment.