Skip to content

Commit 2244f3a

Browse files
Fix tray context menu (#195)
Co-authored-by: Owen McGirr <o.a.mcgirr@gmail.com>
1 parent 8c5f382 commit 2244f3a

2 files changed

Lines changed: 10 additions & 20 deletions

File tree

src/main/tray.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,33 +98,33 @@ describe('createSwitchifyTray', () => {
9898
expect(callbacks.quit).not.toHaveBeenCalled();
9999
});
100100

101-
it('opens the context menu on Windows right-click', () => {
101+
it('attaches the context menu on Windows', () => {
102102
const callbacks = createCallbacks();
103103
createSwitchifyTray({
104104
...callbacks,
105105
getStatus: () => status()
106106
});
107107

108-
tray().emit('right-click');
109-
110-
expect(tray().popUpContextMenu).toHaveBeenCalledTimes(1);
111-
expect(tray().popUpContextMenu).toHaveBeenCalledWith(lastMenu());
112-
expect(callbacks.showWindow).not.toHaveBeenCalled();
108+
expect(tray().setContextMenu).toHaveBeenCalledTimes(1);
109+
expect(tray().setContextMenu).toHaveBeenCalledWith(lastMenu());
110+
expect(tray().popUpContextMenu).not.toHaveBeenCalled();
111+
expect(tray().handlers.has('right-click')).toBe(false);
113112
});
114113

115-
it('refreshes the right-click menu with the latest status', () => {
114+
it('refreshes the context menu with the latest status on update', () => {
116115
const callbacks = createCallbacks();
117116
let connectedClientCount = 0;
118-
createSwitchifyTray({
117+
const switchifyTray = createSwitchifyTray({
119118
...callbacks,
120119
getStatus: () => status({ connectedClientCount })
121120
});
122121

123122
connectedClientCount = 1;
124-
tray().emit('right-click');
123+
switchifyTray.update();
125124

126125
const disconnectItem = lastMenu().template.find((item) => item.label === 'Disconnect device');
127126
expect(disconnectItem?.enabled).toBe(true);
127+
expect(tray().setContextMenu).toHaveBeenLastCalledWith(lastMenu());
128128
});
129129

130130
it('refreshes the tooltip on update', () => {

src/main/tray.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,10 @@ export function createSwitchifyTray(options: SwitchifyTrayOptions): SwitchifyTra
2424
const status = options.getStatus();
2525
currentMenu = buildTrayMenu(options, status);
2626
tray.setToolTip(`Switchify PC - ${formatTooltipStatus(status)}`);
27-
if (process.platform !== 'win32') {
28-
tray.setContextMenu(currentMenu);
29-
}
27+
tray.setContextMenu(currentMenu);
3028
};
3129

3230
tray.on('click', options.showWindow);
33-
if (process.platform === 'win32') {
34-
tray.on('right-click', () => {
35-
update();
36-
if (currentMenu) {
37-
tray.popUpContextMenu(currentMenu);
38-
}
39-
});
40-
}
4131
update();
4232

4333
return {

0 commit comments

Comments
 (0)