1
1
use std:: collections:: HashMap ;
2
2
3
- use crate :: { app:: AppState , errors} ;
3
+ use crate :: { app:: AppState , errors, template } ;
4
4
5
5
pub struct Package {
6
6
pub name : String ,
@@ -13,30 +13,31 @@ pub struct Package {
13
13
pub authors : Vec < String > ,
14
14
}
15
15
16
- #[ derive( Debug , Clone , serde:: Serialize , serde:: Deserialize ) ]
17
- #[ serde( rename_all = "camelCase" ) ]
18
- pub struct PackageManagerEditorManifest {
19
- pub schema_version : u64 ,
20
- pub packages : HashMap < String , PackageManagerEditorManifestPackage > ,
21
- pub metadata_package_name : String
22
- }
23
-
24
- #[ derive( Debug , Clone , serde:: Serialize , serde:: Deserialize ) ]
25
- #[ serde( rename_all = "camelCase" ) ]
26
- pub struct PackageManagerEditorManifestPackage {
27
- pub is_discoverable : Option < bool > ,
28
- pub must_be_bundled : Option < bool > ,
29
- pub version : Option < String > ,
30
- pub minimum_version : Option < String > ,
31
- pub deprecated : Option < String > ,
32
- pub remove_on_project_upgrade : Option < bool > ,
33
- pub is_file : Option < bool >
34
- }
16
+ // #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
17
+ // #[serde(rename_all = "camelCase")]
18
+ // pub struct PackageManagerEditorManifest {
19
+ // pub schema_version: u64,
20
+ // pub packages: HashMap<String, PackageManagerEditorManifestPackage>,
21
+ // pub metadata_package_name: String
22
+ // }
23
+
24
+ // #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
25
+ // #[serde(rename_all = "camelCase")]
26
+ // pub struct PackageManagerEditorManifestPackage {
27
+ // pub is_discoverable: Option<bool>,
28
+ // pub must_be_bundled: Option<bool>,
29
+ // pub version: Option<String>,
30
+ // pub minimum_version: Option<String>,
31
+ // pub deprecated: Option<String>,
32
+ // pub remove_on_project_upgrade: Option<bool>,
33
+ // pub is_file: Option<bool>
34
+ // }
35
35
36
36
#[ derive( Debug , Clone , serde:: Serialize , serde:: Deserialize , PartialEq , Eq ) ]
37
37
#[ serde( rename_all = "camelCase" ) ]
38
38
pub enum PackageType {
39
39
Internal ,
40
+ Default ,
40
41
Git ,
41
42
Local
42
43
}
@@ -46,71 +47,71 @@ pub enum PackageType {
46
47
pub struct MinimalPackage {
47
48
pub name : String ,
48
49
pub version : String ,
49
- pub is_file : bool ,
50
+ // pub is_file: bool,
50
51
pub is_discoverable : bool ,
51
52
pub _type : PackageType
52
53
}
53
54
54
- pub fn get_editor_package_manager_manifest ( editor_version : String , app_state : & tauri:: State < AppState > ) -> Result < PackageManagerEditorManifest , errors:: AnyError > {
55
- let editor = app_state. editors . lock ( )
56
- . map_err ( |_| errors:: str_error ( "Failed to get editors. Is it locked?" ) ) ?
57
- . iter ( )
58
- . find ( |x| x. version == editor_version)
59
- . ok_or ( errors:: str_error ( "Invalid editor version" ) ) ?
60
- . clone ( ) ;
61
-
62
- let root_path = crate :: editor:: get_root_folder ( editor. exe_path . clone ( ) ) ;
63
- let manifest_folder_path = crate :: editor:: get_package_manager_folder ( & editor) ?;
64
- let manifest_folder_path = manifest_folder_path
65
- . join ( "Editor" ) ;
66
-
67
- let manifest_path = manifest_folder_path
68
- . join ( "manifest" )
69
- . with_extension ( "json" ) ;
70
-
71
- if !manifest_path. exists ( ) {
72
- return Err ( errors:: io_not_found ( "Invalid manifest path" ) ) ;
73
- }
74
-
75
- let manifest_contents = std:: fs:: read_to_string ( & manifest_path)
76
- . map_err ( |_| errors:: io_not_found ( "Invalid manifest file" ) ) ?;
77
-
78
- let mut manifest: PackageManagerEditorManifest = serde_json:: from_str ( & manifest_contents)
79
- . map_err ( |_| errors:: io_not_found ( "Invalid manifest file" ) ) ?;
80
-
81
- let files = std:: fs:: read_dir ( & manifest_folder_path)
82
- . map_err ( |_| errors:: io_not_found ( "Invalid manifest file" ) ) ?
83
- . filter_map ( |x| x. ok ( ) )
84
- . filter_map ( |x| x. file_name ( ) . to_str ( ) . map ( |x| x. to_string ( ) ) )
85
- . collect :: < Vec < _ > > ( ) ;
86
-
87
- for ( key, package) in manifest. packages . iter_mut ( ) {
88
- let version = package. version . clone ( ) ;
89
- if let Some ( version) = version {
90
- package. is_file = Some ( files. contains ( & format ! ( "{}-{}.tgz" , & key, version) ) ) ;
91
- } else {
92
- package. is_file = None ;
93
- }
94
- }
95
-
96
- Ok ( manifest)
97
- }
55
+ // pub fn get_editor_package_manager_manifest(editor_version: String, app_state: &tauri::State<AppState>) -> Result<PackageManagerEditorManifest, errors::AnyError> {
56
+ // let editor = app_state.editors.lock()
57
+ // .map_err(|_| errors::str_error("Failed to get editors. Is it locked?"))?
58
+ // .iter()
59
+ // .find(|x| x.version == editor_version)
60
+ // .ok_or(errors::str_error("Invalid editor version"))?
61
+ // .clone();
62
+
63
+ // let root_path = crate::editor::get_root_folder(editor.exe_path.clone());
64
+ // let manifest_folder_path = crate::editor::get_package_manager_folder(&editor)?;
65
+ // let manifest_folder_path = manifest_folder_path
66
+ // .join("Editor");
67
+
68
+ // let manifest_path = manifest_folder_path
69
+ // .join("manifest")
70
+ // .with_extension("json");
71
+
72
+ // if !manifest_path.exists() {
73
+ // return Err(errors::io_not_found("Invalid manifest path"));
74
+ // }
75
+
76
+ // let manifest_contents = std::fs::read_to_string(&manifest_path)
77
+ // .map_err(|_| errors::io_not_found("Invalid manifest file"))?;
78
+
79
+ // let mut manifest: PackageManagerEditorManifest = serde_json::from_str(&manifest_contents)
80
+ // .map_err(|_| errors::io_not_found("Invalid manifest file"))?;
81
+
82
+ // let files = std::fs::read_dir(&manifest_folder_path)
83
+ // .map_err(|_| errors::io_not_found("Invalid manifest file"))?
84
+ // .filter_map(|x| x.ok())
85
+ // .filter_map(|x| x.file_name().to_str().map(|x| x.to_string()))
86
+ // .collect::<Vec<_>>();
87
+
88
+ // for (key, package) in manifest.packages.iter_mut() {
89
+ // let version = package.version.clone();
90
+ // if let Some(version) = version {
91
+ // package.is_file = Some(files.contains(&format!("{}-{}.tgz", &key, version)));
92
+ // } else {
93
+ // package.is_file = None;
94
+ // }
95
+ // }
96
+
97
+ // Ok(manifest)
98
+ // }
98
99
99
100
// commands
100
101
101
102
// need to override versions with current template versions
102
103
#[ tauri:: command]
103
104
pub fn cmd_get_default_editor_packages ( editor_version : String , app_state : tauri:: State < AppState > ) -> Result < Vec < MinimalPackage > , errors:: AnyError > {
104
- let manifest = get_editor_package_manager_manifest ( editor_version, & app_state) ?;
105
+ let manifest = crate :: editor :: read_package_manager_manifest ( editor_version, & app_state) ?;
105
106
let mut manifest_packages = manifest. packages
106
107
. iter ( )
107
108
// .filter(|x| x.1.is_discoverable == Some(true))
108
109
. map ( |x| MinimalPackage {
109
110
name : x. 0 . clone ( ) ,
110
111
version : x. 1 . version . clone ( ) . unwrap_or_default ( ) ,
111
- is_file : x. 1 . is_file . unwrap_or ( false ) ,
112
+ // is_file: x.1.is_file.unwrap_or(false),
112
113
is_discoverable : x. 1 . is_discoverable . unwrap_or ( false ) ,
113
- _type : PackageType :: Internal
114
+ _type : x . 1 . is_default . unwrap_or ( false ) . then ( || PackageType :: Default ) . unwrap_or ( PackageType :: Internal )
114
115
} )
115
116
. collect :: < Vec < _ > > ( ) ;
116
117
0 commit comments