Skip to main content

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};
9use ::Vine::Generated::{ShowProgressRequest, ShowProgressResponse};
10
11use crate::{RPC::CocoonService::CocoonServiceImpl, dev_log};
12
13pub async fn Fn(
14	Service:&CocoonServiceImpl,
15
16	Request:ShowProgressRequest,
17) -> Result<Response<ShowProgressResponse>, Status> {
18	dev_log!("cocoon", "[CocoonService] show_progress: title={}", Request.title);
19
20	let Handle = SystemTime::now()
21		.duration_since(UNIX_EPOCH)
22		.map(|D| D.as_millis() as u32)
23		.unwrap_or(0);
24
25	let _ = Service.environment.ApplicationHandle.emit(
26		"sky://progress/start",
27		json!({
28			"handle": Handle,
29			"title": Request.title,
30			"cancellable": Request.cancellable,
31			"location": Request.location,
32		}),
33	);
34
35	Ok(Response::new(ShowProgressResponse { handle:Handle }))
36}