Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/RPC/CocoonService/Window/
ShowProgress.rs

1//! Begin a progress notification. Mints a millisecond handle, emits
2//! `sky://progress/start` so the workbench can render the bar.
3
4use std::time::{SystemTime, UNIX_EPOCH};
5
6use serde_json::json;
7use tauri::Emitter;
8use tonic::{Response, Status};
9
10use crate::{
11	RPC::CocoonService::CocoonServiceImpl,
12	Vine::Generated::{ShowProgressRequest, ShowProgressResponse},
13	dev_log,
14};
15
16pub async fn Fn(
17	Service:&CocoonServiceImpl,
18
19	Request:ShowProgressRequest,
20) -> Result<Response<ShowProgressResponse>, Status> {
21	dev_log!("cocoon", "[CocoonService] show_progress: title={}", Request.title);
22
23	let Handle = SystemTime::now()
24		.duration_since(UNIX_EPOCH)
25		.map(|D| D.as_millis() as u32)
26		.unwrap_or(0);
27
28	let _ = Service.environment.ApplicationHandle.emit(
29		"sky://progress/start",
30		json!({
31			"handle": Handle,
32			"title": Request.title,
33			"cancellable": Request.cancellable,
34			"location": Request.location,
35		}),
36	);
37
38	Ok(Response::new(ShowProgressResponse { handle:Handle }))
39}