diff --git a/src/lib/api/native/modules/index.ts b/src/lib/api/native/modules/index.ts index 88739d4..f1165e2 100644 --- a/src/lib/api/native/modules/index.ts +++ b/src/lib/api/native/modules/index.ts @@ -1,23 +1,12 @@ -import type { DiscordNativeModules } from "./types"; +import { RNModules } from "./types"; -export const NativeCacheModule = __turboModuleProxy( - 'NativeCacheModule', -) as DiscordNativeModules.CacheModule +const nmp = window.nativeModuleProxy; -export const NativeFileModule = __turboModuleProxy( - 'NativeFileModule', -) as DiscordNativeModules.FileModule +export const NativeCacheModule = (nmp.NativeCacheModule ?? nmp.MMKVManager) as RNModules.MMKVManager; +export const NativeFileModule = (nmp.NativeFileModule ?? nmp.RTNFileManager ?? nmp.DCDFileManager) as RNModules.FileManager; +export const NativeClientInfoModule = nmp.NativeClientInfoModule ?? nmp.RTNClientInfoManager ?? nmp.InfoDictionaryManager; +export const NativeDeviceModule = nmp.NativeDeviceModule ?? nmp.RTNDeviceManager ?? nmp.DCDDeviceManager; +export const NativeThemeModule = nmp.NativeThemeModule ?? nmp.RTNThemeManager ?? nmp.DCDTheme; -export const NativeClientInfoModule = __turboModuleProxy( - 'NativeClientInfoModule', -) as DiscordNativeModules.ClientInfoModule +export const { BundleUpdaterManager } = nmp; -export const NativeDeviceModule = __turboModuleProxy( - 'NativeClientInfoModule', -) as DiscordNativeModules.ClientInfoModule - -export const BundleUpdaterManager = getNativeModule("BundleUpdaterManager"); - -export const NativeThemeModule = __turboModuleProxy( - 'NativeThemeModule', -) as DiscordNativeModules.ThemeModule diff --git a/src/lib/api/native/modules/types.ts b/src/lib/api/native/modules/types.ts index 07ad554..970a6af 100644 --- a/src/lib/api/native/modules/types.ts +++ b/src/lib/api/native/modules/types.ts @@ -1,65 +1,53 @@ -export namespace DiscordNativeModules { +export namespace RNModules { /** - * Key-value storage + * A key-value storage based upon `SharedPreferences` on Android. + * + * These types are based on Android though everything should be the same between + * platforms. */ - export interface CacheModule { + export interface MMKVManager { /** * Get the value for the given `key`, or null * @param key The key to fetch */ - getItem: (key: string) => Promise + getItem: (key: string) => Promise; /** * Deletes the value for the given `key` * @param key The key to delete - */ - removeItem: (key: string) => void + */ + removeItem: (key: string) => void; /** * Sets the value of `key` to `value` */ - setItem: (key: string, value: string) => void + setItem: (key: string, value: string) => void; /** - * Goes through every item in storage and returns it, excluding the keys specified in `exclude`. + * Goes through every item in storage and returns it, excluding the + * keys specified in `exclude`. * @param exclude A list of items to exclude from result */ - refresh: (exclude: string[]) => Promise> + refresh: (exclude: string[]) => Promise>; /** + * You will be murdered if you use this function. * Clears ALL of Discord's settings. */ - clear: () => void + clear: () => void; } - /** - * File manager - */ - export interface FileModule { + export interface FileManager { /** * @param path **Full** path to file */ - fileExists: (path: string) => Promise - /** - * Reads an asset from the given URI - * @param nameOrUri The name or URI to read from (`http://` scheme is supported) - * @param encoding The encoding to read the asset with - * @returns - */ - readAsset: ( - nameOrUri: string, - encoding: 'base64' | 'utf8', - ) => Promise + fileExists: (path: string) => Promise; /** * Allowed URI schemes on Android: `file://`, `content://` ([See here](https://developer.android.com/reference/android/content/ContentResolver#accepts-the-following-uri-schemes:_3)) */ - getSize: (uri: string) => Promise + getSize: (uri: string) => Promise; /** * @param path **Full** path to file * @param encoding Set to `base64` in order to encode response */ - readFile(path: string, encoding: 'base64' | 'utf8'): Promise - saveFileToGallery?( - uri: string, - fileName: string, - fileType: 'PNG' | 'JPEG', - ): Promise + readFile(path: string, encoding: "base64" | "utf8"): Promise; + saveFileToGallery?(uri: string, fileName: string, fileType: "PNG" | "JPEG"): Promise; /** * @param storageDir Either `cache` or `documents`. * @param path Path in `storageDir`, parents are recursively created. @@ -67,21 +55,14 @@ export namespace DiscordNativeModules { * @param encoding Set to `base64` if `data` is base64 encoded. * @returns Promise that resolves to path of the file once it got written */ - writeFile( - storageDir: 'cache' | 'documents', - path: string, - data: string, - encoding: 'base64' | 'utf8', - ): Promise + writeFile(storageDir: "cache" | "documents", path: string, data: string, encoding: "base64" | "utf8"): Promise; /** * Removes a file from the path given. + * (!) On Android, this always returns false, regardless if it fails or not! * @param storageDir Either `cache` or `documents` * @param path Path to the file to be removed */ - removeFile( - storageDir: 'cache' | 'documents', - path: string, - ): Promise + removeFile(storageDir: "cache" | "documents", path: string): Promise; /** * Clear the folder from the path given * (!) On Android, this only clears all *files* and not subdirectories! @@ -89,166 +70,18 @@ export namespace DiscordNativeModules { * @param path Path to the folder to be cleared * @returns Whether the clearance succeeded */ - clearFolder( - storageDir: 'cache' | 'documents', - path: string, - ): Promise - getConstants(): { + clearFolder(storageDir: "cache" | "documents", path: string): Promise; + getConstants: () => { /** * The path the `documents` storage dir (see {@link writeFile}) represents. */ - DocumentsDirPath: string - CacheDirPath: string - } - } - - /** - * Client information - */ - export interface ClientInfoModule { - getConstants(): { - /** - * Sentry ingestion DSN URL for alpha/beta builds - */ - SentryAlphaBetaDsn: string - /** - * Sentry ingestion DSN URL for staff builds (?) - */ - SentryStaffDsn: string - /** - * Sentry ingestion DSN URL for stable builds - */ - SentryDsn: string - DeviceVendorID: string - Manifest: string - /** - * Version code - * - * Follows the format of `{MINOR}{CHANNEL}{PATCH}` for `{MINOR}.{PATCH} ({CHANNEL})` - * - `248200` for `248.0 (alpha)` - * - `247105` for `247.5 (beta)` - * - `246011` for `246.11 (stable)` - */ - Build: any - /** - * Version string - * - * Eg. `248.0` - */ - Version: string - /** - * Release channel - */ - ReleaseChannel: string - /** - * Matches `Version` - */ - OTABuild: string - /** - * Identifier for the installed client - * - * - **Android**: Package name - * - **iOS**: Bundle ID - */ - Identifier: string - } - } - - /** - * OTA updates, app reloads, etc. - */ - export interface BundleUpdaterManager { + DocumentsDirPath: string; + CacheDirPath: string; + }; /** - * Reloads the app + * Will apparently cease to exist some time in the future so please use {@link getConstants} instead. + * @deprecated */ - reload(): void - } - - /** - * Device information - */ - export interface DeviceModule { - /** - * Returns the screen size of the device - */ - getScreenSize(): { width: number; height: number } - getConstants(): { - /** - * Maximum CPU frequency - * @example "2.00" - */ - maxCpuFreq: string - /** - * The brand of the device - * - On Android, returns the value of `ro.product.brand` - */ - deviceBrand: string - /** - * Whether the device is using gesture navigation - */ - isGestureNavigationEnabled: boolean - /** - * The manufacturer of the device - * - On Android, returns the value of `ro.product.manufacturer` - */ - deviceManufacturer: string - /** - * RAM size in gigabytes (most likely an approximation) - * @example "3.62" - */ - ramSize: string - /** - * The device's DPI setting - */ - smallestScreenWidth: number - /** - * The version of the system - * - On Android, returns the value of `ro.build.version.sdk` - */ - systemVersion: string - /** - * Whether the system taskbar navigation is enabled - */ - isTaskBarEnabled: boolean - /** - * The name of the device product - * - On Android, returns the value of `ro.product.name` - */ - deviceProduct: string - /** - * The model of the device - * - On Android, returns the value of `ro.product.model` - */ - deviceModel: string - /** - * The name of the device - * - On Android, returns the value of `ro.product.device` - */ - device: string - /** - * The name of the device board - * - On Android, returns the value of `{ro.product.manufacturer}_{ro.soc.model}` - * @example "Google_Tensor G4" // ro.product.manufacturer=Google; ro.soc.model=Tensor G4 - */ - socName: string - } - } - - /** - * Manage theme settings, saturation settings, etc. - * - * This only manages the native-side components and already-rendered native components will need to be re-rendered to apply changes. - */ - export interface ThemeModule { - /** - * Sets the saturation value - * @param saturation The saturation value to set - */ - updateSaturation(saturation: number): void - /** - * Sets the theme - * @param theme The theme to set - */ - updateTheme(theme: 'dark' | 'light'): void + DocumentsDirPath: string; } } \ No newline at end of file