mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-06-02 06:14:48 +02:00
refactor(big-picture): simplify global checks and improve conditional logic in various services and components
This commit is contained in:
@@ -294,21 +294,23 @@ function getRegionPath(
|
||||
currentRegionId: string | null | undefined,
|
||||
regions: Array<{ id: string; parentRegionId: string | null }>
|
||||
) {
|
||||
if (!currentRegionId) return [];
|
||||
if (currentRegionId) {
|
||||
const path: string[] = [];
|
||||
let regionId: string | null = currentRegionId;
|
||||
|
||||
const path: string[] = [];
|
||||
let regionId: string | null = currentRegionId;
|
||||
while (regionId) {
|
||||
const region = regions.find((candidate) => candidate.id === regionId);
|
||||
|
||||
while (regionId) {
|
||||
const region = regions.find((candidate) => candidate.id === regionId);
|
||||
if (!region) break;
|
||||
|
||||
if (!region) break;
|
||||
path.unshift(region.id);
|
||||
regionId = region.parentRegionId;
|
||||
}
|
||||
|
||||
path.unshift(region.id);
|
||||
regionId = region.parentRegionId;
|
||||
return path;
|
||||
}
|
||||
|
||||
return path;
|
||||
return [];
|
||||
}
|
||||
|
||||
function getActiveInputLabel(
|
||||
@@ -317,7 +319,7 @@ function getActiveInputLabel(
|
||||
) {
|
||||
return (
|
||||
pressedButtons[0] ??
|
||||
(leftStickDirection !== "none" ? `left-stick.${leftStickDirection}` : null)
|
||||
(leftStickDirection === "none" ? null : `left-stick.${leftStickDirection}`)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export const IS_BROWSER =
|
||||
typeof globalThis.self !== "undefined" &&
|
||||
typeof Window !== "undefined" &&
|
||||
globalThis.self instanceof Window;
|
||||
globalThis.self !== undefined &&
|
||||
globalThis.Window !== undefined &&
|
||||
globalThis.self instanceof globalThis.Window;
|
||||
|
||||
export const IS_DESKTOP = IS_BROWSER && !!globalThis.window.electron;
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import { NavigationItemActionsService } from "../services";
|
||||
import { NavigationScreenActionsService } from "../services";
|
||||
import {
|
||||
NavigationItemActionsService,
|
||||
NavigationScreenActionsService,
|
||||
NavigationService,
|
||||
type FocusDirection,
|
||||
} from "../services";
|
||||
import type {
|
||||
FocusItemHoldButton,
|
||||
FocusItemPressButton,
|
||||
NavigationActionButton,
|
||||
} from "../types";
|
||||
import type { FocusDirection } from "../services";
|
||||
import { NavigationService } from "../services";
|
||||
import { useNavigationSnapshot } from "../stores";
|
||||
import { useCallback } from "react";
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ export class GamepadService {
|
||||
}
|
||||
|
||||
private isWindowAvailable() {
|
||||
return typeof globalThis.window !== "undefined";
|
||||
return globalThis.window !== undefined;
|
||||
}
|
||||
|
||||
private setupListeners() {
|
||||
|
||||
@@ -609,7 +609,7 @@ export class NavigationService {
|
||||
while (currentRegionId) {
|
||||
const currentRegion = this.regions.get(currentRegionId);
|
||||
|
||||
if (!currentRegion || currentRegion.layerId !== this.getActiveLayerId()) {
|
||||
if (currentRegion?.layerId !== this.getActiveLayerId()) {
|
||||
break;
|
||||
}
|
||||
const regionOverride = currentRegion.navigationOverrides?.[direction];
|
||||
@@ -943,7 +943,7 @@ export class NavigationService {
|
||||
while (currentRegionId) {
|
||||
const region = this.regions.get(currentRegionId);
|
||||
|
||||
if (!region || region.layerId !== this.getActiveLayerId()) {
|
||||
if (region?.layerId !== this.getActiveLayerId()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1010,7 +1010,7 @@ export class NavigationService {
|
||||
while (currentRegionId) {
|
||||
const currentRegion = this.regions.get(currentRegionId);
|
||||
|
||||
if (!currentRegion || currentRegion.layerId !== this.getActiveLayerId()) {
|
||||
if (currentRegion?.layerId !== this.getActiveLayerId()) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1282,7 +1282,7 @@ export class NavigationService {
|
||||
): string | null {
|
||||
const region = this.regions.get(regionId);
|
||||
|
||||
if (!region || region.layerId !== this.getActiveLayerId()) {
|
||||
if (region?.layerId !== this.getActiveLayerId()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ export class WindowManager {
|
||||
public static mainWindow: Electron.BrowserWindow | null = null;
|
||||
public static notificationWindow: Electron.BrowserWindow | null = null;
|
||||
public static gameLauncherWindow: Electron.BrowserWindow | null = null;
|
||||
public static bigPicture: Electron.BrowserWindow | null = null;
|
||||
private static bigPicture: Electron.BrowserWindow | null = null;
|
||||
|
||||
private static readonly editorWindows: Map<string, BrowserWindow> = new Map();
|
||||
|
||||
|
||||
@@ -537,7 +537,7 @@ export function Sidebar() {
|
||||
}, [collections, favoritesCount, t]);
|
||||
|
||||
const handleOpenBigPictureWindow = () => {
|
||||
window.electron.openBigPictureWindow();
|
||||
globalThis.window.electron.openBigPictureWindow();
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user