chore: Apply linting rules and add git hok (#611)

Co-authored-by: Fredrik Burmester <fredrik.burmester@gmail.com>
This commit is contained in:
lostb1t
2025-03-16 18:01:12 +01:00
committed by GitHub
parent 2688e1b981
commit 92513e234f
268 changed files with 9197 additions and 8394 deletions

View File

@@ -93,7 +93,7 @@ export const sortByPreferenceAtom = atomWithStorage<SortPreference>(
removeItem: (key) => {
storage.delete(key);
},
}
},
);
export const sortOrderPreferenceAtom = atomWithStorage<SortOrderPreference>(
@@ -110,19 +110,19 @@ export const sortOrderPreferenceAtom = atomWithStorage<SortOrderPreference>(
removeItem: (key) => {
storage.delete(key);
},
}
},
);
export const getSortByPreference = (
libraryId: string,
preferences: SortPreference
preferences: SortPreference,
) => {
return preferences?.[libraryId] || null;
};
export const getSortOrderPreference = (
libraryId: string,
preferences: SortOrderPreference
preferences: SortOrderPreference,
) => {
return preferences?.[libraryId] || null;
};

View File

@@ -2,5 +2,5 @@ import * as ScreenOrientation from "@/packages/expo-screen-orientation";
import { atom } from "jotai";
export const orientationAtom = atom<number>(
ScreenOrientation.OrientationLock.PORTRAIT_UP
ScreenOrientation.OrientationLock.PORTRAIT_UP,
);

View File

@@ -7,9 +7,9 @@ interface ThemeColors {
export const calculateTextColor = (backgroundColor: string): string => {
// Convert hex to RGB
const r = parseInt(backgroundColor.slice(1, 3), 16);
const g = parseInt(backgroundColor.slice(3, 5), 16);
const b = parseInt(backgroundColor.slice(5, 7), 16);
const r = Number.parseInt(backgroundColor.slice(1, 3), 16);
const g = Number.parseInt(backgroundColor.slice(3, 5), 16);
const b = Number.parseInt(backgroundColor.slice(5, 7), 16);
// Calculate perceived brightness
// Using the formula: (R * 299 + G * 587 + B * 114) / 1000
@@ -47,9 +47,9 @@ const calculateRelativeLuminance = (rgb: number[]): number => {
};
export const isCloseToBlack = (color: string): boolean => {
const r = parseInt(color.slice(1, 3), 16);
const g = parseInt(color.slice(3, 5), 16);
const b = parseInt(color.slice(5, 7), 16);
const r = Number.parseInt(color.slice(1, 3), 16);
const g = Number.parseInt(color.slice(3, 5), 16);
const b = Number.parseInt(color.slice(5, 7), 16);
// Check if the color is very dark (close to black)
return r < 20 && g < 20 && b < 20;

View File

@@ -1,9 +1,9 @@
import { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models";
import { processesAtom } from "@/providers/DownloadProvider";
import { useSettings } from "@/utils/atoms/settings";
import type { JobStatus } from "@/utils/optimize-server";
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models";
import { atom, useAtom } from "jotai";
import { useEffect } from "react";
import {JobStatus} from "@/utils/optimize-server";
import {processesAtom} from "@/providers/DownloadProvider";
import {useSettings} from "@/utils/atoms/settings";
export interface Job {
id: string;
@@ -24,7 +24,7 @@ export const queueActions = {
processJob: async (
queue: Job[],
setQueue: (update: Job[]) => void,
setProcessing: (processing: boolean) => void
setProcessing: (processing: boolean) => void,
) => {
const [job, ...rest] = queue;
@@ -45,7 +45,7 @@ export const queueActions = {
},
clear: (
setQueue: (update: Job[]) => void,
setProcessing: (processing: boolean) => void
setProcessing: (processing: boolean) => void,
) => {
setQueue([]);
setProcessing(false);
@@ -59,7 +59,12 @@ export const useJobProcessor = () => {
const [settings] = useSettings();
useEffect(() => {
if (!running && queue.length > 0 && settings && processes.length < settings?.remuxConcurrentLimit) {
if (
!running &&
queue.length > 0 &&
settings &&
processes.length < settings?.remuxConcurrentLimit
) {
console.info("Processing queue", queue);
queueActions.processJob(queue, setQueue, setRunning);
}

View File

@@ -1,20 +1,20 @@
import { BITRATES, type Bitrate } from "@/components/BitrateSelector";
import * as ScreenOrientation from "@/packages/expo-screen-orientation";
import { apiAtom } from "@/providers/JellyfinProvider";
import { Video } from "@/utils/jellyseerr/server/models/Movie";
import { writeInfoLog } from "@/utils/log";
import {
type BaseItemKind,
type CultureDto,
type ItemFilter,
type ItemSortBy,
type SortOrder,
SubtitlePlaybackMode,
} from "@jellyfin/sdk/lib/generated-client";
import { atom, useAtom, useAtomValue } from "jotai";
import { useCallback, useEffect, useMemo } from "react";
import * as ScreenOrientation from "@/packages/expo-screen-orientation";
import { storage } from "../mmkv";
import { Platform } from "react-native";
import {
CultureDto,
SubtitlePlaybackMode,
ItemSortBy,
SortOrder,
BaseItemKind,
ItemFilter,
} from "@jellyfin/sdk/lib/generated-client";
import { Bitrate, BITRATES } from "@/components/BitrateSelector";
import { apiAtom } from "@/providers/JellyfinProvider";
import { writeInfoLog } from "@/utils/log";
import { Video } from "@/utils/jellyseerr/server/models/Movie";
import { storage } from "../mmkv";
const STREAMYFIN_PLUGIN_ID = "1e9e5d386e6746158719e98a5c34f004";
const STREAMYFIN_PLUGIN_SETTINGS = "STREAMYFIN_PLUGIN_SETTINGS";
@@ -26,17 +26,30 @@ export type DownloadOption = {
value: DownloadQuality;
};
export const ScreenOrientationEnum: Record<ScreenOrientation.OrientationLock, string> = {
[ScreenOrientation.OrientationLock.DEFAULT]: "home.settings.other.orientations.DEFAULT",
[ScreenOrientation.OrientationLock.ALL]: "home.settings.other.orientations.ALL",
[ScreenOrientation.OrientationLock.PORTRAIT]: "home.settings.other.orientations.PORTRAIT",
[ScreenOrientation.OrientationLock.PORTRAIT_UP]: "home.settings.other.orientations.PORTRAIT_UP",
[ScreenOrientation.OrientationLock.PORTRAIT_DOWN]: "home.settings.other.orientations.PORTRAIT_DOWN",
[ScreenOrientation.OrientationLock.LANDSCAPE]: "home.settings.other.orientations.LANDSCAPE",
[ScreenOrientation.OrientationLock.LANDSCAPE_LEFT]: "home.settings.other.orientations.LANDSCAPE_LEFT",
[ScreenOrientation.OrientationLock.LANDSCAPE_RIGHT]: "home.settings.other.orientations.LANDSCAPE_RIGHT",
[ScreenOrientation.OrientationLock.OTHER]: "home.settings.other.orientations.OTHER",
[ScreenOrientation.OrientationLock.UNKNOWN]: "home.settings.other.orientations.UNKNOWN",
export const ScreenOrientationEnum: Record<
ScreenOrientation.OrientationLock,
string
> = {
[ScreenOrientation.OrientationLock.DEFAULT]:
"home.settings.other.orientations.DEFAULT",
[ScreenOrientation.OrientationLock.ALL]:
"home.settings.other.orientations.ALL",
[ScreenOrientation.OrientationLock.PORTRAIT]:
"home.settings.other.orientations.PORTRAIT",
[ScreenOrientation.OrientationLock.PORTRAIT_UP]:
"home.settings.other.orientations.PORTRAIT_UP",
[ScreenOrientation.OrientationLock.PORTRAIT_DOWN]:
"home.settings.other.orientations.PORTRAIT_DOWN",
[ScreenOrientation.OrientationLock.LANDSCAPE]:
"home.settings.other.orientations.LANDSCAPE",
[ScreenOrientation.OrientationLock.LANDSCAPE_LEFT]:
"home.settings.other.orientations.LANDSCAPE_LEFT",
[ScreenOrientation.OrientationLock.LANDSCAPE_RIGHT]:
"home.settings.other.orientations.LANDSCAPE_RIGHT",
[ScreenOrientation.OrientationLock.OTHER]:
"home.settings.other.orientations.OTHER",
[ScreenOrientation.OrientationLock.UNKNOWN]:
"home.settings.other.orientations.UNKNOWN",
};
export const DownloadOptions: DownloadOption[] = [
@@ -102,8 +115,8 @@ export type HomeSectionNextUpResolver = {
export enum VideoPlayer {
// NATIVE, //todo: changes will make this a lot more easier to implement if we want. delete if not wanted
VLC_3,
VLC_4,
VLC_3 = 0,
VLC_4 = 1,
}
export type Settings = {
@@ -201,7 +214,8 @@ const defaultValues: Settings = {
const loadSettings = (): Partial<Settings> => {
try {
const jsonValue = storage.getString("settings");
const loadedValues: Partial<Settings> = jsonValue != null ? JSON.parse(jsonValue) : {};
const loadedValues: Partial<Settings> =
jsonValue != null ? JSON.parse(jsonValue) : {};
return loadedValues;
} catch (error) {
@@ -223,7 +237,9 @@ const saveSettings = (settings: Settings) => {
};
export const settingsAtom = atom<Partial<Settings> | null>(null);
export const pluginSettingsAtom = atom(storage.get<PluginLockableSettings>(STREAMYFIN_PLUGIN_SETTINGS));
export const pluginSettingsAtom = atom(
storage.get<PluginLockableSettings>(STREAMYFIN_PLUGIN_SETTINGS),
);
export const useSettings = () => {
const api = useAtomValue(apiAtom);
@@ -242,7 +258,7 @@ export const useSettings = () => {
storage.setAny(STREAMYFIN_PLUGIN_SETTINGS, settings);
_setPluginSettings(settings);
},
[_setPluginSettings]
[_setPluginSettings],
);
const refreshStreamyfinPluginSettings = useCallback(async () => {
@@ -252,7 +268,7 @@ export const useSettings = () => {
writeInfoLog(`Got remote settings: ${data?.settings}`);
return data?.settings;
},
(err) => undefined
(err) => undefined,
);
setPluginSettings(settings);
return settings;
@@ -260,11 +276,17 @@ export const useSettings = () => {
const updateSettings = (update: Partial<Settings>) => {
if (!_settings) return;
const hasChanges = Object.entries(update).some(([key, value]) => _settings[key as keyof Settings] !== value);
const hasChanges = Object.entries(update).some(
([key, value]) => _settings[key as keyof Settings] !== value,
);
if (hasChanges) {
// Merge default settings, current settings, and updates to ensure all required properties exist
const newSettings = { ...defaultValues, ..._settings, ...update } as Settings;
const newSettings = {
...defaultValues,
..._settings,
...update,
} as Settings;
setSettings(newSettings);
saveSettings(newSettings);
}
@@ -275,24 +297,33 @@ export const useSettings = () => {
// use user settings first and fallback on admin setting if required.
const settings: Settings = useMemo(() => {
let unlockedPluginDefaults = {} as Settings;
const overrideSettings = Object.entries(pluginSettings || {}).reduce((acc, [key, setting]) => {
if (setting) {
const { value, locked } = setting;
const overrideSettings = Object.entries(pluginSettings || {}).reduce(
(acc, [key, setting]) => {
if (setting) {
const { value, locked } = setting;
// Make sure we override default settings with plugin settings when they are not locked.
// Admin decided what users defaults should be and grants them the ability to change them too.
if (locked === false && value && _settings?.[key as keyof Settings] !== value) {
unlockedPluginDefaults = Object.assign(unlockedPluginDefaults, {
[key as keyof Settings]: value,
// Make sure we override default settings with plugin settings when they are not locked.
// Admin decided what users defaults should be and grants them the ability to change them too.
if (
locked === false &&
value &&
_settings?.[key as keyof Settings] !== value
) {
unlockedPluginDefaults = Object.assign(unlockedPluginDefaults, {
[key as keyof Settings]: value,
});
}
acc = Object.assign(acc, {
[key]: locked
? value
: (_settings?.[key as keyof Settings] ?? value),
});
}
acc = Object.assign(acc, {
[key]: locked ? value : _settings?.[key as keyof Settings] ?? value,
});
}
return acc;
}, {} as Settings);
return acc;
},
{} as Settings,
);
return {
...defaultValues,
@@ -301,5 +332,11 @@ export const useSettings = () => {
};
}, [_settings, pluginSettings]);
return [settings, updateSettings, pluginSettings, setPluginSettings, refreshStreamyfinPluginSettings] as const;
return [
settings,
updateSettings,
pluginSettings,
setPluginSettings,
refreshStreamyfinPluginSettings,
] as const;
};