Skip to content

Commit 7d680e3

Browse files
authored
fix(tray): 🔧 Fix setter for tray-menu (#2594)
* fix(tray): 🔧 Fix setter for tray-menu Signed-off-by: Nishant Arora <[email protected]> * fix(tray): 🗑️ no need for tray-menu on context Signed-off-by: Nishant Arora <[email protected]> * fix(tray): ✏️ fix ts-expect-error Signed-off-by: Nishant Arora <[email protected]> * fix(translation): removing a cyclic call Signed-off-by: Nishant Arora <[email protected]> --------- Signed-off-by: Nishant Arora <[email protected]>
1 parent 87449b2 commit 7d680e3

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/context.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const pDefer = require('p-defer')
33
const logger = require('./common/logger')
44

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

99
/**

src/i18n.js

-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,5 @@ module.exports = async function () {
3535
store.safeSet('language', lang)
3636

3737
await i18n.changeLanguage(lang)
38-
ipcMain.emit(ipcMainEvents.LANG_UPDATED, lang)
3938
})
4039
}

src/tray.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ function buildCheckbox (key, label) {
3232
// they natively work as soon as the menu opens. They don't work like that on Windows
3333
// or other OSes and must be registered globally. They still collide with global
3434
// accelerator. Please see ../utils/setup-global-shortcut.js for more info.
35+
/**
36+
*
37+
* @returns {Promise<Omit<Electron.Menu, 'getMenuItemById'> & {getMenuItemById: (id: string) => Electron.MenuItem}>}
38+
*/
3539
async function buildMenu () {
3640
const ctx = getCtx()
3741
const restartIpfs = ctx.getFn('restartIpfs')
@@ -40,6 +44,7 @@ async function buildMenu () {
4044
const launchWebUI = ctx.getFn('launchWebUI')
4145
const manualCheckForUpdates = ctx.getFn('manualCheckForUpdates')
4246

47+
// @ts-expect-error
4348
return Menu.buildFromTemplate([
4449
// @ts-ignore
4550
...[
@@ -259,7 +264,6 @@ const setupMenu = async () => {
259264
const ctx = getCtx()
260265
const updateMenu = ctx.getFn('tray.update-menu')
261266
const menu = await buildMenu()
262-
ctx.setProp('tray-menu', menu)
263267

264268
tray.setContextMenu(menu)
265269
tray.setToolTip('IPFS Desktop')
@@ -309,7 +313,7 @@ module.exports = async function () {
309313
const ctx = getCtx()
310314
const { status, gcRunning, isUpdating } = await ctx.getProp('tray-menu-state')
311315
const errored = status === STATUS.STARTING_FAILED || status === STATUS.STOPPING_FAILED
312-
const menu = await ctx.getProp('tray-menu')
316+
const menu = await buildMenu()
313317

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

398402
ipcMain.on(ipcMainEvents.CONFIG_UPDATED, () => { updateMenu() })
399-
ipcMain.on(ipcMainEvents.LANG_UPDATED, async () => { await setupMenu() })
403+
ipcMain.on(ipcMainEvents.LANG_UPDATED, () => { updateMenu() })
400404

401405
nativeTheme.on('updated', () => {
402406
updateMenu()

0 commit comments

Comments
 (0)