Skip to main content

Mountain/IPC/WindServiceHandler/
History.rs

1#![allow(non_snake_case)]
2
3//! Navigation History domain handlers for Wind IPC.
4
5use std::sync::Arc;
6
7use serde_json::{Value, json};
8
9use crate::RunTime::ApplicationRunTime::ApplicationRunTime;
10
11/// Navigate backward in the editor history stack.
12pub async fn handle_history_go_back(Runtime:Arc<ApplicationRunTime>) -> Result<Value, String> {
13	let Uri = Runtime.Environment.ApplicationState.Feature.NavigationHistory.GoBack();
14	Ok(Uri.map(Value::String).unwrap_or(Value::Null))
15}
16
17/// Navigate forward in the editor history stack.
18pub async fn handle_history_go_forward(Runtime:Arc<ApplicationRunTime>) -> Result<Value, String> {
19	let Uri = Runtime.Environment.ApplicationState.Feature.NavigationHistory.GoForward();
20	Ok(Uri.map(Value::String).unwrap_or(Value::Null))
21}
22
23/// Return whether backward navigation is available.
24pub async fn handle_history_can_go_back(Runtime:Arc<ApplicationRunTime>) -> Result<Value, String> {
25	Ok(Value::Bool(
26		Runtime.Environment.ApplicationState.Feature.NavigationHistory.CanGoBack(),
27	))
28}
29
30/// Return whether forward navigation is available.
31pub async fn handle_history_can_go_forward(Runtime:Arc<ApplicationRunTime>) -> Result<Value, String> {
32	Ok(Value::Bool(
33		Runtime.Environment.ApplicationState.Feature.NavigationHistory.CanGoForward(),
34	))
35}
36
37/// Push a URI onto the navigation history stack.
38pub async fn handle_history_push(Runtime:Arc<ApplicationRunTime>, Args:Vec<Value>) -> Result<Value, String> {
39	let Uri = Args
40		.first()
41		.and_then(|V| V.as_str())
42		.ok_or("history:push requires uri".to_string())?
43		.to_owned();
44
45	Runtime.Environment.ApplicationState.Feature.NavigationHistory.Push(Uri);
46	Ok(Value::Null)
47}
48
49/// Clear the entire navigation history stack.
50pub async fn handle_history_clear(Runtime:Arc<ApplicationRunTime>) -> Result<Value, String> {
51	Runtime.Environment.ApplicationState.Feature.NavigationHistory.Clear();
52	Ok(Value::Null)
53}
54
55/// Return the full navigation history stack as an array of URI strings.
56pub async fn handle_history_get_stack(Runtime:Arc<ApplicationRunTime>) -> Result<Value, String> {
57	let Stack = Runtime.Environment.ApplicationState.Feature.NavigationHistory.GetStack();
58	Ok(Value::Array(Stack.into_iter().map(Value::String).collect()))
59}