Mountain/IPC/WindServiceAdapters/
WindServiceAdapter.rs1#![allow(non_snake_case)]
2
3use std::sync::Arc;
11
12use CommonLibrary::{
13 Configuration::ConfigurationProvider::ConfigurationProvider,
14 Environment::Requires::Requires,
15 FileSystem::{FileSystemReader::FileSystemReader, FileSystemWriter::FileSystemWriter},
16 Storage::StorageProvider::StorageProvider,
17};
18
19use crate::{
20 IPC::WindServiceAdapters::{
21 MountainSandboxConfiguration::Struct as MountainSandboxConfiguration,
22 OsInfo::Struct as OsInfo,
23 Profiles::Struct as Profiles,
24 WindConfigurationService::Struct as WindConfigurationService,
25 WindDesktopConfiguration::Struct as WindDesktopConfiguration,
26 WindEnvironmentService::Struct as WindEnvironmentService,
27 WindFileService::Struct as WindFileService,
28 WindStorageService::Struct as WindStorageService,
29 },
30 RunTime::ApplicationRunTime::ApplicationRunTime,
31 dev_log,
32};
33
34pub struct Struct {
35 pub(super) runtime:Arc<ApplicationRunTime>,
36}
37
38impl Struct {
39 pub fn new(runtime:Arc<ApplicationRunTime>) -> Self {
40 dev_log!("ipc", "[WindServiceAdapters] Creating Wind service adapter");
41
42 Self { runtime }
43 }
44
45 pub async fn convert_to_wind_configuration(
46 &self,
47
48 mountain_config:serde_json::Value,
49 ) -> Result<WindDesktopConfiguration, String> {
50 dev_log!("ipc", "[WindServiceAdapters] Converting Mountain config to Wind config");
51
52 let config:MountainSandboxConfiguration = serde_json::from_value(mountain_config)
53 .map_err(|e| format!("Failed to parse Mountain configuration: {}", e))?;
54
55 Ok(WindDesktopConfiguration {
56 window_id:config.window_id.parse().unwrap_or(1),
57 app_root:config.app_root,
58 user_data_path:config.user_data_dir,
59 temp_path:config.tmp_dir,
60 log_level:config.log_level.to_string(),
61 is_packaged:config.product_configuration.is_packaged,
62 tauri_version:config.versions.mountain,
63 platform:config.platform,
64 arch:config.arch,
65 workspace:None,
66 files_to_open_or_create:None,
67 files_to_diff:None,
68 files_to_wait:None,
69 fullscreen:Some(false),
70 zoom_level:Some(config.zoom_level),
71 is_custom_zoom_level:Some(false),
72 profiles:Profiles { all:vec![], home:config.home_dir, profile:serde_json::Value::Null },
73 policies_data:None,
74 loggers:vec![],
75 backup_path:Some(config.backup_path),
76 disable_layout_restore:Some(false),
77 os:OsInfo { release:std::env::consts::OS.to_string() },
78 })
79 }
80
81 pub async fn get_environment_service(&self) -> Result<WindEnvironmentService, String> {
82 dev_log!("ipc", "[WindServiceAdapters] Getting Wind environment service");
83
84 Ok(WindEnvironmentService::new())
85 }
86
87 pub async fn get_file_service(&self) -> Result<WindFileService, String> {
88 dev_log!("ipc", "[WindServiceAdapters] Getting Wind file service");
89
90 let file_system_reader:Arc<dyn FileSystemReader> = self.runtime.Environment.Require();
91
92 let file_system_writer:Arc<dyn FileSystemWriter> = self.runtime.Environment.Require();
93
94 Ok(WindFileService::new(file_system_reader, file_system_writer))
95 }
96
97 pub async fn get_storage_service(&self) -> Result<WindStorageService, String> {
98 dev_log!("ipc", "[WindServiceAdapters] Getting Wind storage service");
99
100 let storage:Arc<dyn StorageProvider> = self.runtime.Environment.Require();
101
102 Ok(WindStorageService::new(storage))
103 }
104
105 pub async fn get_configuration_service(&self) -> Result<WindConfigurationService, String> {
106 dev_log!("ipc", "[WindServiceAdapters] Getting Wind configuration service");
107
108 let config:Arc<dyn ConfigurationProvider> = self.runtime.Environment.Require();
109
110 Ok(WindConfigurationService::new(config))
111 }
112}