Skip to content

Commit 7d0e7cd

Browse files
authored
fix: unregister ext hotkey when it gets deleted (#770)
This commit fixes the bug that when an extension gets uninstalled, its registered hotkey won't be cleared.
1 parent e56d6b1 commit 7d0e7cd

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

  • docs/content.en/docs/release-notes
  • src-tauri/src/extension/third_party

docs/content.en/docs/release-notes/_index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Information about release notes of Coco Server is provided here.
2323
- fix(file search): apply filters before from/size parameters #741
2424
- fix(file search): searching by name&content does not search file name #743
2525
- fix: prevent window from hiding when moved on Windows #748
26+
- fix: unregister ext hotkey when it gets deleted #770
2627

2728
### ✈️ Improvements
2829

src-tauri/src/extension/third_party/mod.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use super::alter_extension_json_file;
44
use super::canonicalize_relative_icon_path;
55
use super::Extension;
66
use super::ExtensionType;
7-
use crate::util::platform::Platform;
87
use super::LOCAL_QUERY_SOURCE_TYPE;
98
use super::PLUGIN_JSON_FILE_NAME;
109
use crate::common::document::open;
@@ -16,6 +15,7 @@ use crate::common::search::QuerySource;
1615
use crate::common::search::SearchQuery;
1716
use crate::common::traits::SearchSource;
1817
use crate::extension::ExtensionBundleIdBorrowed;
18+
use crate::util::platform::Platform;
1919
use crate::GLOBAL_TAURI_APP_HANDLE;
2020
use async_trait::async_trait;
2121
use borrowme::ToOwned;
@@ -48,7 +48,6 @@ pub(crate) static THIRD_PARTY_EXTENSIONS_DIRECTORY: LazyLock<PathBuf> = LazyLock
4848
app_data_dir
4949
});
5050

51-
5251
pub(crate) async fn list_third_party_extensions(
5352
directory: &Path,
5453
) -> Result<(bool, Vec<Extension>), String> {
@@ -810,7 +809,7 @@ impl ThirdPartyExtensionsSearchSource {
810809
}
811810

812811
/// Remove `extension` from the **in-memory** extension list.
813-
pub(crate) async fn remove_extension(&self, developer: &str, extension_id: &str) {
812+
pub(crate) async fn remove_extension(&self, developer: &str, extension_id: &str) -> Extension {
814813
let mut write_lock_guard = self.inner.extensions.write().await;
815814
let Some(index) = write_lock_guard
816815
.iter()
@@ -822,7 +821,7 @@ impl ThirdPartyExtensionsSearchSource {
822821
);
823822
};
824823

825-
write_lock_guard.remove(index);
824+
write_lock_guard.remove(index)
826825
}
827826
}
828827

@@ -1044,7 +1043,6 @@ fn calculate_text_similarity(query: &str, text: &str) -> Option<f64> {
10441043
}
10451044
}
10461045

1047-
10481046
#[tauri::command]
10491047
pub(crate) async fn uninstall_extension(
10501048
developer: String,
@@ -1066,12 +1064,19 @@ pub(crate) async fn uninstall_extension(
10661064
.await
10671065
.map_err(|e| e.to_string())?;
10681066

1069-
THIRD_PARTY_EXTENSIONS_SEARCH_SOURCE
1067+
let extension = THIRD_PARTY_EXTENSIONS_SEARCH_SOURCE
10701068
.get()
10711069
.unwrap()
10721070
.remove_extension(&developer, &extension_id)
10731071
.await;
10741072

1073+
// Unregister the extension hotkey, if set.
1074+
//
1075+
// Unregistering hotkey is the only thing that we will do when we disable
1076+
// an extension, so we directly use this function here even though "disabling"
1077+
// the extension that one is trying to uninstall does not make too much sense.
1078+
ThirdPartyExtensionsSearchSource::_disable_extension(&extension).await?;
1079+
10751080
Ok(())
10761081
}
10771082

0 commit comments

Comments
 (0)