Skip to main content

Mountain/RPC/CocoonService/Debug/
StartDebugging.rs

1#![allow(non_snake_case)]
2
3//! Start a debug session. Mints a session id, emits `sky://debug/start` so
4//! the workbench can render the debug toolbar/console.
5
6use std::time::{SystemTime, UNIX_EPOCH};
7
8use serde_json::json;
9use tauri::Emitter;
10use tonic::{Response, Status};
11
12use crate::{
13	RPC::CocoonService::CocoonServiceImpl,
14	Vine::Generated::{StartDebuggingRequest, StartDebuggingResponse},
15	dev_log,
16};
17
18pub async fn Fn(
19	Service:&CocoonServiceImpl,
20
21	Request:StartDebuggingRequest,
22) -> Result<Response<StartDebuggingResponse>, Status> {
23	dev_log!("cocoon", "[CocoonService] start_debugging: type={}", Request.debug_type);
24
25	let SessionIdentifier = format!(
26		"debug-{}",
27		SystemTime::now().duration_since(UNIX_EPOCH).map(|D| D.as_millis()).unwrap_or(0)
28	);
29
30	let _ = Service.environment.ApplicationHandle.emit(
31		"sky://debug/start",
32		json!({
33			"sessionId": SessionIdentifier,
34			"debugType": Request.debug_type,
35			"configuration": Request.configuration.as_ref().map(|C| json!({
36				"name": C.name,
37				"type": C.r#type,
38				"request": C.request,
39			})),
40		}),
41	);
42
43	Ok(Response::new(StartDebuggingResponse { success:true }))
44}