Skip to content

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

TypeScript fluxerfluxerapp

refactor(desktop): remove test-only seams from main modules

Hampus15bc27daddff
diff --git a/fluxer_desktop/src/common/ModulePollPlan.ts b/fluxer_desktop/src/common/ModulePollPlan.ts
index ea76d15cf..af31c7022 100644
--- a/fluxer_desktop/src/common/ModulePollPlan.ts
+++ b/fluxer_desktop/src/common/ModulePollPlan.ts
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
-export const MODULE_POLL_INTERVAL_MS = 90 * 1000;
+const MODULE_POLL_INTERVAL_MS = 90 * 1000;
const MODULE_POLL_JITTER_RATIO = 0.15;
export interface ModulePollPlan {
@@ -15,10 +15,10 @@ export function resolveModulePollPlan(devIntervalMs: number | null): ModulePollP
return {intervalMs: MODULE_POLL_INTERVAL_MS, jitterRatio: MODULE_POLL_JITTER_RATIO};
}
-export function nextModulePollDelay(plan: ModulePollPlan, random: () => number = Math.random): number {
+export function nextModulePollDelay(plan: ModulePollPlan): number {
if (plan.jitterRatio <= 0) {
return plan.intervalMs;
}
const spread = plan.intervalMs * plan.jitterRatio;
- return Math.max(1, Math.round(plan.intervalMs - spread + random() * spread * 2));
+ return Math.max(1, Math.round(plan.intervalMs - spread + Math.random() * spread * 2));
}
diff --git a/fluxer_desktop/src/main/AppLoadRetry.ts b/fluxer_desktop/src/main/AppLoadRetry.ts
index 2954c7ad1..745ad5036 100644
--- a/fluxer_desktop/src/main/AppLoadRetry.ts
+++ b/fluxer_desktop/src/main/AppLoadRetry.ts
@@ -1,11 +1,13 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
+import {errorMessage} from '@electron/common/ErrorMessage';
+
const INITIAL_RETRY_DELAY_MS = 1000;
const MAX_RETRY_DELAY_MS = 30000;
const FAILURES_BEFORE_PROMPT = 3;
const ERR_ABORTED = -3;
-export interface AppLoadFailure {
+interface AppLoadFailure {
errorCode: number;
errorDescription: string;
url: string;
@@ -24,8 +26,6 @@ interface AppLoadRetryOptions {
isTrustedUrl: (url: string) => boolean;
onRepeatedFailure: (failure: AppLoadFailure) => void;
onCommitted: () => void;
- setTimer?: (callback: () => void, delayMs: number) => ReturnType<typeof setTimeout>;
- clearTimer?: (timer: ReturnType<typeof setTimeout>) => void;
}
export interface AppLoadRetry {
@@ -38,7 +38,7 @@ function isRetryableLoadError(errorCode: number): boolean {
}
function getLoadErrorCode(error: unknown): number | null {
- const message = error instanceof Error ? error.message : String(error);
+ const message = errorMessage(error);
const match = /\(([-\d]+)\)/.exec(message);
if (!match) return null;
const value = Number.parseInt(match[1], 10);
@@ -47,14 +47,12 @@ function getLoadErrorCode(error: unknown): number | null {
export function createAppLoadRetry(options: AppLoadRetryOptions): AppLoadRetry {
const {webContents, logger} = options;
- const setTimer = options.setTimer ?? setTimeout;
- const clearTimer = options.clearTimer ?? clearTimeout;
const appUrl = options.appUrl;
let attempt = 0;
let timer: ReturnType<typeof setTimeout> | null = null;
const cancelTimer = () => {
if (timer) {
- clearTimer(timer);
+ clearTimeout(timer);
timer = null;
}
};
@@ -74,7 +72,7 @@ export function createAppLoadRetry(options: AppLoadRetryOptions): AppLoadRetry {
const delay = Math.min(INITIAL_RETRY_DELAY_MS * 2 ** attempt, MAX_RETRY_DELAY_MS);
attempt += 1;
logger.warn('Scheduling app load retry', {reason, delay, attempt, ...detail});
- timer = setTimer(() => {
+ timer = setTimeout(() => {
timer = null;
if (webContents.isDestroyed()) return;
if (webContents.isLoadingMainFrame()) {
diff --git a/fluxer_desktop/src/main/DesktopAppStoreHealth.ts b/fluxer_desktop/src/main/DesktopAppStoreHealth.ts
index 6ca5d6510..14034f8b1 100644
--- a/fluxer_desktop/src/main/DesktopAppStoreHealth.ts
+++ b/fluxer_desktop/src/main/DesktopAppStoreHealth.ts
@@ -3,8 +3,8 @@
import {readFileSync, renameSync, writeFileSync} from 'node:fs';
import path from 'node:path';
-export const DESKTOP_APP_STORE_STATE_FILE_NAME = 'account-store-state-v1.json';
-export const DESKTOP_APP_STORE_STATE_VERSION = 1;
+const DESKTOP_APP_STORE_STATE_FILE_NAME = 'account-store-state-v1.json';
+const DESKTOP_APP_STORE_STATE_VERSION = 1;
export interface DesktopAppStoreState {
readonly version: number;
diff --git a/fluxer_desktop/src/main/DesktopDebugInfo.ts b/fluxer_desktop/src/main/DesktopDebugInfo.ts
index 1c4da4c22..9fd6bcf23 100644
--- a/fluxer_desktop/src/main/DesktopDebugInfo.ts
+++ b/fluxer_desktop/src/main/DesktopDebugInfo.ts
@@ -81,7 +81,7 @@ export function shouldDisableHardwareAccelerationForLaunch(argv: ReadonlyArray<s
return hasFlag(argv, DISABLE_HARDWARE_ACCELERATION_ARGS) || isSafeModeLaunch(argv);
}
-export function resolveEffectiveDesktopTroubleshootingSettings(
+function resolveEffectiveDesktopTroubleshootingSettings(
settings: DesktopTroubleshootingSettings,
argv: ReadonlyArray<string>,
platform: NodeJS.Platform,
diff --git a/fluxer_desktop/src/main/DesktopLastRoute.ts b/fluxer_desktop/src/main/DesktopLastRoute.ts
index 5e494a892..41aaf4321 100644
--- a/fluxer_desktop/src/main/DesktopLastRoute.ts
+++ b/fluxer_desktop/src/main/DesktopLastRoute.ts
@@ -12,7 +12,7 @@ const LEGACY_SESSION_TOKEN_KEY = 'token';
const LEGACY_SESSION_USER_ID_KEY = 'userId';
const LEGACY_LOCATION_STORE_KEY = 'Location';
-export function desktopLastRouteFilePath(userDataPath: string): string {
+function desktopLastRouteFilePath(userDataPath: string): string {
return path.join(userDataPath, LAST_ROUTE_FILE_NAME);
}
diff --git a/fluxer_desktop/src/main/DesktopUpdatePoll.ts b/fluxer_desktop/src/main/DesktopUpdatePoll.ts
index c120056c9..847fa2647 100644
--- a/fluxer_desktop/src/main/DesktopUpdatePoll.ts
+++ b/fluxer_desktop/src/main/DesktopUpdatePoll.ts
@@ -15,9 +15,6 @@ interface DesktopUpdatePollOptions {
readonly plan: ModulePollPlan;
readonly check: () => Promise<DesktopUpdateState>;
readonly logger: DesktopUpdatePollLogger;
- readonly random?: () => number;
- readonly setTimer?: (callback: () => void, delayMs: number) => unknown;
- readonly clearTimer?: (timer: unknown) => void;
}
function setUnrefTimer(callback: () => void, delayMs: number): NodeJS.Timeout {
@@ -26,21 +23,15 @@ function setUnrefTimer(callback: () => void, delayMs: number): NodeJS.Timeout {
return timer;
}
-export class DesktopUpdatePoll {
+class DesktopUpdatePoll {
private readonly options: DesktopUpdatePollOptions;
- private readonly random: () => number;
- private readonly setTimer: (callback: () => void, delayMs: number) => unknown;
- private readonly clearTimer: (timer: unknown) => void;
- private timer: unknown = null;
+ private timer: NodeJS.Timeout | null = null;
private inFlight = false;
private failures = 0;
private available = false;
public constructor(options: DesktopUpdatePollOptions) {
this.options = options;
- this.random = options.random ?? Math.random;
- this.setTimer = options.setTimer ?? setUnrefTimer;
- this.clearTimer = options.clearTimer ?? ((timer) => clearTimeout(timer as NodeJS.Timeout));
}
public start(immediately: boolean): void {
@@ -60,7 +51,7 @@ export class DesktopUpdatePoll {
}
private nextDelay(): number {
- const delay = nextModulePollDelay(this.options.plan, this.random);
+ const delay = nextModulePollDelay(this.options.plan);
if (this.failures === 0) {
return delay;
}
@@ -70,13 +61,13 @@ export class DesktopUpdatePoll {
this.options.plan.intervalMs,
DESKTOP_UPDATE_POLL_BACKOFF_CAP_MS,
this.failures,
- this.random,
+ Math.random,
),
);
}
private schedule(): void {
- this.timer = this.setTimer(() => {
+ this.timer = setUnrefTimer(() => {
this.timer = null;
this.tick();
}, this.nextDelay());
@@ -87,7 +78,7 @@ export class DesktopUpdatePoll {
return;
}
if (this.timer != null) {
- this.clearTimer(this.timer);
+ clearTimeout(this.timer);
this.timer = null;
}
this.inFlight = true;
diff --git a/fluxer_desktop/src/main/LocalAppURL.ts b/fluxer_desktop/src/main/LocalAppURL.ts
index 06e9c098b..d9508a5a4 100644
--- a/fluxer_desktop/src/main/LocalAppURL.ts
+++ b/fluxer_desktop/src/main/LocalAppURL.ts
@@ -33,7 +33,7 @@ export function isLocalAppURL(value: string | null): boolean {
return parseLocalAppURL(value) != null;
}
-export function isReservedLocalAppProxyPath(pathname: string): boolean {
+function isReservedLocalAppProxyPath(pathname: string): boolean {
if (pathname === LOCAL_APP_API_PATH_PREFIX || pathname.startsWith(`${LOCAL_APP_API_PATH_PREFIX}/`)) {
return true;
}
diff --git a/fluxer_desktop/src/main/LocalNetworkSplashHint.ts b/fluxer_desktop/src/main/LocalNetworkSplashHint.ts
index a008d5701..a8e9cb986 100644
--- a/fluxer_desktop/src/main/LocalNetworkSplashHint.ts
+++ b/fluxer_desktop/src/main/LocalNetworkSplashHint.ts
@@ -8,29 +8,20 @@ interface LocalNetworkSplashHintDependencies {
readonly apiBaseUrl: string;
readonly platform: NodeJS.Platform;
readonly onHint: () => void;
- readonly delayMs?: number;
- readonly schedule?: (callback: () => void, delayMs: number) => NodeJS.Timeout;
- readonly cancel?: (timer: NodeJS.Timeout) => void;
}
-export function shouldWatchForLocalNetworkPrompt(apiBaseUrl: string, platform: NodeJS.Platform): boolean {
+function shouldWatchForLocalNetworkPrompt(apiBaseUrl: string, platform: NodeJS.Platform): boolean {
return platform === 'darwin' && isLocalNetworkUrl(apiBaseUrl);
}
export class LocalNetworkSplashHint {
private readonly enabled: boolean;
private readonly onHint: () => void;
- private readonly delayMs: number;
- private readonly schedule: (callback: () => void, delayMs: number) => NodeJS.Timeout;
- private readonly cancel: (timer: NodeJS.Timeout) => void;
private timer: NodeJS.Timeout | null = null;
public constructor(dependencies: LocalNetworkSplashHintDependencies) {
this.enabled = shouldWatchForLocalNetworkPrompt(dependencies.apiBaseUrl, dependencies.platform);
this.onHint = dependencies.onHint;
- this.delayMs = dependencies.delayMs ?? LOCAL_NETWORK_HINT_DELAY_MS;
- this.schedule = dependencies.schedule ?? ((callback, delayMs) => setTimeout(callback, delayMs));
- this.cancel = dependencies.cancel ?? ((timer) => clearTimeout(timer));
}
public armWhileChecking(checking: boolean): void {
@@ -41,18 +32,18 @@ export class LocalNetworkSplashHint {
if (this.timer != null) {
return;
}
- this.timer = this.schedule(() => {
+ this.timer = setTimeout(() => {
this.timer = null;
this.onHint();
- }, this.delayMs);
- this.timer.unref?.();
+ }, LOCAL_NETWORK_HINT_DELAY_MS);
+ this.timer.unref();
}
public disarm(): void {
if (this.timer == null) {
return;
}
- this.cancel(this.timer);
+ clearTimeout(this.timer);
this.timer = null;
}
}
diff --git a/fluxer_desktop/src/main/MainWindowReveal.ts b/fluxer_desktop/src/main/MainWindowReveal.ts
index a8a12dedf..906d78a49 100644
--- a/fluxer_desktop/src/main/MainWindowReveal.ts
+++ b/fluxer_desktop/src/main/MainWindowReveal.ts
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
-export const MAIN_WINDOW_CONTENT_GRACE_MS = 6000;
-export const MAIN_WINDOW_HARD_FALLBACK_MS = 10000;
+const MAIN_WINDOW_CONTENT_GRACE_MS = 6000;
+const MAIN_WINDOW_HARD_FALLBACK_MS = 10000;
export const MainWindowRevealReason = Object.freeze({
CONTENT_PAINTED: 'content-painted',
@@ -15,28 +15,16 @@ type RevealTimer = ReturnType<typeof setTimeout>;
interface MainWindowRevealGateOptions {
readonly onReveal: (reason: MainWindowRevealReason) => void;
- readonly contentGraceMs?: number;
- readonly hardFallbackMs?: number;
- readonly setTimer?: (callback: () => void, delayMs: number) => RevealTimer;
- readonly clearTimer?: (timer: RevealTimer) => void;
}
export class MainWindowRevealGate {
private readonly onReveal: (reason: MainWindowRevealReason) => void;
- private readonly contentGraceMs: number;
- private readonly hardFallbackMs: number;
- private readonly setTimer: (callback: () => void, delayMs: number) => RevealTimer;
- private readonly clearTimer: (timer: RevealTimer) => void;
private graceTimer: RevealTimer | null = null;
private hardTimer: RevealTimer | null = null;
private settled = false;
public constructor(options: MainWindowRevealGateOptions) {
this.onReveal = options.onReveal;
- this.contentGraceMs = options.contentGraceMs ?? MAIN_WINDOW_CONTENT_GRACE_MS;
- this.hardFallbackMs = options.hardFallbackMs ?? MAIN_WINDOW_HARD_FALLBACK_MS;
- this.setTimer = options.setTimer ?? setTimeout;
- this.clearTimer = options.clearTimer ?? clearTimeout;
}
public get revealed(): boolean {
@@ -45,18 +33,18 @@ export class MainWindowRevealGate {
public start(): void {
if (this.settled || this.hardTimer != null) return;
- this.hardTimer = this.setTimer(() => {
+ this.hardTimer = setTimeout(() => {
this.hardTimer = null;
this.reveal(MainWindowRevealReason.HARD_FALLBACK);
- }, this.hardFallbackMs);
+ }, MAIN_WINDOW_HARD_FALLBACK_MS);
}
public markReadyToShow(): void {
if (this.settled || this.graceTimer != null) return;
- this.graceTimer = this.setTimer(() => {
+ this.graceTimer = setTimeout(() => {
this.graceTimer = null;
this.reveal(MainWindowRevealReason.CONTENT_GRACE_EXPIRED);
- }, this.contentGraceMs);
+ }, MAIN_WINDOW_CONTENT_GRACE_MS);
}
public markContentPainted(): void {
@@ -77,11 +65,11 @@ export class MainWindowRevealGate {
private cancelTimers(): void {
if (this.graceTimer != null) {
- this.clearTimer(this.graceTimer);
+ clearTimeout(this.graceTimer);
this.graceTimer = null;
}
if (this.hardTimer != null) {
- this.clearTimer(this.hardTimer);
+ clearTimeout(this.hardTimer);
this.hardTimer = null;
}
}
diff --git a/fluxer_desktop/src/main/ModuleOnDemand.ts b/fluxer_desktop/src/main/ModuleOnDemand.ts
index 832e98b2d..1bf6ae2d5 100644
--- a/fluxer_desktop/src/main/ModuleOnDemand.ts
+++ b/fluxer_desktop/src/main/ModuleOnDemand.ts
@@ -8,7 +8,7 @@ import {DesktopModuleEnsureStatus, isDesktopModuleName} from '@fluxer/desktop_ip
const logger = createChildLogger('ModuleOnDemand');
const ON_DEMAND_MODULE_DISTINCT_INSTALLS_MAX = 8;
-export class UnknownDesktopModuleRequestError extends Error {
+class UnknownDesktopModuleRequestError extends Error {
public constructor() {
super('The renderer requested a module with an unusable name');
this.name = 'UnknownDesktopModuleRequestError';
diff --git a/fluxer_desktop/src/main/NativeProbeCache.ts b/fluxer_desktop/src/main/NativeProbeCache.ts
index 674c918b3..071fd708e 100644
--- a/fluxer_desktop/src/main/NativeProbeCache.ts
+++ b/fluxer_desktop/src/main/NativeProbeCache.ts
@@ -2,8 +2,8 @@
import path from 'node:path';
-export const NATIVE_PROBE_CACHE_ENV = 'FLUXER_NATIVE_PROBE_CACHE_FILE';
-export const NATIVE_PROBE_CACHE_FILENAME = 'native-module-probes-v1.json';
+const NATIVE_PROBE_CACHE_ENV = 'FLUXER_NATIVE_PROBE_CACHE_FILE';
+const NATIVE_PROBE_CACHE_FILENAME = 'native-module-probes-v1.json';
export function armNativeProbeCache(userDataPath: string, env: NodeJS.ProcessEnv = process.env): void {
if (env[NATIVE_PROBE_CACHE_ENV]) {
diff --git a/fluxer_desktop/src/main/ShellDownloadFormats.ts b/fluxer_desktop/src/main/ShellDownloadFormats.ts
index bc9e169f0..b4ab99703 100644
--- a/fluxer_desktop/src/main/ShellDownloadFormats.ts
+++ b/fluxer_desktop/src/main/ShellDownloadFormats.ts
@@ -2,13 +2,13 @@
import {BUILD_CHANNEL, type BuildChannel} from '@electron/common/BuildChannel';
-export type DesktopDownloadArch = 'x64' | 'arm64';
+type DesktopDownloadArch = 'x64' | 'arm64';
-export function getDesktopDownloadArch(arch: NodeJS.Architecture): DesktopDownloadArch {
+function getDesktopDownloadArch(arch: NodeJS.Architecture): DesktopDownloadArch {
return arch === 'arm64' ? 'arm64' : 'x64';
}
-export const DESKTOP_DOWNLOAD_ARCH = getDesktopDownloadArch(process.arch);
+const DESKTOP_DOWNLOAD_ARCH = getDesktopDownloadArch(process.arch);
const PACKAGE_ORIGIN_ENV = 'FLUXER_DESKTOP_PACKAGE_ORIGIN';
const CHANNEL_PACKAGE_ORIGINS: Record<BuildChannel, string> = {
stable: 'https://pkgs.fluxer.com',
diff --git a/fluxer_desktop/src/main/ShellSelfUpdate.ts b/fluxer_desktop/src/main/ShellSelfUpdate.ts
index f9bcc5e99..3e59ef4a2 100644
--- a/fluxer_desktop/src/main/ShellSelfUpdate.ts
+++ b/fluxer_desktop/src/main/ShellSelfUpdate.ts
@@ -25,10 +25,10 @@ import type {UpdateInfo, VelopackAsset} from 'velopack';
const requireModule = createRequire(import.meta.url);
const logger = createChildLogger('ShellSelfUpdate');
-export const SHELL_SELF_UPDATE_CHECK_TIMEOUT_MS = 30_000;
-export const SHELL_SELF_UPDATE_TOTAL_TIMEOUT_MS = 600_000;
+const SHELL_SELF_UPDATE_CHECK_TIMEOUT_MS = 30_000;
+const SHELL_SELF_UPDATE_TOTAL_TIMEOUT_MS = 600_000;
-export function getElectronUpdateFeedUrl(): string {
+function getElectronUpdateFeedUrl(): string {
return `${getUpdateBaseUrl()}/RELEASES.json`;
}
@@ -352,12 +352,6 @@ function armElectronUpdateSession(): void {
});
}
-export function resetElectronUpdateSessionForTests(): void {
- electronUpdateSession.phase = ElectronUpdatePhase.IDLE;
- electronUpdateSession.armed = false;
- electronUpdateSession.observers.clear();
-}
-
function runElectronSelfUpdate(control: SelfUpdateControl, hooks: ShellSelfUpdateHooks): void {
armElectronUpdateSession();
const install = (): void => {
diff --git a/fluxer_desktop/src/main/ShellUpdateCapability.ts b/fluxer_desktop/src/main/ShellUpdateCapability.ts
index 6d3e8a526..0158c8c01 100644
--- a/fluxer_desktop/src/main/ShellUpdateCapability.ts
+++ b/fluxer_desktop/src/main/ShellUpdateCapability.ts
@@ -33,7 +33,7 @@ interface ShellUpdateRuntime {
readonly platform: NodeJS.Platform;
}
-export function decideShellUpdatePlan(runtime: ShellUpdateRuntime): ShellUpdatePlan {
+function decideShellUpdatePlan(runtime: ShellUpdateRuntime): ShellUpdatePlan {
if (!runtime.packaged || runtime.channel === 'development') {
return {capability: ShellUpdateCapability.MANUAL_DOWNLOAD, reason: 'unpackaged'};
}
diff --git a/fluxer_desktop/src/main/SplashDiagnostics.ts b/fluxer_desktop/src/main/SplashDiagnostics.ts
index c5431af49..00a7e027e 100644
--- a/fluxer_desktop/src/main/SplashDiagnostics.ts
+++ b/fluxer_desktop/src/main/SplashDiagnostics.ts
@@ -30,7 +30,7 @@ const SECRET_HEADER_PATTERN =
const SECRET_QUERY_PATTERN = /([?&])([^=&#\s]+)=([^&#\s]*)/gu;
const SECRET_USERINFO_PATTERN = /[^\s:@/]+:[^\s@/]+@/gu;
-export function redactDiagnosticText(value: string): string {
+function redactDiagnosticText(value: string): string {
return value
.replace(SECRET_HEADER_PATTERN, (_match, key: string) => `${key}=…`)
.replace(SECRET_QUERY_PATTERN, (_match, separator: string, key: string) => `${separator}${key}=…`)
diff --git a/fluxer_desktop/src/main/SplashWindow.ts b/fluxer_desktop/src/main/SplashWindow.ts
index d37648e37..3c80466f3 100644
--- a/fluxer_desktop/src/main/SplashWindow.ts
+++ b/fluxer_desktop/src/main/SplashWindow.ts
@@ -13,18 +13,18 @@ const SPLASH_ACTION_LABEL_MAX_LENGTH = 48;
const SPLASH_MESSAGE_MAX_LENGTH = 160;
const SPLASH_PROGRESS_MAX = 100;
-export const SPLASH_READY_WATCHDOG_MS = 3000;
-export const SPLASH_CLOSE_DELAY_MS = 100;
-
-export const DESKTOP_SPLASH_STATE_CHANNEL = 'desktop-splash:state';
-export const DESKTOP_SPLASH_REVEALED_CHANNEL = 'desktop-splash:revealed';
-export const DESKTOP_SPLASH_READY_CHANNEL = 'desktop-splash:ready';
-export const DESKTOP_SPLASH_RETRY_NOW_CHANNEL = 'desktop-splash:retry-now';
-export const DESKTOP_SPLASH_QUIT_CHANNEL = 'desktop-splash:quit';
-export const DESKTOP_SPLASH_OPEN_DOWNLOAD_CHANNEL = 'desktop-splash:open-download';
-export const DESKTOP_SPLASH_NETWORK_ONLINE_CHANNEL = 'desktop-splash:network-online';
-export const DESKTOP_SPLASH_OPEN_LOGS_CHANNEL = 'desktop-splash:open-logs';
-export const DESKTOP_SPLASH_COPY_DIAGNOSTICS_CHANNEL = 'desktop-splash:copy-diagnostics';
+const SPLASH_READY_WATCHDOG_MS = 3000;
+const SPLASH_CLOSE_DELAY_MS = 100;
+
+const DESKTOP_SPLASH_STATE_CHANNEL = 'desktop-splash:state';
+const DESKTOP_SPLASH_REVEALED_CHANNEL = 'desktop-splash:revealed';
+const DESKTOP_SPLASH_READY_CHANNEL = 'desktop-splash:ready';
+const DESKTOP_SPLASH_RETRY_NOW_CHANNEL = 'desktop-splash:retry-now';
+const DESKTOP_SPLASH_QUIT_CHANNEL = 'desktop-splash:quit';
+const DESKTOP_SPLASH_OPEN_DOWNLOAD_CHANNEL = 'desktop-splash:open-download';
+const DESKTOP_SPLASH_NETWORK_ONLINE_CHANNEL = 'desktop-splash:network-online';
+const DESKTOP_SPLASH_OPEN_LOGS_CHANNEL = 'desktop-splash:open-logs';
+const DESKTOP_SPLASH_COPY_DIAGNOSTICS_CHANNEL = 'desktop-splash:copy-diagnostics';
export const SplashStatus = Object.freeze({
CHECKING_FOR_UPDATES: 'checking-for-updates',
@@ -46,13 +46,13 @@ export const SplashStatus = Object.freeze({
export type SplashStatus = (typeof SplashStatus)[keyof typeof SplashStatus];
-export const SplashActionKind = Object.freeze({
+const SplashActionKind = Object.freeze({
RETRY: 'retry',
DOWNLOAD: 'download',
QUIT: 'quit',
} as const);
-export type SplashActionKind = (typeof SplashActionKind)[keyof typeof SplashActionKind];
+type SplashActionKind = (typeof SplashActionKind)[keyof typeof SplashActionKind];
export interface SplashActionDescriptor {
readonly kind: SplashActionKind;
@@ -78,7 +78,7 @@ export interface SplashState {
readonly message?: string | null;
}
-export interface SerializedSplashState {
+interface SerializedSplashState {
readonly status: SplashStatus;
readonly current: number | null;
readonly total: number | null;
@@ -140,7 +140,7 @@ function toSplashAction(action: SplashActionDescriptor | null | undefined): Spla
return {kind: action.kind, label};
}
-export function serializeSplashState(state: SplashState): SerializedSplashState {
+function serializeSplashState(state: SplashState): SerializedSplashState {
return {
status: SPLASH_STATUSES.has(state.status) ? state.status : SplashStatus.CHECKING_FOR_UPDATES,
current: toSplashCount(state.current),
@@ -155,18 +155,10 @@ export function serializeSplashState(state: SplashState): SerializedSplashState
};
}
-export function hasSplashAffordance(state: SerializedSplashState): boolean {
+function hasSplashAffordance(state: SerializedSplashState): boolean {
return state.action != null;
}
-export function getSplashWindowHeight(platform: NodeJS.Platform): number {
- return platform === 'darwin' ? SPLASH_WINDOW_HEIGHT_DARWIN : SPLASH_WINDOW_HEIGHT_DEFAULT;
-}
-
-export function shouldQuitOnSplashClosed(platform: NodeJS.Platform, isLaunchLatched: boolean): boolean {
- return platform !== 'darwin' && !isLaunchLatched;
-}
-
function addSplashListener(listeners: Set<SplashListener>, listener: SplashListener): () => void {
listeners.add(listener);
return () => {
@@ -295,7 +287,7 @@ function createSplashWindow(darkThemeOnShow: boolean, heldHidden: boolean): Brow
if (!darkThemeOnShow) applySplashTheme();
const window = new BrowserWindow({
width: SPLASH_WINDOW_WIDTH,
- height: getSplashWindowHeight(process.platform),
+ height: process.platform === 'darwin' ? SPLASH_WINDOW_HEIGHT_DARWIN : SPLASH_WINDOW_HEIGHT_DEFAULT,
frame: false,
hasShadow: true,
resizable: false,
@@ -326,7 +318,9 @@ function createSplashWindow(darkThemeOnShow: boolean, heldHidden: boolean): Brow
splashDocumentReady = false;
}
restoreThemeSource();
- if (!shouldQuitOnSplashClosed(process.platform, launchLatched)) return;
+ if (process.platform === 'darwin' || launchLatched) {
+ return;
+ }
logger.info('The splash window closed before launch, quitting');
app.quit();
});
diff --git a/fluxer_desktop/src/main/TrayIconImage.ts b/fluxer_desktop/src/main/TrayIconImage.ts
index b123b4f6a..ddcbb117a 100644
--- a/fluxer_desktop/src/main/TrayIconImage.ts
+++ b/fluxer_desktop/src/main/TrayIconImage.ts
@@ -74,7 +74,7 @@ function bodyLuminance(bitmap: Buffer): number | null {
return null;
}
-export function paintMonochromeGlyph(bitmap: Buffer, glyphBgr: Bgr): void {
+function paintMonochromeGlyph(bitmap: Buffer, glyphBgr: Bgr): void {
const body = bodyLuminance(bitmap);
let highlight = 0;
for (let offset = 0; offset < bitmap.length; offset += 4) {
@@ -100,7 +100,7 @@ export function paintMonochromeGlyph(bitmap: Buffer, glyphBgr: Bgr): void {
}
}
-export function paintTrayIndicatorDot(bitmap: Buffer, width: number, height: number, dotBgr: Bgr): void {
+function paintTrayIndicatorDot(bitmap: Buffer, width: number, height: number, dotBgr: Bgr): void {
const size = Math.min(width, height);
const radius = size * DOT_RADIUS_RATIO;
const cutRadius = radius + size * DOT_GAP_RATIO;
diff --git a/fluxer_desktop/src/main/UpdateServerRetry.ts b/fluxer_desktop/src/main/UpdateServerRetry.ts
index 6e7458eec..c1ec5206d 100644
--- a/fluxer_desktop/src/main/UpdateServerRetry.ts
+++ b/fluxer_desktop/src/main/UpdateServerRetry.ts
@@ -3,8 +3,8 @@
import {jitteredExponentialDelay} from '@electron/common/ExponentialBackoff';
import {ModuleUpdaterStatus} from '@electron/main/ModuleUpdater';
-export const UPDATE_SERVER_RETRY_BASE_MS = 15_000;
-export const UPDATE_SERVER_RETRY_CAP_MS = 300_000;
+const UPDATE_SERVER_RETRY_BASE_MS = 15_000;
+const UPDATE_SERVER_RETRY_CAP_MS = 300_000;
const QUIET_STATUSES: ReadonlySet<ModuleUpdaterStatus> = new Set([
ModuleUpdaterStatus.CHECKING,
@@ -12,35 +12,20 @@ const QUIET_STATUSES: ReadonlySet<ModuleUpdaterStatus> = new Set([
ModuleUpdaterStatus.BLOCKED_UPDATE_REQUIRED,
]);
-interface UpdateServerRetryDependencies {
- readonly random?: () => number;
- readonly schedule?: (callback: () => void, delayMs: number) => NodeJS.Timeout;
- readonly cancel?: (timer: NodeJS.Timeout) => void;
-}
-
-export function nextUpdateServerRetryDelay(attempt: number, random: () => number = Math.random): number {
+function nextUpdateServerRetryDelay(attempt: number): number {
return jitteredExponentialDelay(
UPDATE_SERVER_RETRY_BASE_MS,
UPDATE_SERVER_RETRY_CAP_MS,
Math.max(0, attempt),
- random,
+ Math.random,
);
}
export class UpdateServerRetry {
- private readonly random: () => number;
- private readonly schedule: (callback: () => void, delayMs: number) => NodeJS.Timeout;
- private readonly cancel: (timer: NodeJS.Timeout) => void;
private readonly wakers = new Set<() => void>();
private attempt = 0;
private held = false;
- public constructor(dependencies: UpdateServerRetryDependencies = {}) {
- this.random = dependencies.random ?? Math.random;
- this.schedule = dependencies.schedule ?? ((callback, delayMs) => setTimeout(callback, delayMs));
- this.cancel = dependencies.cancel ?? ((timer) => clearTimeout(timer));
- }
-
public get holding(): boolean {
return this.held;
}
@@ -48,18 +33,18 @@ export class UpdateServerRetry {
public readonly sleep = (delayMs: number): Promise<void> => {
return new Promise((resolve) => {
const wake = (): void => {
- this.cancel(timer);
+ clearTimeout(timer);
this.wakers.delete(wake);
resolve();
};
- const timer = this.schedule(wake, delayMs);
+ const timer = setTimeout(wake, delayMs);
this.wakers.add(wake);
});
};
public async holdUntilNextAttempt(): Promise<void> {
this.held = true;
- const delayMs = nextUpdateServerRetryDelay(this.attempt, this.random);
+ const delayMs = nextUpdateServerRetryDelay(this.attempt);
this.attempt += 1;
await this.sleep(delayMs);
}
diff --git a/fluxer_desktop/src/main/WindowsBadge.ts b/fluxer_desktop/src/main/WindowsBadge.ts
index f10e3ed08..1a3281d8c 100644
--- a/fluxer_desktop/src/main/WindowsBadge.ts
+++ b/fluxer_desktop/src/main/WindowsBadge.ts
@@ -28,7 +28,7 @@ function isSupported(): boolean {
return process.platform === 'win32';
}
-export function readIconPngFrames(data: Buffer): BadgeFrames {
+function readIconPngFrames(data: Buffer): BadgeFrames {
const frames = new Map<number, Buffer>();
if (data.length < ICON_HEADER_BYTES || data.readUInt16LE(2) !== 1) return frames;
const count = data.readUInt16LE(4);
@@ -46,7 +46,7 @@ export function readIconPngFrames(data: Buffer): BadgeFrames {
return frames;
}
-export function pickBadgeFrameSize(sizes: Iterable<number>, scaleFactor: number): number | null {
+function pickBadgeFrameSize(sizes: Iterable<number>, scaleFactor: number): number | null {
const target = Math.round(OVERLAY_BASE_SIZE * scaleFactor);
const sorted = [...sizes].sort((left, right) => left - right);
return sorted.find((size) => size >= target) ?? sorted.at(-1) ?? null;