use super::action::{Action, WorkflowStep};
use super::key_combo::KeyCombo;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Effect<'a> {
None,
Click(MouseButton),
Shortcut(Shortcut),
Key(&'a KeyCombo),
Scroll {
dx: i8,
dy: i8,
},
Media(MediaKey),
Native(NativeAction),
Script(Script<'a>),
Text(&'a str),
AgentSide,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum MouseButton {
Left,
Right,
Middle,
Back,
Forward,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, strum::VariantArray)]
pub enum Shortcut {
Copy,
Paste,
Cut,
Undo,
Redo,
SelectAll,
Find,
Save,
BrowserBack,
BrowserForward,
NewTab,
CloseTab,
ReopenTab,
NextTab,
PrevTab,
ReloadPage,
}
impl Shortcut {
pub const ALL: &'static [Shortcut] = <Shortcut as strum::VariantArray>::VARIANTS;
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum MediaKey {
PlayPause,
NextTrack,
PrevTrack,
VolumeUp,
VolumeDown,
Mute,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum NativeAction {
MissionControl,
AppExpose,
PreviousDesktop,
NextDesktop,
ShowDesktop,
LaunchpadShow,
LockScreen,
Screenshot,
CaptureRegion,
Sleep,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Script<'a> {
AppleScript(&'a str),
ShellCommand(&'a str),
Workflow(&'a [WorkflowStep]),
}
impl Action {
#[must_use]
pub fn effect(&self) -> Effect<'_> {
match self {
Action::None => Effect::None,
Action::LeftClick => Effect::Click(MouseButton::Left),
Action::RightClick => Effect::Click(MouseButton::Right),
Action::MiddleClick => Effect::Click(MouseButton::Middle),
Action::MouseBack => Effect::Click(MouseButton::Back),
Action::MouseForward => Effect::Click(MouseButton::Forward),
Action::Copy => Effect::Shortcut(Shortcut::Copy),
Action::Paste => Effect::Shortcut(Shortcut::Paste),
Action::Cut => Effect::Shortcut(Shortcut::Cut),
Action::Undo => Effect::Shortcut(Shortcut::Undo),
Action::Redo => Effect::Shortcut(Shortcut::Redo),
Action::SelectAll => Effect::Shortcut(Shortcut::SelectAll),
Action::Find => Effect::Shortcut(Shortcut::Find),
Action::Save => Effect::Shortcut(Shortcut::Save),
Action::BrowserBack => Effect::Shortcut(Shortcut::BrowserBack),
Action::BrowserForward => Effect::Shortcut(Shortcut::BrowserForward),
Action::NewTab => Effect::Shortcut(Shortcut::NewTab),
Action::CloseTab => Effect::Shortcut(Shortcut::CloseTab),
Action::ReopenTab => Effect::Shortcut(Shortcut::ReopenTab),
Action::NextTab => Effect::Shortcut(Shortcut::NextTab),
Action::PrevTab => Effect::Shortcut(Shortcut::PrevTab),
Action::ReloadPage => Effect::Shortcut(Shortcut::ReloadPage),
Action::MissionControl => Effect::Native(NativeAction::MissionControl),
Action::AppExpose => Effect::Native(NativeAction::AppExpose),
Action::PreviousDesktop => Effect::Native(NativeAction::PreviousDesktop),
Action::NextDesktop => Effect::Native(NativeAction::NextDesktop),
Action::ShowDesktop => Effect::Native(NativeAction::ShowDesktop),
Action::LaunchpadShow => Effect::Native(NativeAction::LaunchpadShow),
Action::LockScreen => Effect::Native(NativeAction::LockScreen),
Action::Screenshot => Effect::Native(NativeAction::Screenshot),
Action::CaptureRegion => Effect::Native(NativeAction::CaptureRegion),
Action::Sleep => Effect::Native(NativeAction::Sleep),
Action::PlayPause => Effect::Media(MediaKey::PlayPause),
Action::NextTrack => Effect::Media(MediaKey::NextTrack),
Action::PrevTrack => Effect::Media(MediaKey::PrevTrack),
Action::VolumeUp => Effect::Media(MediaKey::VolumeUp),
Action::VolumeDown => Effect::Media(MediaKey::VolumeDown),
Action::MuteVolume => Effect::Media(MediaKey::Mute),
Action::CycleDpiPresets
| Action::SetDpiPreset(_)
| Action::ToggleSmartShift
| Action::ShowActionsRing
| Action::OpenApplication(_) => Effect::AgentSide,
Action::ScrollUp => Effect::Scroll { dx: 0, dy: 1 },
Action::ScrollDown => Effect::Scroll { dx: 0, dy: -1 },
Action::HorizontalScrollLeft => Effect::Scroll { dx: -1, dy: 0 },
Action::HorizontalScrollRight => Effect::Scroll { dx: 1, dy: 0 },
Action::CustomShortcut(combo) => Effect::Key(combo),
Action::TypeText(text) => Effect::Text(text),
Action::RunAppleScript(src) => Effect::Script(Script::AppleScript(src)),
Action::RunShellCommand(cmd) => Effect::Script(Script::ShellCommand(cmd)),
Action::Workflow(steps) => Effect::Script(Script::Workflow(steps)),
}
}
}