mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-27 03:41:26 +01:00
Decouple Tree from client app's hotkey system by adding getSelectedItems() to TreeHandle and having callers register hotkeys externally. Extract shared action callbacks to eliminate duplication between hotkey and context menu handlers. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
54 lines
1.5 KiB
Rust
54 lines
1.5 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
use ts_rs::TS;
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
|
|
#[serde(rename_all = "snake_case")]
|
|
#[ts(export, export_to = "gen_rpc.ts")]
|
|
pub enum GlobalAction {
|
|
ProxyStart,
|
|
ProxyStop,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
|
|
#[serde(tag = "scope", rename_all = "snake_case")]
|
|
#[ts(export, export_to = "gen_rpc.ts")]
|
|
pub enum ActionInvocation {
|
|
Global { action: GlobalAction },
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
|
|
#[serde(rename_all = "camelCase")]
|
|
#[ts(export, export_to = "gen_rpc.ts")]
|
|
pub struct ActionMetadata {
|
|
pub label: String,
|
|
pub default_hotkey: Option<String>,
|
|
}
|
|
|
|
fn default_hotkey(mac: &str, other: &str) -> Option<String> {
|
|
if cfg!(target_os = "macos") {
|
|
Some(mac.into())
|
|
} else {
|
|
Some(other.into())
|
|
}
|
|
}
|
|
|
|
/// All global actions with their metadata, used by `list_actions` RPC.
|
|
pub fn all_global_actions() -> Vec<(ActionInvocation, ActionMetadata)> {
|
|
vec![
|
|
(
|
|
ActionInvocation::Global { action: GlobalAction::ProxyStart },
|
|
ActionMetadata {
|
|
label: "Start Proxy".into(),
|
|
default_hotkey: default_hotkey("Meta+Shift+P", "Ctrl+Shift+P"),
|
|
},
|
|
),
|
|
(
|
|
ActionInvocation::Global { action: GlobalAction::ProxyStop },
|
|
ActionMetadata {
|
|
label: "Stop Proxy".into(),
|
|
default_hotkey: default_hotkey("Meta+Shift+S", "Ctrl+Shift+S"),
|
|
},
|
|
),
|
|
]
|
|
}
|