Skip to content

Commit bcafdc7

Browse files
Legend-MasterKokoro2336
authored andcommitted
Clean up
1 parent fa4ba89 commit bcafdc7

1 file changed

Lines changed: 21 additions & 29 deletions

File tree

plugins/recent-doc/src/commands.rs

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub(crate) fn add_recent_document<R: Runtime>(app: AppHandle<R>, _path: &str) ->
5858
unsafe {
5959
let _com_guard = ComGuard::new();
6060

61-
let app_id = app.config().identifier.clone();
61+
let app_id = &app.config().identifier;
6262
let app_id_hstring = HSTRING::from(app_id);
6363

6464
let path_hstring = HSTRING::from(_path);
@@ -97,17 +97,13 @@ pub(crate) fn clear_recent_documents<R: Runtime>(_app: AppHandle<R>) -> Result<(
9797
unsafe {
9898
let _guard = ComGuard::new();
9999

100-
let app_id = _app.config().identifier.clone();
100+
let app_id = &_app.config().identifier;
101101
let app_id_hstring = HSTRING::from(app_id);
102102

103-
if let Ok(dests) = CoCreateInstance::<_, IApplicationDestinations>(
104-
&ApplicationDestinations as *const _,
105-
None,
106-
CLSCTX_INPROC_SERVER,
107-
) {
108-
let _ = dests.SetAppID(PCWSTR::from_raw(app_id_hstring.as_ptr()));
109-
let _ = dests.RemoveAllDestinations();
110-
}
103+
let dests: IApplicationDestinations =
104+
CoCreateInstance(&ApplicationDestinations, None, CLSCTX_INPROC_SERVER)?;
105+
let _ = dests.SetAppID(PCWSTR::from_raw(app_id_hstring.as_ptr()));
106+
let _ = dests.RemoveAllDestinations();
111107
}
112108

113109
#[cfg(target_os = "macos")]
@@ -134,30 +130,26 @@ pub(crate) fn get_recent_documents<R: Runtime>(_app: AppHandle<R>) -> Result<Vec
134130
unsafe {
135131
let _guard = ComGuard::new();
136132

137-
let app_id = _app.config().identifier.clone();
133+
let app_id = &_app.config().identifier;
138134
let app_id_hstring = HSTRING::from(app_id);
139135
let app_id_pcwstr = PCWSTR::from_raw(app_id_hstring.as_ptr());
140136

141-
if let Ok(doc_lists) = CoCreateInstance::<_, IApplicationDocumentLists>(
142-
&ApplicationDocumentLists,
143-
None,
144-
CLSCTX_INPROC_SERVER,
145-
) {
146-
let _ = doc_lists.SetAppID(app_id_pcwstr);
147-
if let Ok(obj_array) = doc_lists.GetList::<IObjectArray>(ADLT_RECENT, 30) {
148-
let count = obj_array.GetCount().unwrap_or(0);
149-
150-
for i in 0..count {
151-
if let Ok(shell_item) = obj_array.GetAt::<IShellItem>(i) {
152-
if let Ok(name_pwstr) = shell_item.GetDisplayName(SIGDN_FILESYSPATH) {
153-
if let Ok(path) = name_pwstr.to_string() {
154-
if !path.is_empty() {
155-
recent_docs.push(path);
156-
}
137+
let doc_lists: IApplicationDocumentLists =
138+
CoCreateInstance(&ApplicationDocumentLists, None, CLSCTX_INPROC_SERVER)?;
139+
let _ = doc_lists.SetAppID(app_id_pcwstr);
140+
if let Ok(obj_array) = doc_lists.GetList::<IObjectArray>(ADLT_RECENT, 30) {
141+
let count = obj_array.GetCount().unwrap_or(0);
142+
143+
for i in 0..count {
144+
if let Ok(shell_item) = obj_array.GetAt::<IShellItem>(i) {
145+
if let Ok(name_pwstr) = shell_item.GetDisplayName(SIGDN_FILESYSPATH) {
146+
if let Ok(path) = name_pwstr.to_string() {
147+
if !path.is_empty() {
148+
recent_docs.push(path);
157149
}
158-
159-
CoTaskMemFree(Some(name_pwstr.as_ptr() as *const core::ffi::c_void));
160150
}
151+
152+
CoTaskMemFree(Some(name_pwstr.as_ptr() as *const core::ffi::c_void));
161153
}
162154
}
163155
}

0 commit comments

Comments
 (0)