1use std::fmt;
2
3use thiserror::Error;
4
5pub type MacosAdapterResult<T> = Result<T, MacosAdapterError>;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8pub enum PermissionKind {
9 Microphone,
10 Accessibility,
11 InputMonitoring,
12}
13
14impl PermissionKind {
15 #[must_use]
16 pub const fn as_str(self) -> &'static str {
17 match self {
18 Self::Microphone => "microphone",
19 Self::Accessibility => "accessibility",
20 Self::InputMonitoring => "input_monitoring",
21 }
22 }
23}
24
25impl fmt::Display for PermissionKind {
26 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27 f.write_str(self.as_str())
28 }
29}
30
31#[derive(Debug, Error, Clone, PartialEq, Eq)]
32pub enum MacosAdapterError {
33 #[error("unsupported platform")]
34 UnsupportedPlatform,
35 #[error("missing required permissions: {permissions:?}")]
36 MissingPermissions { permissions: Vec<PermissionKind> },
37 #[error("hotkey event stream closed")]
38 HotkeyEventStreamClosed,
39 #[error("audio recorder is already active")]
40 RecorderAlreadyActive,
41 #[error("audio recorder is not active")]
42 RecorderNotActive,
43 #[error("text injection payload must not be empty")]
44 EmptyInjectionText,
45 #[error("{operation} failed: {message}")]
46 OperationFailed {
47 operation: &'static str,
48 message: String,
49 },
50}
51
52impl MacosAdapterError {
53 #[must_use]
54 pub fn operation_failed(operation: &'static str, message: impl Into<String>) -> Self {
55 Self::OperationFailed {
56 operation,
57 message: message.into(),
58 }
59 }
60}