Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

fix(app): guard the idle check outside Electron (#3548)

Hampusf45617cf58d3
diff --git a/fluxer_app/src/features/ui/state/Idle.ts b/fluxer_app/src/features/ui/state/Idle.ts
index a054ae6e9..d6eff71f2 100644
--- a/fluxer_app/src/features/ui/state/Idle.ts
+++ b/fluxer_app/src/features/ui/state/Idle.ts
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import {IS_DEV} from '@app/features/platform/types/Env';
+import {isElectron} from '@app/features/ui/utils/ElectronRuntime';
import {makeAutoObservable} from 'mobx';
const IDLE_DURATION_MS = 1000 * (IS_DEV ? 10 : 60 * 10);
@@ -12,6 +13,7 @@ interface DesktopIdleApi {
}
function getDesktopIdleApi(): Required<DesktopIdleApi> | null {
+ if (!isElectron()) return null;
const electronApi = (
window as {
electron?: DesktopIdleApi | null;
diff --git a/fluxer_app/src/features/ui/state/IdleWithoutWindow.test.ts b/fluxer_app/src/features/ui/state/IdleWithoutWindow.test.ts
new file mode 100644
index 000000000..495bb778b
--- /dev/null
+++ b/fluxer_app/src/features/ui/state/IdleWithoutWindow.test.ts
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import {afterEach, expect, it, vi} from 'vitest';
+
+afterEach(async () => {
+ const {default: Idle} = await import('@app/features/ui/state/Idle');
+ Idle.destroy();
+ vi.useRealTimers();
+});
+
+it('checks idle state on its timer when there is no window', async () => {
+ vi.useFakeTimers();
+ const {default: Idle} = await import('@app/features/ui/state/Idle');
+ expect(typeof window).toBe('undefined');
+
+ await vi.advanceTimersByTimeAsync(11 * 60 * 1000);
+
+ expect(Idle.isIdle()).toBe(true);
+});