дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 01:31:41 +02:00
A command is now declared once, on the fn that implements it. A project-host command is an ide-host fn with #[command(trust = …)] listed in its module's domain!; its Tauri adapter, bindings entry, JSON-RPC handler, trust class and remote routing are derived from that declaration. Desktop-only commands keep their Tauri fn and add #[desktop_command(trust = …)]. This removes the hand-written pass-through adapters, collect_commands!, the per-domain register fns and the trust tables in trust.rs. The invoke handler looks up each command's declared trust class; a name nothing declares is denied. A remote window routes the project-host commands of the desktop's own build. Duplicate names are a compile error. CI runs ide-command's compile_fail doctests. Part of #3344. Co-authored-by: Mr0Bread <[email protected]>
68 рядки
2.1 KiB
Rust
68 рядки
2.1 KiB
Rust
use crate::state::AppState;
|
||
use ide_command::desktop_command;
|
||
use ide_core::{IdeEvent, IdeResult};
|
||
use tauri::State;
|
||
|
||
/// Settings › SSH Configurations: the configurations in effect.
|
||
pub(crate) fn apply_ssh_settings(state: &AppState) {
|
||
state.ssh.set_configs(state.global_settings.effective().ssh.configs);
|
||
}
|
||
|
||
/// Answers an `IdeEvent::Askpass` prompt (`None`: cancelled); every window drops it.
|
||
#[desktop_command(trust = always)]
|
||
#[tauri::command]
|
||
#[specta::specta]
|
||
pub fn ssh_askpass_answer(state: State<'_, AppState>, id: u64, answer: Option<String>, remember: bool) {
|
||
if let Some(server) = &state.askpass {
|
||
server.answer(id, answer, remember);
|
||
}
|
||
state.sink.emit(IdeEvent::AskpassDone { id });
|
||
}
|
||
|
||
/// Settings › Git › Saved credentials: `scheme://host` of every saved entry.
|
||
#[desktop_command(trust = always)]
|
||
#[tauri::command]
|
||
#[specta::specta]
|
||
pub fn git_credentials(_state: State<'_, AppState>) -> Vec<String> {
|
||
ide_ssh::git_creds::get().map(|s| s.list()).unwrap_or_default()
|
||
}
|
||
|
||
/// Forgets the credential of `key` (a `git_credentials` entry).
|
||
#[desktop_command(trust = always)]
|
||
#[tauri::command]
|
||
#[specta::specta]
|
||
pub fn git_credential_forget(_state: State<'_, AppState>, key: String) {
|
||
if let Some(store) = ide_ssh::git_creds::get() {
|
||
store.forget(&key);
|
||
}
|
||
}
|
||
|
||
/// Tools › Start SSH Session: a shell on configuration `id` in a terminal tab, through the
|
||
/// built-in client with the configuration's saved credentials.
|
||
#[desktop_command(trust = always)]
|
||
#[tauri::command]
|
||
#[specta::specta]
|
||
pub async fn ssh_open_terminal(
|
||
window: tauri::Window,
|
||
state: State<'_, AppState>,
|
||
id: String,
|
||
cols: u16,
|
||
rows: u16,
|
||
on_output: tauri::ipc::Channel<String>,
|
||
) -> IdeResult<ide_terminal::TerminalInfo> {
|
||
let host = state.host.clone();
|
||
ide_host::ops::term::spawn_ssh(
|
||
&host,
|
||
window.label(),
|
||
&id,
|
||
cols,
|
||
rows,
|
||
std::sync::Arc::new(move |chunk| {
|
||
let _ = on_output.send(chunk);
|
||
}),
|
||
)
|
||
.await
|
||
}
|
||
|
||
ide_command::desktop_domain!(git_credential_forget, git_credentials, ssh_askpass_answer, ssh_open_terminal,);
|