@@ -19,24 +19,51 @@ impl PluginService {
1919 }
2020 }
2121
22+ fn resolve_resource_dir ( app : & AppHandle , candidates : & [ & str ] , marker : & str ) -> Option < PathBuf > {
23+ for candidate in candidates {
24+ let Ok ( path) = app
25+ . path ( )
26+ . resolve ( candidate, tauri:: path:: BaseDirectory :: Resource )
27+ else {
28+ continue ;
29+ } ;
30+
31+ if path. join ( marker) . is_file ( ) {
32+ log:: info!( "Resolved resource dir '{}' to {:?}" , candidate, path) ;
33+ return Some ( path) ;
34+ }
35+ }
36+
37+ None
38+ }
39+
40+ fn resolve_resource_file ( app : & AppHandle , candidates : & [ & str ] ) -> Option < PathBuf > {
41+ for candidate in candidates {
42+ let Ok ( path) = app
43+ . path ( )
44+ . resolve ( candidate, tauri:: path:: BaseDirectory :: Resource )
45+ else {
46+ continue ;
47+ } ;
48+
49+ if path. is_file ( ) {
50+ log:: info!( "Resolved resource file '{}' to {:?}" , candidate, path) ;
51+ return Some ( path) ;
52+ }
53+ }
54+
55+ None
56+ }
57+
2258 fn resolve_builtin_dir ( app : & AppHandle ) -> Option < PathBuf > {
23- let resource = app
24- . path ( )
25- . resolve (
26- "resources/plugins/builtin" ,
27- tauri:: path:: BaseDirectory :: Resource ,
28- )
29- . ok ( )
30- . filter ( |p| p. join ( "index.json" ) . is_file ( ) )
31- . or_else ( || {
32- app. path ( )
33- . resolve ( "plugins/builtin" , tauri:: path:: BaseDirectory :: Resource )
34- . ok ( )
35- . filter ( |p| p. join ( "index.json" ) . is_file ( ) )
36- } ) ;
37-
38- if resource. is_some ( ) {
39- return resource;
59+ let resource = Self :: resolve_resource_dir (
60+ app,
61+ & [ "resources/plugins/builtin" , "plugins/builtin" , "builtin" ] ,
62+ "index.json" ,
63+ ) ;
64+
65+ if let Some ( path) = resource {
66+ return Some ( path) ;
4067 }
4168
4269 let cwd = std:: env:: current_dir ( ) . unwrap_or_else ( |_| PathBuf :: from ( "." ) ) ;
@@ -45,40 +72,43 @@ impl PluginService {
4572 cwd. join ( "../plugins/builtin" ) ,
4673 cwd. join ( "../../plugins/builtin" ) ,
4774 ] ;
48- candidates
75+ let resolved = candidates
4976 . into_iter ( )
50- . find ( |p| p. join ( "index.json" ) . is_file ( ) )
77+ . find ( |p| p. join ( "index.json" ) . is_file ( ) ) ;
78+
79+ if let Some ( path) = resolved. as_ref ( ) {
80+ log:: info!( "Resolved builtin plugins from cwd fallback: {:?}" , path) ;
81+ }
82+
83+ resolved
5184 }
5285
5386 fn resolve_defaults_path ( app : & AppHandle ) -> Option < PathBuf > {
54- let resource = app
55- . path ( )
56- . resolve (
87+ let resource = Self :: resolve_resource_file (
88+ app ,
89+ & [
5790 "resources/plugins/plugins-state.defaults.json" ,
58- tauri:: path:: BaseDirectory :: Resource ,
59- )
60- . ok ( )
61- . filter ( |p| p. is_file ( ) )
62- . or_else ( || {
63- app. path ( )
64- . resolve (
65- "plugins/plugins-state.defaults.json" ,
66- tauri:: path:: BaseDirectory :: Resource ,
67- )
68- . ok ( )
69- . filter ( |p| p. is_file ( ) )
70- } ) ;
71-
72- if resource. is_some ( ) {
73- return resource;
91+ "plugins/plugins-state.defaults.json" ,
92+ "plugins-state.defaults.json" ,
93+ ] ,
94+ ) ;
95+
96+ if let Some ( path) = resource {
97+ return Some ( path) ;
7498 }
7599
76100 let cwd = std:: env:: current_dir ( ) . unwrap_or_else ( |_| PathBuf :: from ( "." ) ) ;
77101 let candidates = [
78102 cwd. join ( "plugins/plugins-state.defaults.json" ) ,
79103 cwd. join ( "../plugins/plugins-state.defaults.json" ) ,
80104 ] ;
81- candidates. into_iter ( ) . find ( |p| p. is_file ( ) )
105+ let resolved = candidates. into_iter ( ) . find ( |p| p. is_file ( ) ) ;
106+
107+ if let Some ( path) = resolved. as_ref ( ) {
108+ log:: info!( "Resolved plugin defaults from cwd fallback: {:?}" , path) ;
109+ }
110+
111+ resolved
82112 }
83113
84114 fn read_json ( path : & Path ) -> Result < Value , String > {
@@ -95,7 +125,10 @@ impl PluginService {
95125
96126 let mut changed = false ;
97127 if Self :: os_key ( ) != "windows" {
98- if let Some ( selections) = state_obj. get_mut ( "selections" ) . and_then ( |v| v. as_object_mut ( ) ) {
128+ if let Some ( selections) = state_obj
129+ . get_mut ( "selections" )
130+ . and_then ( |v| v. as_object_mut ( ) )
131+ {
99132 for key in [ "terminal:ssh" , "terminal:telnet" ] {
100133 if selections. get ( key) . and_then ( |v| v. as_str ( ) ) == Some ( "builtin.putty" ) {
101134 selections. remove ( key) ;
@@ -105,6 +138,24 @@ impl PluginService {
105138 }
106139 }
107140
141+ if Self :: os_key ( ) == "linux" {
142+ if let Some ( selections) = state_obj
143+ . get_mut ( "selections" )
144+ . and_then ( |v| v. as_object_mut ( ) )
145+ {
146+ match selections. get ( "remotedesktop:rdp" ) . and_then ( |v| v. as_str ( ) ) {
147+ Some ( "builtin.mstsc" ) | Some ( "builtin.remmina" ) => {
148+ selections. insert (
149+ "remotedesktop:rdp" . to_string ( ) ,
150+ Value :: String ( "builtin.xfreerdp" . to_string ( ) ) ,
151+ ) ;
152+ changed = true ;
153+ }
154+ _ => { }
155+ }
156+ }
157+ }
158+
108159 let should_remove_sftp_iterm = state_obj
109160 . get ( "selections" )
110161 . and_then ( |v| v. get ( "filetransfer:sftp" ) )
@@ -120,7 +171,9 @@ impl PluginService {
120171 . and_then ( |v| v. get ( "builtin.iterm-sftp" ) )
121172 . and_then ( |v| v. as_object ( ) )
122173 . map ( |obj| {
123- obj. get ( "enabled" ) . and_then ( |v| v. as_bool ( ) ) . unwrap_or ( false )
174+ obj. get ( "enabled" )
175+ . and_then ( |v| v. as_bool ( ) )
176+ . unwrap_or ( false )
124177 || obj
125178 . get ( "path" )
126179 . and_then ( |v| v. as_str ( ) )
@@ -133,7 +186,10 @@ impl PluginService {
133186 return changed;
134187 }
135188
136- if let Some ( selections) = state_obj. get_mut ( "selections" ) . and_then ( |v| v. as_object_mut ( ) ) {
189+ if let Some ( selections) = state_obj
190+ . get_mut ( "selections" )
191+ . and_then ( |v| v. as_object_mut ( ) )
192+ {
137193 if selections. remove ( "filetransfer:sftp" ) . is_some ( ) {
138194 changed = true ;
139195 }
0 commit comments