diff --git a/src/lib/api/native/modules/index.ts b/src/lib/api/native/modules/index.ts index fdc2419..89afeec 100644 --- a/src/lib/api/native/modules/index.ts +++ b/src/lib/api/native/modules/index.ts @@ -1,11 +1,23 @@ -import { RNModules } from "./types"; +import type { DiscordNativeModules } from "./types"; -const nmp = window.nativeModuleProxy; +export const NativeCacheModule = __turboModuleProxy( + 'NativeCacheModule', +) as DiscordNativeModules.CacheModule -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 NativeFileModule = __turboModuleProxy( + 'NativeFileModule', +) as DiscordNativeModules.FileModule -export const { BundleUpdaterManager } = nmp; +export const NativeClientInfoModule = __turboModuleProxy( + 'NativeClientInfoModule', +) as DiscordNativeModules.ClientInfoModule + +export const NativeDeviceModule = __turboModuleProxy( + 'NativeClientInfoModule', +) as DiscordNativeModules.ClientInfoModule + +export const BundleUpdaterModule = 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 4fd4501..07ad554 100644 --- a/src/lib/api/native/modules/types.ts +++ b/src/lib/api/native/modules/types.ts @@ -1,55 +1,65 @@ - - -export namespace RNModules { +export namespace DiscordNativeModules { /** - * A key-value storage based upon `SharedPreferences` on Android. - * - * These types are based on Android though everything should be the same between - * platforms. + * Key-value storage */ - export interface MMKVManager { + export interface CacheModule { /** * 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 } - export interface FileManager { + /** + * File manager + */ + export interface FileModule { /** * @param path **Full** path to file */ - fileExists: (path: string) => Promise; + 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 /** * 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. @@ -57,14 +67,21 @@ export namespace RNModules { * @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! @@ -72,18 +89,166 @@ export namespace RNModules { * @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; - }; - /** - * Will apparently cease to exist some time in the future so please use {@link getConstants} instead. - * @deprecated - */ - DocumentsDirPath: string; + 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 { + /** + * Reloads the app + */ + 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 + } +} \ No newline at end of file