Skip to content

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

TypeScript fluxerfluxerapp

refactor(desktop): replace nested ternaries with if blocks

Hampusb0d6f41ee5c0
diff --git a/fluxer_desktop/electron-builder.config.cjs b/fluxer_desktop/electron-builder.config.cjs
index 648adfe1b..4c3990d16 100644
--- a/fluxer_desktop/electron-builder.config.cjs
+++ b/fluxer_desktop/electron-builder.config.cjs
@@ -67,13 +67,16 @@ const platformArguments = new Set(process.argv.map((argument) => argument.split(
const linuxRequested = ['--linux', '-l'].some((selector) => platformArguments.has(selector));
const macRequested = ['--mac', '--macos', '-m', '-o'].some((selector) => platformArguments.has(selector));
const windowsRequested = ['--win', '--windows', '-w'].some((selector) => platformArguments.has(selector));
-const targetPlatform = linuxRequested
- ? 'linux'
- : macRequested
- ? 'darwin'
- : windowsRequested
- ? 'win32'
- : process.platform;
+let targetPlatform;
+if (linuxRequested) {
+ targetPlatform = 'linux';
+} else if (macRequested) {
+ targetPlatform = 'darwin';
+} else if (windowsRequested) {
+ targetPlatform = 'win32';
+} else {
+ targetPlatform = process.platform;
+}
const isLinuxBuild = targetPlatform === 'linux';
const customLinuxElectron =
isLinuxBuild && process.env.FLUXER_ELECTRON_DIST?.trim() ? require('./scripts/custom-electron.cjs') : null;
@@ -821,7 +824,14 @@ async function beforePack(context) {
'Linux packaging requires patched Electron. Set FLUXER_ELECTRON_DIST to the directory containing its ZIP and build manifest.',
);
}
- const arch = context.arch === 1 ? 'x64' : context.arch === 3 ? 'arm64' : context.arch;
+ let arch;
+ if (context.arch === 1) {
+ arch = 'x64';
+ } else if (context.arch === 3) {
+ arch = 'arm64';
+ } else {
+ arch = context.arch;
+ }
verifiedLinuxElectronArtifacts.set(
arch,
await customLinuxElectron.verifyLinuxElectronArchive(linuxElectronDist, arch),
@@ -1531,13 +1541,14 @@ async function verifyRpmArtifactsSweepTheRenamedInstallDirectory(buildResult) {
const violations = [];
for (const artifactPath of rpmArtifacts) {
const scriptlet = await readRpmPostTransactionScriptlet(artifactPath);
- const detail = !scriptlet.includes(legacyLinuxCanaryOptDir)
- ? `does not reference ${legacyLinuxCanaryOptDir}`
- : !scriptlet.includes('rmdir')
- ? 'does not sweep the directory with rmdir'
- : /\brm\s+-[a-zA-Z]*[rf]/.test(scriptlet)
- ? 'removes files rather than only empty directories'
- : null;
+ let detail = null;
+ if (!scriptlet.includes(legacyLinuxCanaryOptDir)) {
+ detail = `does not reference ${legacyLinuxCanaryOptDir}`;
+ } else if (!scriptlet.includes('rmdir')) {
+ detail = 'does not sweep the directory with rmdir';
+ } else if (/\brm\s+-[a-zA-Z]*[rf]/.test(scriptlet)) {
+ detail = 'removes files rather than only empty directories';
+ }
if (detail !== null) {
violations.push({artifactPath, detail});
}
diff --git a/fluxer_desktop/src/main/Autostart.ts b/fluxer_desktop/src/main/Autostart.ts
index ccda69749..c25d0b7b5 100644
--- a/fluxer_desktop/src/main/Autostart.ts
+++ b/fluxer_desktop/src/main/Autostart.ts
@@ -128,9 +128,17 @@ function getWindowsLoginItemPath(): string {
}
function getAutoLaunchConfig(): AutoLaunchConfig {
+ let launchPath: string;
+ if (isWindows) {
+ launchPath = getWindowsLoginItemPath();
+ } else if (isLinux) {
+ launchPath = getStableLinuxLaunchPath();
+ } else {
+ launchPath = process.execPath;
+ }
return {
name: isWindows ? WINDOWS_APP_USER_MODEL_ID : APP_NAME,
- path: isWindows ? getWindowsLoginItemPath() : isLinux ? getStableLinuxLaunchPath() : process.execPath,
+ path: launchPath,
args: [AUTOSTART_LAUNCH_ARG],
};
}
@@ -596,7 +604,7 @@ function isLegacyGeneratedLinuxAutostartEntry(contents: string, entry: Map<strin
return contents.includes(GENERATED_MARKER) || entry.get('StartupWMClass')?.trim() === LEGACY_LINUX_DESKTOP_ENTRY_ID;
}
-export function rewriteLegacyLinuxAutostartContents(contents: string, execPath: string, execStale: boolean): string {
+function rewriteLegacyLinuxAutostartContents(contents: string, execPath: string, execStale: boolean): string {
const replacements = new Map<string, string>([
['StartupWMClass', LINUX_STARTUP_WM_CLASS],
['Icon', LINUX_ICON_NAME],
diff --git a/fluxer_desktop/src/main/ChromiumRuntime.ts b/fluxer_desktop/src/main/ChromiumRuntime.ts
index 1275a3ddf..a4e90b624 100644
--- a/fluxer_desktop/src/main/ChromiumRuntime.ts
+++ b/fluxer_desktop/src/main/ChromiumRuntime.ts
@@ -250,7 +250,12 @@ export function hasEnabledBlinkFeature(feature: string): boolean {
}
export function appendConfiguredChromiumSwitches(rawSwitches: unknown): void {
- const switches = Array.isArray(rawSwitches) ? rawSwitches : isRecord(rawSwitches) ? Object.keys(rawSwitches) : [];
+ let switches: Array<unknown> = [];
+ if (Array.isArray(rawSwitches)) {
+ switches = rawSwitches;
+ } else if (isRecord(rawSwitches)) {
+ switches = Object.keys(rawSwitches);
+ }
for (const chromiumSwitch of switches) {
if (typeof chromiumSwitch !== 'string') continue;
if (!CONFIGURED_CHROMIUM_SWITCH_ALLOWLIST.has(chromiumSwitch)) continue;
diff --git a/fluxer_desktop/src/main/LinuxAppearance.ts b/fluxer_desktop/src/main/LinuxAppearance.ts
index a7cdf7c57..f6e2913df 100644
--- a/fluxer_desktop/src/main/LinuxAppearance.ts
+++ b/fluxer_desktop/src/main/LinuxAppearance.ts
@@ -61,16 +61,22 @@ export function subscribeLinuxAppearance(listener: LinuxAppearanceListener): Lin
contrast: mod.readContrast(),
accent: mod.readAccentColor(),
};
- if (event.namespace === 'org.freedesktop.appearance') {
- if (event.key === 'color-scheme' && event.uint32 != null) {
- snapshot.colorScheme =
- event.uint32 === 1 ? 'prefer-dark' : event.uint32 === 2 ? 'prefer-light' : 'no-preference';
- } else if (event.key === 'contrast' && event.uint32 != null) {
- snapshot.contrast = event.uint32 === 1 ? 'high' : 'no-preference';
- } else if (event.key === 'accent-color') {
- snapshot.accent =
- event.accent && event.accent.r >= 0 && event.accent.g >= 0 && event.accent.b >= 0 ? event.accent : null;
+ if (event.namespace !== 'org.freedesktop.appearance') {
+ listener(snapshot);
+ return;
+ }
+ if (event.key === 'color-scheme' && event.uint32 != null) {
+ snapshot.colorScheme = 'no-preference';
+ if (event.uint32 === 1) {
+ snapshot.colorScheme = 'prefer-dark';
+ } else if (event.uint32 === 2) {
+ snapshot.colorScheme = 'prefer-light';
}
+ } else if (event.key === 'contrast' && event.uint32 != null) {
+ snapshot.contrast = event.uint32 === 1 ? 'high' : 'no-preference';
+ } else if (event.key === 'accent-color') {
+ snapshot.accent =
+ event.accent && event.accent.r >= 0 && event.accent.g >= 0 && event.accent.b >= 0 ? event.accent : null;
}
listener(snapshot);
});
diff --git a/fluxer_desktop/src/main/LinuxSandbox.ts b/fluxer_desktop/src/main/LinuxSandbox.ts
index a235ca8f0..daa99bf7a 100644
--- a/fluxer_desktop/src/main/LinuxSandbox.ts
+++ b/fluxer_desktop/src/main/LinuxSandbox.ts
@@ -14,7 +14,7 @@ export function isFlatpakRuntime(): boolean {
}
}
-export function parseFlatpakInfoAppId(contents: string): string | null {
+function parseFlatpakInfoAppId(contents: string): string | null {
let inApplication = false;
for (const rawLine of contents.split('\n')) {
const line = rawLine.trim();
diff --git a/fluxer_desktop/src/main/LinuxSession.ts b/fluxer_desktop/src/main/LinuxSession.ts
index ad15c81d8..ad755969e 100644
--- a/fluxer_desktop/src/main/LinuxSession.ts
+++ b/fluxer_desktop/src/main/LinuxSession.ts
@@ -5,24 +5,25 @@ import type {LinuxDesktopKind, LinuxSessionType} from '@electron/common/Types';
type SessionEnv = Readonly<Record<string, string | undefined>>;
-export function detectLinuxSessionType(env: SessionEnv, pathExists: (candidate: string) => boolean): LinuxSessionType {
+function detectLinuxSessionType(env: SessionEnv, pathExists: (candidate: string) => boolean): LinuxSessionType {
const sessionType = (env.XDG_SESSION_TYPE ?? '').trim().toLowerCase();
if (sessionType === 'x11' || sessionType === 'wayland') return sessionType;
const waylandDisplay = (env.WAYLAND_DISPLAY ?? '').trim();
if (waylandDisplay.length > 0) {
const runtimeDir = (env.XDG_RUNTIME_DIR ?? '').trim();
- const socketPath = waylandDisplay.startsWith('/')
- ? waylandDisplay
- : runtimeDir.length > 0
- ? `${runtimeDir.replace(/\/+$/, '')}/${waylandDisplay}`
- : null;
+ let socketPath: string | null = null;
+ if (waylandDisplay.startsWith('/')) {
+ socketPath = waylandDisplay;
+ } else if (runtimeDir.length > 0) {
+ socketPath = `${runtimeDir.replace(/\/+$/, '')}/${waylandDisplay}`;
+ }
if (socketPath !== null && pathExists(socketPath)) return 'wayland';
}
if ((env.DISPLAY ?? '').trim().length > 0) return 'x11';
return 'unknown';
}
-export function detectLinuxDesktop(env: SessionEnv): LinuxDesktopKind {
+function detectLinuxDesktop(env: SessionEnv): LinuxDesktopKind {
const tokens = new Set((env.XDG_CURRENT_DESKTOP ?? '').split(':').map((token) => token.trim().toLowerCase()));
if (tokens.has('kde')) return 'kde';
if (tokens.has('hyprland') || (env.HYPRLAND_INSTANCE_SIGNATURE ?? '').trim().length > 0) return 'hyprland';
diff --git a/fluxer_desktop/src/main/StreamingPriority.ts b/fluxer_desktop/src/main/StreamingPriority.ts
index c3a80d4bc..1df9a9b1b 100644
--- a/fluxer_desktop/src/main/StreamingPriority.ts
+++ b/fluxer_desktop/src/main/StreamingPriority.ts
@@ -130,6 +130,13 @@ function formatErrorDetail(error: unknown): string {
return String(error);
}
+function gpuPriorityResultStatus(succeededCount: number, failedCount: number): GpuPriorityAttemptStatus {
+ if (failedCount === 0) {
+ return 'succeeded';
+ }
+ return succeededCount > 0 ? 'partial' : 'failed';
+}
+
const GPU_PRIORITY_MODULE_UNAVAILABLE_DETAIL = 'Windows GPU priority native API unavailable';
function gpuPriorityModuleUnavailableReason(): string {
@@ -473,7 +480,7 @@ function elevateGpuSchedulingPriority(targets: Array<GpuPriorityTarget>): void {
}
}
lastGpuPriorityAcquire = {
- status: failedProcessIds.length === 0 ? 'succeeded' : elevatedProcessIds.length > 0 ? 'partial' : 'failed',
+ status: gpuPriorityResultStatus(elevatedProcessIds.length, failedProcessIds.length),
priorityClass: GPU_SCHEDULING_PRIORITY,
targets: limitGpuPriorityTargets(targets),
elevatedProcessIds: elevatedProcessIds.slice(0, MAX_GPU_PRIORITY_DIAGNOSTIC_TARGETS),
@@ -555,7 +562,7 @@ function restoreGpuSchedulingPriority(): void {
}
}
lastGpuPriorityRestore = {
- status: failedProcessIds.length === 0 ? 'succeeded' : restoredProcessIds.length > 0 ? 'partial' : 'failed',
+ status: gpuPriorityResultStatus(restoredProcessIds.length, failedProcessIds.length),
processIds,
restoredProcessIds,
failedProcessIds,