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