Skip to content

Commit 3bf71df

Browse files
committed
fix[linux]: Tray menu not updating after start / stop on Linux KDE desktop environment;
v1.0.16
1 parent 41b7947 commit 3bf71df

File tree

4 files changed

+56
-16
lines changed

4 files changed

+56
-16
lines changed

electron/main/icpHandlers/startAndStopEffects.ts

+30-11
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
import { ipcMain } from "electron/main";
2-
import { app, BrowserWindow, Menu, nativeImage, Tray } from "electron";
2+
import {
3+
app,
4+
BrowserWindow,
5+
Menu,
6+
MenuItemConstructorOptions,
7+
nativeImage,
8+
Tray,
9+
} from "electron";
310
import path from "node:path";
11+
import cloneDeep from "lodash-es/cloneDeep";
12+
413

514
export const startAndStopEffectsHandler = (
615
_ipcMain: typeof ipcMain,
716
win: BrowserWindow,
817
tray: Tray,
9-
contextMenu: Menu
18+
contextMenuStructure: MenuItemConstructorOptions[]
1019
) => {
1120
const STOP_ICON = nativeImage.createFromPath(
1221
path.join(process.env.VITE_PUBLIC!, "icon.png")
@@ -33,13 +42,18 @@ export const startAndStopEffectsHandler = (
3342
win.setOverlayIcon(WORKING_OVERLAY_ICON, "Working");
3443
win.setTitle("Mouse Animator - Working");
3544

36-
const startBtnMenu = contextMenu.items.find(({label})=>label ==='Start')!
45+
const menuStructureCp =cloneDeep(contextMenuStructure);
46+
47+
const startBtnMenu = menuStructureCp.find(
48+
({ label }) => label === "Start"
49+
)!;
3750
startBtnMenu.enabled = false;
38-
const stopBtn = startBtnMenu.menu.items.find(
39-
({ label }) => label === "Stop"
40-
);
51+
52+
const stopBtn = menuStructureCp.find(({ label }) => label === "Stop");
53+
4154
if (stopBtn) stopBtn.enabled = true;
4255

56+
tray.setContextMenu(Menu.buildFromTemplate(menuStructureCp));
4357
});
4458

4559
_ipcMain.handle("stop-service-effects", async () => {
@@ -50,12 +64,17 @@ export const startAndStopEffectsHandler = (
5064
win.setTitle("Mouse Animator");
5165
win.setOverlayIcon(null, "");
5266

53-
const stopBtnMenu = contextMenu.items.find(({label})=>label ==='Stop')!
54-
stopBtnMenu.enabled = false;
55-
const startBtn = stopBtnMenu.menu.items.find(
67+
const menuStructureCp =cloneDeep(contextMenuStructure);
68+
69+
const startBtnMenu = menuStructureCp.find(
5670
({ label }) => label === "Start"
57-
);
58-
if (startBtn) startBtn.enabled = true;
71+
)!;
72+
startBtnMenu.enabled = true;
73+
74+
const stopBtn = menuStructureCp.find(({ label }) => label === "Stop");
75+
76+
if (stopBtn) stopBtn.enabled = false;
5977

78+
tray.setContextMenu(Menu.buildFromTemplate(menuStructureCp));
6079
});
6180
};

electron/main/index.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
BrowserWindow,
44
ipcMain,
55
Menu,
6+
MenuItemConstructorOptions,
67
nativeImage,
78
Tray,
89
} from "electron";
@@ -141,7 +142,7 @@ app.whenReady().then(() => {
141142

142143
tray = new Tray(trayImg.resize({ width: 24, height: 24 }));
143144

144-
const contextMenu = Menu.buildFromTemplate([
145+
const menuStructure = [
145146
{
146147
label: "Show App",
147148
click: () => win?.show(),
@@ -159,7 +160,9 @@ app.whenReady().then(() => {
159160
label: "Quit",
160161
click: () => app.exit(),
161162
},
162-
]);
163+
] as MenuItemConstructorOptions[]
164+
165+
const contextMenu = Menu.buildFromTemplate(menuStructure);
163166

164167
tray.setToolTip("Mosue Automator");
165168
tray.setContextMenu(contextMenu);
@@ -174,5 +177,5 @@ app.whenReady().then(() => {
174177
toggleAutoStartHandler(ipcMain);
175178
exitBehaviorHandler(ipcMain, win!);
176179
exitHandler(ipcMain);
177-
startAndStopEffectsHandler(ipcMain, win!, tray, contextMenu);
180+
startAndStopEffectsHandler(ipcMain, win!, tray, menuStructure);
178181
});

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "mouse-automator",
33
"private": true,
4-
"version": "1.0.15",
4+
"version": "1.0.16",
55
"type": "module",
66
"author": "Terry Chan",
77
"description": "Mouse Automator is a lightweight, user-friendly desktop application designed to automate mouse clicks with ease. Whether you're gaming, testing software, or handling repetitive tasks, Mouse Automator has you covered!",
@@ -25,7 +25,7 @@
2525
"@trufflesuite/ps-list": "^0.0.3",
2626
"electron-store": "^9.0.0",
2727
"i": "^0.3.7",
28-
"lodash": "^4.17.21",
28+
"lodash-es": "^4.17.21",
2929
"react": "^18.2.0",
3030
"react-dom": "^18.2.0",
3131
"react-toastify": "^10.0.5"
@@ -36,6 +36,7 @@
3636
"@testing-library/user-event": "^14.5.2",
3737
"@types/jest": "^29.5.12",
3838
"@types/lodash": "^4.17.4",
39+
"@types/lodash-es": "^4.17.12",
3940
"@types/react": "^18.2.64",
4041
"@types/react-dom": "^18.2.21",
4142
"@typescript-eslint/eslint-plugin": "^7.12.0",

yarn.lock

+17
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,18 @@
12201220
dependencies:
12211221
"@types/node" "*"
12221222

1223+
"@types/lodash-es@^4.17.12":
1224+
version "4.17.12"
1225+
resolved "https://registry.yarnpkg.com/@types/lodash-es/-/lodash-es-4.17.12.tgz#65f6d1e5f80539aa7cfbfc962de5def0cf4f341b"
1226+
integrity sha512-0NgftHUcV4v34VhXm8QBSftKVXtbkBG3ViCjs6+eJ5a6y6Mi/jiFGPc1sC7QK+9BFhWrURE3EOggmWaSxL9OzQ==
1227+
dependencies:
1228+
"@types/lodash" "*"
1229+
1230+
"@types/lodash@*":
1231+
version "4.17.7"
1232+
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.17.7.tgz#2f776bcb53adc9e13b2c0dfd493dfcbd7de43612"
1233+
integrity sha512-8wTvZawATi/lsmNu10/j2hk1KEP0IvjubqPE3cu1Xz7xfXXt5oCq3SNUz4fMIP4XGF9Ky+Ue2tBA3hcS7LSBlA==
1234+
12231235
"@types/lodash@^4.17.4":
12241236
version "4.17.4"
12251237
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.17.4.tgz#0303b64958ee070059e3a7184048a55159fe20b7"
@@ -4258,6 +4270,11 @@ locate-path@^6.0.0:
42584270
dependencies:
42594271
p-locate "^5.0.0"
42604272

4273+
lodash-es@^4.17.21:
4274+
version "4.17.21"
4275+
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.21.tgz#43e626c46e6591b7750beb2b50117390c609e3ee"
4276+
integrity sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==
4277+
42614278
lodash.merge@^4.6.2:
42624279
version "4.6.2"
42634280
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a"

0 commit comments

Comments
 (0)