Skip to main content

Mountain/RPC/CocoonService/Window/
ShowProgress.rs

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