Mountain/IPC/WindServiceHandler/
History.rs1#![allow(non_snake_case)]
2
3use std::sync::Arc;
6
7use serde_json::{Value, json};
8
9use crate::RunTime::ApplicationRunTime::ApplicationRunTime;
10
11pub 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
17pub 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
23pub 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
30pub 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
37pub 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
49pub async fn handle_history_clear(Runtime:Arc<ApplicationRunTime>) -> Result<Value, String> {
51 Runtime.Environment.ApplicationState.Feature.NavigationHistory.Clear();
52 Ok(Value::Null)
53}
54
55pub 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}