@@ -37,6 +37,127 @@ pub fn show_main_window<R: Runtime>(window: Window<R>) -> Result<(), String> {
3737 window. show ( ) . map_err ( |e| e. to_string ( ) )
3838}
3939
40+ /// Toggle hidden files visibility - updates menu checkbox and emits event.
41+ /// This is used by the command palette to sync with menu state.
42+ #[ tauri:: command]
43+ pub fn toggle_hidden_files < R : Runtime > ( app : AppHandle < R > ) -> Result < bool , String > {
44+ let menu_state = app. state :: < MenuState < R > > ( ) ;
45+ let guard = menu_state. show_hidden_files . lock ( ) . unwrap ( ) ;
46+ let Some ( check_item) = guard. as_ref ( ) else {
47+ return Err ( "Menu not initialized" . to_string ( ) ) ;
48+ } ;
49+
50+ // Get current state and toggle it
51+ let current = check_item. is_checked ( ) . unwrap_or ( false ) ;
52+ let new_state = !current;
53+ check_item. set_checked ( new_state) . map_err ( |e| e. to_string ( ) ) ?;
54+
55+ // Emit event to frontend with the new state
56+ app. emit ( "settings-changed" , serde_json:: json!( { "showHiddenFiles" : new_state } ) )
57+ . map_err ( |e| e. to_string ( ) ) ?;
58+
59+ Ok ( new_state)
60+ }
61+
62+ /// Set view mode - updates menu radio buttons and emits event.
63+ /// This is used by the command palette to sync with menu state.
64+ #[ tauri:: command]
65+ pub fn set_view_mode < R : Runtime > ( app : AppHandle < R > , mode : String ) -> Result < ( ) , String > {
66+ let menu_state = app. state :: < MenuState < R > > ( ) ;
67+ let full_guard = menu_state. view_mode_full . lock ( ) . unwrap ( ) ;
68+ let brief_guard = menu_state. view_mode_brief . lock ( ) . unwrap ( ) ;
69+
70+ let ( Some ( full_item) , Some ( brief_item) ) = ( full_guard. as_ref ( ) , brief_guard. as_ref ( ) ) else {
71+ return Err ( "Menu not initialized" . to_string ( ) ) ;
72+ } ;
73+
74+ // Set the correct check state (radio behavior)
75+ let is_full = mode == "full" ;
76+ full_item. set_checked ( is_full) . map_err ( |e| e. to_string ( ) ) ?;
77+ brief_item. set_checked ( !is_full) . map_err ( |e| e. to_string ( ) ) ?;
78+
79+ // Emit event to frontend
80+ app. emit ( "view-mode-changed" , serde_json:: json!( { "mode" : mode } ) )
81+ . map_err ( |e| e. to_string ( ) ) ?;
82+
83+ Ok ( ( ) )
84+ }
85+
86+ // ============================================================================
87+ // Direct file action commands (for command palette and other invocations)
88+ // ============================================================================
89+
90+ /// Show a file in Finder (reveal in parent folder)
91+ #[ tauri:: command]
92+ #[ cfg( target_os = "macos" ) ]
93+ pub fn show_in_finder ( path : String ) -> Result < ( ) , String > {
94+ Command :: new ( "open" )
95+ . arg ( "-R" )
96+ . arg ( & path)
97+ . spawn ( )
98+ . map_err ( |e| e. to_string ( ) ) ?;
99+ Ok ( ( ) )
100+ }
101+
102+ #[ tauri:: command]
103+ #[ cfg( not( target_os = "macos" ) ) ]
104+ pub fn show_in_finder ( _path : String ) -> Result < ( ) , String > {
105+ Err ( "Show in Finder is only available on macOS" . to_string ( ) )
106+ }
107+
108+ /// Copy text to clipboard
109+ #[ tauri:: command]
110+ pub fn copy_to_clipboard < R : Runtime > ( app : AppHandle < R > , text : String ) -> Result < ( ) , String > {
111+ app. clipboard ( ) . write_text ( text) . map_err ( |e| e. to_string ( ) )
112+ }
113+
114+ /// Quick Look preview (macOS only)
115+ #[ tauri:: command]
116+ #[ cfg( target_os = "macos" ) ]
117+ pub fn quick_look ( path : String ) -> Result < ( ) , String > {
118+ Command :: new ( "qlmanage" )
119+ . arg ( "-p" )
120+ . arg ( & path)
121+ . spawn ( )
122+ . map_err ( |e| e. to_string ( ) ) ?;
123+ Ok ( ( ) )
124+ }
125+
126+ #[ tauri:: command]
127+ #[ cfg( not( target_os = "macos" ) ) ]
128+ pub fn quick_look ( _path : String ) -> Result < ( ) , String > {
129+ Err ( "Quick Look is only available on macOS" . to_string ( ) )
130+ }
131+
132+ /// Open Get Info window in Finder (macOS only)
133+ #[ tauri:: command]
134+ #[ cfg( target_os = "macos" ) ]
135+ pub fn get_info ( path : String ) -> Result < ( ) , String > {
136+ // Use AppleScript to open the Get Info window
137+ // The path needs to be escaped for AppleScript
138+ let escaped_path = path. replace ( "\\ " , "\\ \\ " ) . replace ( "\" " , "\\ \" " ) ;
139+ let script = format ! (
140+ r#"tell application "Finder"
141+ activate
142+ open information window of (POSIX file "{}" as alias)
143+ end tell"# ,
144+ escaped_path
145+ ) ;
146+
147+ Command :: new ( "osascript" )
148+ . arg ( "-e" )
149+ . arg ( & script)
150+ . spawn ( )
151+ . map_err ( |e| e. to_string ( ) ) ?;
152+ Ok ( ( ) )
153+ }
154+
155+ #[ tauri:: command]
156+ #[ cfg( not( target_os = "macos" ) ) ]
157+ pub fn get_info ( _path : String ) -> Result < ( ) , String > {
158+ Err ( "Get Info is only available on macOS" . to_string ( ) )
159+ }
160+
40161/// Executes a menu action for the current context.
41162pub fn execute_menu_action < R : Runtime > ( app : & AppHandle < R > , id : & str ) {
42163 let state = app. state :: < MenuState < R > > ( ) ;
@@ -53,7 +174,7 @@ pub fn execute_menu_action<R: Runtime>(app: &AppHandle<R>, id: &str) {
53174 crate :: menu:: SHOW_IN_FINDER_ID => {
54175 #[ cfg( target_os = "macos" ) ]
55176 {
56- let _ = Command :: new ( "open" ) . arg ( "-R" ) . arg ( & context. path ) . spawn ( ) ;
177+ let _ = show_in_finder ( context. path ) ;
57178 }
58179 }
59180 crate :: menu:: COPY_PATH_ID => {
@@ -65,14 +186,14 @@ pub fn execute_menu_action<R: Runtime>(app: &AppHandle<R>, id: &str) {
65186 crate :: menu:: QUICK_LOOK_ID => {
66187 #[ cfg( target_os = "macos" ) ]
67188 {
68- let _ = Command :: new ( "qlmanage" ) . arg ( "-p" ) . arg ( & context. path ) . spawn ( ) ;
189+ let _ = quick_look ( context. path ) ;
69190 }
70191 }
71192 crate :: menu:: GET_INFO_ID => {
72- let _ = app . emit (
73- "menu-action" ,
74- serde_json :: json! ( { "action" : "get-info" , "path" : context. path } ) ,
75- ) ;
193+ # [ cfg ( target_os = "macos" ) ]
194+ {
195+ let _ = get_info ( context. path ) ;
196+ }
76197 }
77198 _ => { }
78199 }
0 commit comments