diff options
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/constants.ts | 42 | ||||
| -rw-r--r-- | src/utils/index.ts | 30 |
2 files changed, 72 insertions, 0 deletions
diff --git a/src/utils/constants.ts b/src/utils/constants.ts new file mode 100644 index 0000000..fe78dd0 --- /dev/null +++ b/src/utils/constants.ts @@ -0,0 +1,42 @@ +// Common types for the application + +export interface ResultType { + status: string; + message?: string; + output?: string; +} + +export interface GameType { + appid: number; + name: string; +} + +// Common style definitions +export const STYLES = { + resultBox: { + padding: '12px', + marginTop: '16px', + backgroundColor: 'var(--decky-selected-ui-bg)', + borderRadius: '4px' + }, + statusSuccess: { color: "green" }, + statusError: { color: "red" }, + preWrap: { whiteSpace: "pre-wrap" as const } +}; + +// Common timeout values +export const TIMEOUTS = { + resultDisplay: 5000, // 5 seconds + pathCheck: 3000 // 3 seconds +}; + +// Message strings +export const MESSAGES = { + modInstalled: "OptiScaler Mod Is Installed", + modNotInstalled: "OptiScaler Mod Not Installed", + installing: "Installing...", + installButton: "Install OptiScaler FG Mod", + uninstalling: "Uninstalling...", + uninstallButton: "Uninstall OptiScaler FG Mod", + instructionText: "Install the OptiScaler-based mod above, then select and patch a game below to enable DLSS replacement with FSR Frame Generation. Map a button to \"insert\" key to bring up the OptiScaler menu in-game." +}; diff --git a/src/utils/index.ts b/src/utils/index.ts new file mode 100644 index 0000000..d969cb6 --- /dev/null +++ b/src/utils/index.ts @@ -0,0 +1,30 @@ +import { logError } from "../api"; + +/** + * Utility for creating a timer that automatically clears after specified timeout + * @param callback Function to call when timer completes + * @param timeout Timeout in milliseconds + * @returns Cleanup function that can be used in useEffect + */ +export const createAutoCleanupTimer = (callback: () => void, timeout: number): (() => void) => { + const timer = setTimeout(callback, timeout); + return () => clearTimeout(timer); +}; + +/** + * Safe wrapper for async operations to handle errors consistently + * @param operation Async operation to perform + * @param errorContext Context string for error logging + */ +export const safeAsyncOperation = async <T,>( + operation: () => Promise<T>, + errorContext: string +): Promise<T | undefined> => { + try { + return await operation(); + } catch (e) { + logError(`${errorContext}: ${String(e)}`); + console.error(e); + return undefined; + } +}; |
