Skip to main content

Mountain/RPC/CocoonService/Window/
ShowProgress.rs

1#![allow(non_snake_case)]
2
3//! Begin a progress notification. Mints a millisecond handle, emits
4//! `sky://progress/start` so the workbench can render the bar.
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::{ShowProgressRequest, ShowProgressResponse},
15	dev_log,
16};
17
18pub async fn Fn(
19	Service:&CocoonServiceImpl,
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}