fix(tray): update Windows tray click and right-click behaviors to match conventions (#1152) (#1268)
Some checks failed
build-packages / ${{ needs.dedupe.outputs.skip_heavy_ci == 'true' && 'deduped build-linux-x64' || 'build-linux-x64' }} (push) Has been cancelled
build-packages / ${{ needs.dedupe.outputs.skip_heavy_ci == 'true' && 'deduped build-linux-arm64' || 'build-linux-arm64' }} (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / dedupe push run (push) Has been cancelled
build-packages / dedupe result (push) Has been cancelled
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
Some checks failed
build-packages / ${{ needs.dedupe.outputs.skip_heavy_ci == 'true' && 'deduped build-linux-x64' || 'build-linux-x64' }} (push) Has been cancelled
build-packages / ${{ needs.dedupe.outputs.skip_heavy_ci == 'true' && 'deduped build-linux-arm64' || 'build-linux-arm64' }} (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / dedupe push run (push) Has been cancelled
build-packages / dedupe result (push) Has been cancelled
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
This commit is contained in:
@@ -623,10 +623,21 @@ function createTray() {
|
||||
// Build and set initial context menu
|
||||
updateTrayMenu();
|
||||
|
||||
// Click on tray icon toggles tray panel
|
||||
tray.on("click", () => {
|
||||
toggleTrayPanel();
|
||||
});
|
||||
// Click on tray icon behaviors depending on platform conventions
|
||||
if (process.platform === "win32") {
|
||||
// Windows: Left-click opens/focuses main window, Right-click toggles custom tray panel
|
||||
tray.on("click", () => {
|
||||
openMainWindow();
|
||||
});
|
||||
tray.on("right-click", () => {
|
||||
toggleTrayPanel();
|
||||
});
|
||||
} else {
|
||||
// macOS/Linux: Click toggles custom tray panel
|
||||
tray.on("click", () => {
|
||||
toggleTrayPanel();
|
||||
});
|
||||
}
|
||||
|
||||
console.log("[GlobalShortcut] System tray created");
|
||||
} catch (err) {
|
||||
@@ -928,4 +939,5 @@ module.exports = {
|
||||
handleWindowClose,
|
||||
clearPendingFullscreenHide,
|
||||
cleanup,
|
||||
getTray: () => tray,
|
||||
};
|
||||
|
||||
@@ -491,3 +491,27 @@ test("handleWindowClose stays in close-to-tray mode even if hide fails", async (
|
||||
assert.equal(win.visible, true);
|
||||
});
|
||||
});
|
||||
|
||||
test("tray icon event registration is platform-dependent", async () => {
|
||||
// Test win32 platform
|
||||
await withPlatform("win32", async () => {
|
||||
const bridge = loadBridge();
|
||||
const { electronModule } = await enableCloseToTray(bridge);
|
||||
const trayInstance = bridge.getTray();
|
||||
assert.ok(trayInstance, "Tray instance should be created");
|
||||
assert.ok(trayInstance.handlers.has("click"), "win32 tray should have click handler");
|
||||
assert.ok(trayInstance.handlers.has("right-click"), "win32 tray should have right-click handler");
|
||||
bridge.cleanup();
|
||||
});
|
||||
|
||||
// Test other platform (darwin)
|
||||
await withPlatform("darwin", async () => {
|
||||
const bridge = loadBridge();
|
||||
const { electronModule } = await enableCloseToTray(bridge);
|
||||
const trayInstance = bridge.getTray();
|
||||
assert.ok(trayInstance, "Tray instance should be created");
|
||||
assert.ok(trayInstance.handlers.has("click"), "darwin tray should have click handler");
|
||||
assert.ok(!trayInstance.handlers.has("right-click"), "darwin tray should not have right-click handler");
|
||||
bridge.cleanup();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user