22// SPDX-License-Identifier: Apache-2.0
33// SPDX-License-Identifier: MIT
44
5- use crate :: error:: { Error , Result } ;
5+ use crate :: error:: Result ;
66use tauri:: command;
77
88#[ command]
99/// add recent
1010pub ( crate ) fn add_recent_document ( _path : & str ) -> Result < ( ) > {
1111 #[ cfg( target_os = "windows" ) ]
1212 {
13- use std:: mem:: ManuallyDrop ;
1413 use windows:: {
1514 core:: HSTRING ,
1615 Win32 :: UI :: Shell :: { SHAddToRecentDocs , SHARD_PATHW } ,
@@ -27,25 +26,20 @@ pub(crate) fn add_recent_document(_path: &str) -> Result<()> {
2726
2827 #[ cfg( target_os = "macos" ) ]
2928 {
30- use objc2:: rc:: Id ;
3129 use objc2:: MainThreadMarker ;
3230 use objc2_app_kit:: NSDocumentController ;
3331 use objc2_foundation:: { NSString , NSURL } ;
3432
35- unsafe {
36- let ns_path = NSURL :: fileURLWithPath ( & NSString :: from_str ( _path) ) ;
37- let mtm =
38- MainThreadMarker :: new ( ) . expect ( "AppKit API must be called on the main thread" ) ;
39- let controller: Id < NSDocumentController > =
40- NSDocumentController :: sharedDocumentController ( mtm) ;
41- controller. noteNewRecentDocumentURL ( & ns_path) ;
42- }
33+ let ns_path = NSURL :: fileURLWithPath ( & NSString :: from_str ( _path) ) ;
34+ let mtm = MainThreadMarker :: new ( ) . expect ( "AppKit API must be called on the main thread" ) ;
35+ let controller = NSDocumentController :: sharedDocumentController ( mtm) ;
36+ controller. noteNewRecentDocumentURL ( & ns_path) ;
4337 }
4438
4539 #[ cfg( unix) ]
4640 {
4741 // Recent documents are not supported on Unix-like systems.
48- Err ( Error :: UnsupportedPlatform (
42+ Err ( crate :: error :: Error :: UnsupportedPlatform (
4943 "Recent documents are not supported on Unix-like systems." . to_string ( ) ,
5044 ) ) ?;
5145 }
@@ -65,23 +59,21 @@ pub(crate) fn clear_recent_documents() -> Result<()> {
6559
6660 #[ cfg( target_os = "macos" ) ]
6761 {
68- use objc2:: rc:: Id ;
6962 use objc2:: MainThreadMarker ;
7063 use objc2_app_kit:: NSDocumentController ;
7164
7265 unsafe {
7366 let mtm =
7467 MainThreadMarker :: new ( ) . expect ( "AppKit API must be called on the main thread" ) ;
75- let controller: Id < NSDocumentController > =
76- NSDocumentController :: sharedDocumentController ( mtm) ;
68+ let controller = NSDocumentController :: sharedDocumentController ( mtm) ;
7769 controller. clearRecentDocuments ( None ) ;
7870 }
7971 }
8072
8173 #[ cfg( unix) ]
8274 {
8375 // Recent documents are not supported on Unix-like systems.
84- Err ( Error :: UnsupportedPlatform (
76+ Err ( crate :: error :: Error :: UnsupportedPlatform (
8577 "Recent documents are not supported on Unix-like systems." . to_string ( ) ,
8678 ) ) ?;
8779 }
@@ -97,7 +89,7 @@ pub(crate) fn get_recent_documents() -> Result<Vec<String>> {
9789 #[ cfg( target_os = "windows" ) ]
9890 {
9991 use std:: fs;
100- use std:: path:: { Path , PathBuf } ;
92+ use std:: path:: PathBuf ;
10193 use windows:: {
10294 core:: PWSTR ,
10395 Win32 :: System :: Com :: CoTaskMemFree ,
@@ -133,30 +125,24 @@ pub(crate) fn get_recent_documents() -> Result<Vec<String>> {
133125
134126 #[ cfg( target_os = "macos" ) ]
135127 {
136- use objc2:: rc:: Id ;
137128 use objc2:: MainThreadMarker ;
138129 use objc2_app_kit:: NSDocumentController ;
139- use objc2_foundation:: { NSArray , NSString } ;
140130
141- unsafe {
142- let mtm =
143- MainThreadMarker :: new ( ) . expect ( "AppKit API must be called on the main thread" ) ;
144- let controller: Id < NSDocumentController > =
145- NSDocumentController :: sharedDocumentController ( mtm) ;
146- let urls = controller. recentDocumentURLs ( ) ;
131+ let mtm = MainThreadMarker :: new ( ) . expect ( "AppKit API must be called on the main thread" ) ;
132+ let controller = NSDocumentController :: sharedDocumentController ( mtm) ;
133+ let urls = controller. recentDocumentURLs ( ) ;
147134
148- for url in & * urls {
149- if let Some ( ns_path) = url. path ( ) {
150- recent_docs. push ( ns_path. to_string ( ) ) ;
151- }
135+ for url in & * urls {
136+ if let Some ( ns_path) = url. path ( ) {
137+ recent_docs. push ( ns_path. to_string ( ) ) ;
152138 }
153139 }
154140 }
155141
156142 #[ cfg( unix) ]
157143 {
158144 // Recent documents are not supported on Unix-like systems.
159- Err ( Error :: UnsupportedPlatform (
145+ Err ( crate :: error :: Error :: UnsupportedPlatform (
160146 "Recent documents are not supported on Unix-like systems." . to_string ( ) ,
161147 ) ) ?;
162148 }
@@ -166,11 +152,9 @@ pub(crate) fn get_recent_documents() -> Result<Vec<String>> {
166152
167153#[ cfg( target_os = "windows" ) ]
168154fn resolve_shortcut ( lnk_path : & std:: path:: Path ) -> Result < String > {
169- use std:: path:: { Path , PathBuf } ;
170155 use windows:: {
171156 core:: { Interface , HSTRING , PWSTR } ,
172157 Win32 :: Foundation :: MAX_PATH ,
173- Win32 :: Storage :: FileSystem :: WIN32_FIND_DATAW ,
174158 Win32 :: System :: Com :: { CoCreateInstance , IPersistFile , CLSCTX_INPROC_SERVER , STGM_READ } ,
175159 Win32 :: UI :: Shell :: { IShellLinkW , ShellLink } ,
176160 } ;
0 commit comments