feat: find-window, run, clipboard, label-routing, persistent session-id, exe icon
This commit is contained in:
parent
ef4ca0ccbb
commit
672676d3d7
9 changed files with 214 additions and 15 deletions
|
|
@ -404,6 +404,81 @@ pub async fn download_file(
|
|||
}
|
||||
}
|
||||
|
||||
/// POST /sessions/:id/run
|
||||
#[derive(Deserialize)]
|
||||
pub struct RunBody {
|
||||
pub program: String,
|
||||
#[serde(default)]
|
||||
pub args: Vec<String>,
|
||||
}
|
||||
|
||||
pub async fn run_program(
|
||||
Path(session_id): Path<String>,
|
||||
State(state): State<AppState>,
|
||||
Json(body): Json<RunBody>,
|
||||
) -> impl IntoResponse {
|
||||
match dispatch(&state, &session_id, "run", |rid| ServerMessage::RunRequest {
|
||||
request_id: rid,
|
||||
program: body.program.clone(),
|
||||
args: body.args.clone(),
|
||||
})
|
||||
.await
|
||||
{
|
||||
Ok(_) => (StatusCode::OK, Json(serde_json::json!({ "ok": true }))).into_response(),
|
||||
Err(e) => e.into_response(),
|
||||
}
|
||||
}
|
||||
|
||||
/// GET /sessions/:id/clipboard
|
||||
pub async fn clipboard_get(
|
||||
Path(session_id): Path<String>,
|
||||
State(state): State<AppState>,
|
||||
) -> impl IntoResponse {
|
||||
match dispatch(&state, &session_id, "clipboard_get", |rid| {
|
||||
ServerMessage::ClipboardGetRequest { request_id: rid }
|
||||
})
|
||||
.await
|
||||
{
|
||||
Ok(ClientMessage::ClipboardGetResponse { text, .. }) => (
|
||||
StatusCode::OK,
|
||||
Json(serde_json::json!({ "text": text })),
|
||||
)
|
||||
.into_response(),
|
||||
Ok(ClientMessage::Error { message, .. }) => (
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
Json(serde_json::json!({ "error": message })),
|
||||
)
|
||||
.into_response(),
|
||||
Ok(_) => (
|
||||
StatusCode::BAD_GATEWAY,
|
||||
Json(serde_json::json!({ "error": "Unexpected response from client" })),
|
||||
)
|
||||
.into_response(),
|
||||
Err(e) => e.into_response(),
|
||||
}
|
||||
}
|
||||
|
||||
/// POST /sessions/:id/clipboard
|
||||
#[derive(Deserialize)]
|
||||
pub struct ClipboardSetBody {
|
||||
pub text: String,
|
||||
}
|
||||
|
||||
pub async fn clipboard_set(
|
||||
Path(session_id): Path<String>,
|
||||
State(state): State<AppState>,
|
||||
Json(body): Json<ClipboardSetBody>,
|
||||
) -> impl IntoResponse {
|
||||
match dispatch(&state, &session_id, "clipboard_set", |rid| {
|
||||
ServerMessage::ClipboardSetRequest { request_id: rid, text: body.text.clone() }
|
||||
})
|
||||
.await
|
||||
{
|
||||
Ok(_) => (StatusCode::OK, Json(serde_json::json!({ "ok": true }))).into_response(),
|
||||
Err(e) => e.into_response(),
|
||||
}
|
||||
}
|
||||
|
||||
/// POST /sessions/:id/label
|
||||
#[derive(Deserialize)]
|
||||
pub struct LabelBody {
|
||||
|
|
|
|||
|
|
@ -58,6 +58,9 @@ async fn main() -> anyhow::Result<()> {
|
|||
.route("/sessions/:id/version", get(api::client_version))
|
||||
.route("/sessions/:id/upload", post(api::upload_file))
|
||||
.route("/sessions/:id/download", get(api::download_file))
|
||||
.route("/sessions/:id/run", post(api::run_program))
|
||||
.route("/sessions/:id/clipboard", get(api::clipboard_get))
|
||||
.route("/sessions/:id/clipboard", post(api::clipboard_set))
|
||||
.layer(middleware::from_fn_with_state(state.clone(), require_api_key));
|
||||
|
||||
let app = Router::new()
|
||||
|
|
|
|||
|
|
@ -91,6 +91,7 @@ async fn handle_client_message(session_id: Uuid, msg: ClientMessage, state: &App
|
|||
| ClientMessage::ListWindowsResponse { request_id, .. }
|
||||
| ClientMessage::VersionResponse { request_id, .. }
|
||||
| ClientMessage::DownloadResponse { request_id, .. }
|
||||
| ClientMessage::ClipboardGetResponse { request_id, .. }
|
||||
| ClientMessage::Ack { request_id }
|
||||
| ClientMessage::Error { request_id, .. } => {
|
||||
let rid = *request_id;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue