namespace AIStudio.Tools.Rust; /// /// The data structure for a Tauri event sent from the Rust backend to the C# frontend. /// /// The type of the Tauri event. /// The payload of the Tauri event. public readonly record struct TauriEvent(TauriEventType EventType, List Payload) { /// /// Attempts to parse the first payload element as a shortcut. /// /// The parsed shortcut name if successful. /// True if parsing was successful, false otherwise. public bool TryGetShortcut(out Shortcut shortcut) { shortcut = default; if (this.Payload.Count == 0) return false; // Try standard enum parsing (handles PascalCase and numeric values): if (Enum.TryParse(this.Payload[0], ignoreCase: true, out shortcut)) return true; // Try parsing snake_case format (e.g., "voice_recording_toggle"): return TryParseSnakeCase(this.Payload[0], out shortcut); } /// /// Tries to parse a snake_case string into a ShortcutName enum value. /// private static bool TryParseSnakeCase(string value, out Shortcut shortcut) { shortcut = default; // Convert snake_case to UPPER_SNAKE_CASE for enum matching: var upperSnakeCase = value.ToUpperInvariant(); // Try to match against enum names (which are in UPPER_SNAKE_CASE): return Enum.TryParse(upperSnakeCase, ignoreCase: false, out shortcut); } };