mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-05-23 07:16:36 +01:00
feat(tvos): Add TopShelf Extension (#1561)
This commit is contained in:
21
modules/top-shelf-cache/src/TopShelfCache.types.ts
Normal file
21
modules/top-shelf-cache/src/TopShelfCache.types.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
export type TopShelfCacheModuleEvents = Record<string, never>;
|
||||
|
||||
export interface TopShelfCacheItem {
|
||||
id: string;
|
||||
title: string;
|
||||
subtitle?: string;
|
||||
imageUrl?: string;
|
||||
route: string;
|
||||
playRoute?: string;
|
||||
}
|
||||
|
||||
export interface TopShelfCacheSection {
|
||||
title: string;
|
||||
items: TopShelfCacheItem[];
|
||||
}
|
||||
|
||||
export interface TopShelfCachePayload {
|
||||
version: 1;
|
||||
updatedAt: string;
|
||||
sections: TopShelfCacheSection[];
|
||||
}
|
||||
37
modules/top-shelf-cache/src/TopShelfCacheModule.ts
Normal file
37
modules/top-shelf-cache/src/TopShelfCacheModule.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { NativeModule, requireNativeModule } from "expo";
|
||||
import { Platform } from "react-native";
|
||||
import type { TopShelfCacheModuleEvents } from "./TopShelfCache.types";
|
||||
|
||||
declare class TopShelfCacheModuleType extends NativeModule<TopShelfCacheModuleEvents> {
|
||||
writeCache(json: string, apiKey?: string): boolean;
|
||||
clearCache(): boolean;
|
||||
}
|
||||
|
||||
let TopShelfCacheNativeModule: TopShelfCacheModuleType | null = null;
|
||||
|
||||
if (Platform.OS === "ios" && Platform.isTV) {
|
||||
try {
|
||||
TopShelfCacheNativeModule =
|
||||
requireNativeModule<TopShelfCacheModuleType>("TopShelfCache");
|
||||
} catch {
|
||||
TopShelfCacheNativeModule = null;
|
||||
}
|
||||
}
|
||||
|
||||
export function writeTopShelfCache(json: string, apiKey?: string): boolean {
|
||||
if (!TopShelfCacheNativeModule) return false;
|
||||
|
||||
try {
|
||||
return TopShelfCacheNativeModule.writeCache(json, apiKey);
|
||||
} catch {
|
||||
try {
|
||||
return TopShelfCacheNativeModule.writeCache(json);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function clearTopShelfCache(): boolean {
|
||||
return TopShelfCacheNativeModule?.clearCache() ?? false;
|
||||
}
|
||||
2
modules/top-shelf-cache/src/index.ts
Normal file
2
modules/top-shelf-cache/src/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./TopShelfCache.types";
|
||||
export { clearTopShelfCache, writeTopShelfCache } from "./TopShelfCacheModule";
|
||||
Reference in New Issue
Block a user