Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/main/tray.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,33 +98,33 @@ describe('createSwitchifyTray', () => {
expect(callbacks.quit).not.toHaveBeenCalled();
});

it('opens the context menu on Windows right-click', () => {
it('attaches the context menu on Windows', () => {
const callbacks = createCallbacks();
createSwitchifyTray({
...callbacks,
getStatus: () => status()
});

tray().emit('right-click');

expect(tray().popUpContextMenu).toHaveBeenCalledTimes(1);
expect(tray().popUpContextMenu).toHaveBeenCalledWith(lastMenu());
expect(callbacks.showWindow).not.toHaveBeenCalled();
expect(tray().setContextMenu).toHaveBeenCalledTimes(1);
expect(tray().setContextMenu).toHaveBeenCalledWith(lastMenu());
expect(tray().popUpContextMenu).not.toHaveBeenCalled();
expect(tray().handlers.has('right-click')).toBe(false);
});

it('refreshes the right-click menu with the latest status', () => {
it('refreshes the context menu with the latest status on update', () => {
const callbacks = createCallbacks();
let connectedClientCount = 0;
createSwitchifyTray({
const switchifyTray = createSwitchifyTray({
...callbacks,
getStatus: () => status({ connectedClientCount })
});

connectedClientCount = 1;
tray().emit('right-click');
switchifyTray.update();

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

it('refreshes the tooltip on update', () => {
Expand Down
12 changes: 1 addition & 11 deletions src/main/tray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,10 @@ export function createSwitchifyTray(options: SwitchifyTrayOptions): SwitchifyTra
const status = options.getStatus();
currentMenu = buildTrayMenu(options, status);
tray.setToolTip(`Switchify PC - ${formatTooltipStatus(status)}`);
if (process.platform !== 'win32') {
tray.setContextMenu(currentMenu);
}
tray.setContextMenu(currentMenu);
};

tray.on('click', options.showWindow);
if (process.platform === 'win32') {
tray.on('right-click', () => {
update();
if (currentMenu) {
tray.popUpContextMenu(currentMenu);
}
});
}
update();

return {
Expand Down