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
5 changes: 0 additions & 5 deletions src/main/handlers/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { EVENTS } from '../../shared/events';

import { Paths } from '../config';
import { handleMainEvent, onMainEvent } from '../events';
import { setKeepRunningInTray } from '../lifecycle/window';

/**
* Register IPC handlers for general application queries and window/app control.
Expand All @@ -21,10 +20,6 @@ export function registerAppHandlers(mb: Menubar): void {

onMainEvent(EVENTS.QUIT, () => mb.app.quit());

onMainEvent(EVENTS.UPDATE_KEEP_RUNNING_IN_TRAY, (_, value: boolean) => {
setKeepRunningInTray(value);
});

// Path handlers for renderer queries about resource locations
handleMainEvent(EVENTS.NOTIFICATION_SOUND_PATH, () => {
return Paths.notificationSound;
Expand Down
39 changes: 6 additions & 33 deletions src/main/lifecycle/window.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { Menubar } from 'menubar';
import {
__resetWindowLifecycleForTests,
configureWindowEvents,
setKeepRunningInTray,
} from './window';

const appOnMock = vi.fn();
Expand Down Expand Up @@ -57,7 +56,6 @@ describe('main/lifecycle/window.ts', () => {
appOnMock.mockClear();
appQuitMock.mockClear();
__resetWindowLifecycleForTests();
setKeepRunningInTray(false);
setPlatform('linux');

menubar = {
Expand Down Expand Up @@ -128,9 +126,8 @@ describe('main/lifecycle/window.ts', () => {
});

describe('window close handler', () => {
it('hides the window and restores menubar reference when keepRunningInTray is enabled', async () => {
it('hides the window and restores menubar reference on a WM close', async () => {
configureWindowEvents(menubar);
setKeepRunningInTray(true);

const closeHandler = findWindowHandler(menubar, 'close');
const event = { preventDefault: vi.fn() };
Expand All @@ -153,7 +150,6 @@ describe('main/lifecycle/window.ts', () => {

it('skips the deferred hide when the captured window is destroyed', async () => {
configureWindowEvents(menubar);
setKeepRunningInTray(true);

const captured = menubar.window;
const closeHandler = findWindowHandler(menubar, 'close');
Expand All @@ -166,23 +162,9 @@ describe('main/lifecycle/window.ts', () => {
expect(captured?.hide).not.toHaveBeenCalled();
});

it('lets the window close normally when keepRunningInTray is disabled', async () => {
it('lets the window close during quit', async () => {
configureWindowEvents(menubar);

const closeHandler = findWindowHandler(menubar, 'close');
const event = { preventDefault: vi.fn() };
closeHandler?.(event);

await flushDeferred();

expect(event.preventDefault).not.toHaveBeenCalled();
expect(menubar.window?.hide).not.toHaveBeenCalled();
});

it('lets the window close during quit even when keepRunningInTray is enabled', async () => {
configureWindowEvents(menubar);
setKeepRunningInTray(true);

findAppHandler('before-quit')?.();

const closeHandler = findWindowHandler(menubar, 'close');
Expand All @@ -197,37 +179,28 @@ describe('main/lifecycle/window.ts', () => {
});

describe('window-all-closed handler', () => {
it('keeps the app alive when keepRunningInTray is enabled', () => {
it('keeps the app alive when not quitting', () => {
configureWindowEvents(menubar);
setKeepRunningInTray(true);

findAppHandler('window-all-closed')?.();

expect(appQuitMock).not.toHaveBeenCalled();
});

it('quits when keepRunningInTray is disabled (linux)', () => {
configureWindowEvents(menubar);

findAppHandler('window-all-closed')?.();

expect(appQuitMock).toHaveBeenCalled();
});

it('quits when the user is quitting even if keepRunningInTray is enabled', () => {
it('quits on linux when the user is quitting', () => {
configureWindowEvents(menubar);
setKeepRunningInTray(true);

findAppHandler('before-quit')?.();
findAppHandler('window-all-closed')?.();

expect(appQuitMock).toHaveBeenCalled();
});

it('does not quit on macOS when keepRunningInTray is disabled', () => {
it('does not quit on macOS', () => {
setPlatform('darwin');
configureWindowEvents(menubar);

findAppHandler('before-quit')?.();
findAppHandler('window-all-closed')?.();

expect(appQuitMock).not.toHaveBeenCalled();
Expand Down
16 changes: 2 additions & 14 deletions src/main/lifecycle/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,8 @@ import { isMacOS } from '../../shared/platform';

import { WindowConfig } from '../config';

let keepRunningInTray = false;
let isQuitting = false;

/**
* Update the "keep running in tray" preference. When `true`, an OS / window
* manager close request hides the window instead of quitting the app.
*
* @param value - `true` to hide on window close, `false` to quit.
*/
export function setKeepRunningInTray(value: boolean): void {
keepRunningInTray = value;
}

/**
* Reset module-level lifecycle flags. Module-level state is unavoidable
* because `app.on(...)` listeners are registered once at startup; this
Expand All @@ -27,7 +16,6 @@ export function setKeepRunningInTray(value: boolean): void {
* @internal
*/
export function __resetWindowLifecycleForTests(): void {
keepRunningInTray = false;
isQuitting = false;
}

Expand Down Expand Up @@ -94,7 +82,7 @@ export function configureWindowEvents(mb: Menubar): void {
* first.
*/
win.on('close', (event) => {
if (!keepRunningInTray || isQuitting) {
if (isQuitting) {
return;
}

Expand All @@ -117,7 +105,7 @@ export function configureWindowEvents(mb: Menubar): void {
* the next tray click.
*/
app.on('window-all-closed', () => {
if (keepRunningInTray && !isQuitting) {
if (!isQuitting) {
return;
}
if (!isMacOS()) {
Expand Down
9 changes: 0 additions & 9 deletions src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,6 @@ export const api = {
openAsHidden: value,
}),

/**
* Enable or disable hiding the application window to the tray when the
* window receives a close request (e.g. from the OS / window manager).
*
* @param value - `true` to hide on close, `false` to quit on close.
*/
setKeepRunningInTray: (value: boolean) =>
sendMainEvent(EVENTS.UPDATE_KEEP_RUNNING_IN_TRAY, value),

/**
* Apply the global keyboard shortcut for toggling the app window visibility.
*
Expand Down
1 change: 0 additions & 1 deletion src/renderer/__helpers__/vitest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ window.gitify = {
onAuthCallback: vi.fn(),
onResetApp: vi.fn(),
setAutoLaunch: vi.fn(),
setKeepRunningInTray: vi.fn(),
applyKeyboardShortcut: vi.fn().mockResolvedValue({ success: true }),
raiseNativeNotification: vi.fn(),
};
Expand Down
1 change: 0 additions & 1 deletion src/renderer/__mocks__/state-mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ const mockSystemSettings: SystemSettingsState = {
playSound: true,
notificationVolume: 20 as Percentage,
openAtStartup: false,
keepRunningInTray: false,
};

export const mockSettings: SettingsState = {
Expand Down
22 changes: 0 additions & 22 deletions src/renderer/components/settings/SystemSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -372,28 +372,6 @@ export const SystemSettings: FC = () => {
}
visible={!window.gitify.platform.isLinux()}
/>

<Checkbox
checked={settings.keepRunningInTray}
label="Close to tray"
name="keepRunningInTray"
onChange={() =>
updateSetting('keepRunningInTray', !settings.keepRunningInTray)
}
tooltip={
<Stack direction="vertical" gap="condensed">
<Text>
Hide {APPLICATION.NAME} to the system tray when the window is
closed by the operating system or window manager, instead of
quitting the application.
</Text>
<Text>
Use the tray menu or the Quit shortcut to fully exit{' '}
{APPLICATION.NAME}.
</Text>
</Stack>
}
/>
</Stack>
</fieldset>
);
Expand Down
5 changes: 0 additions & 5 deletions src/renderer/context/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ import {
decryptValue,
encryptValue,
setAutoLaunch,
setKeepRunningInTray,
setUseAlternateIdleIcon,
setUseUnreadActiveIcon,
} from '../utils/system/comms';
Expand Down Expand Up @@ -401,10 +400,6 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
setAutoLaunch(settings.openAtStartup);
}, [settings.openAtStartup]);

useEffect(() => {
setKeepRunningInTray(settings.keepRunningInTray);
}, [settings.keepRunningInTray]);

useEffect(() => {
window.gitify.onResetApp(() => {
clearState();
Expand Down
1 change: 0 additions & 1 deletion src/renderer/context/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const defaultSystemSettings: SystemSettingsState = {
playSound: true,
notificationVolume: 20 as Percentage,
openAtStartup: false,
keepRunningInTray: false,
};

export const defaultSettings: SettingsState = {
Expand Down
61 changes: 6 additions & 55 deletions src/renderer/routes/__snapshots__/Settings.test.tsx.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/renderer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ export interface SystemSettingsState {
playSound: boolean;
notificationVolume: Percentage;
openAtStartup: boolean;
keepRunningInTray: boolean;
}

export interface AuthState {
Expand Down
10 changes: 0 additions & 10 deletions src/renderer/utils/system/comms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,6 @@ export function setAutoLaunch(value: boolean): void {
window.gitify.setAutoLaunch(value);
}

/**
* Enable or disable hiding the application window to the tray when the
* window receives a close request (e.g. from the OS / window manager).
*
* @param value - `true` to hide on close, `false` to quit on close.
*/
export function setKeepRunningInTray(value: boolean): void {
window.gitify.setKeepRunningInTray(value);
}

/**
* Switch the tray icon to an alternate idle icon variant.
*
Expand Down
Loading
Loading