Skip to content

Commit 7bc0728

Browse files
committed
Fix tray icon losing position on Windows 11
The issue is still valid on Windows 10, but nothing can be done about it unfortunately, until Electron fixes it. Closes #28
1 parent cb91d48 commit 7bc0728

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

src/main/index.ts

+21-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ import Store from "electron-store";
1515
import cron from "node-cron";
1616
import fs from "node:fs/promises";
1717
import path from "node:path";
18-
import { gt as semverGreaterThan } from "semver";
18+
import os from "node:os";
19+
import {
20+
gt as semverGreaterThan,
21+
gte as semverGreaterThanOrEqual,
22+
} from "semver";
1923
import { setTimeout as setTimeoutAsync } from "timers/promises";
2024

2125
import {
@@ -716,7 +720,7 @@ const setContextMenu = () => {
716720
checked: config.get("sendFiles", true),
717721
click: (checkBox) => handleCheckBoxClick(checkBox, "sendFiles"),
718722
toolTip: "Whether to enable sending copied files or not",
719-
visible: clipboardEx,
723+
visible: !!clipboardEx,
720724
},
721725
],
722726
},
@@ -745,7 +749,7 @@ const setContextMenu = () => {
745749
checked: config.get("receiveFiles", true),
746750
click: (checkBox) => handleCheckBoxClick(checkBox, "receiveFiles"),
747751
toolTip: "Whether to enable receiving files or not",
748-
visible: clipboardEx,
752+
visible: !!clipboardEx,
749753
},
750754
],
751755
},
@@ -810,12 +814,20 @@ const setContextMenu = () => {
810814
};
811815

812816
const createAppIcon = async () => {
813-
appIcon = new Tray(
814-
getTrayIcon("clipboard")
815-
// This GUID should not be changed. It ensures the tray icon position is kept between app updates.
816-
// TODO: restore GUID, see:
817-
// "72812af2-6bcc-40d9-b35d-0b43e72ac346"
818-
);
817+
// guid only works on Windows 11+
818+
// https://github.com/electron/electron/issues/41773
819+
if (
820+
os.platform() === "win32" &&
821+
semverGreaterThanOrEqual(os.release(), "10.0.22000")
822+
) {
823+
appIcon = new Tray(
824+
getTrayIcon("clipboard"),
825+
// This GUID should not be changed. It ensures the tray icon position is kept between app updates.
826+
"72812af2-6bcc-40d9-b35d-0b43e72ac346"
827+
);
828+
} else {
829+
appIcon = new Tray(getTrayIcon("clipboard"));
830+
}
819831
setContextMenu();
820832
appIcon.setToolTip(`${app.name} v${app.getVersion()}`);
821833

tsconfig.json

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"extends": "@electron-toolkit/tsconfig/tsconfig.node.json",
33
"include": ["electron.vite.config.ts", "src/main/*"],
44
"compilerOptions": {
5+
"module": "node16",
6+
"moduleResolution": "node16",
57
"composite": true,
68
"types": ["electron-vite/node"],
79
"strict": false,

0 commit comments

Comments
 (0)