Skip to content

refactor: optimized some issues with extensions #711

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 46 additions & 37 deletions src-tauri/src/extension/store.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Extension store related stuff.

use crate::extension::canonicalize_relative_icon_path;
use super::LOCAL_QUERY_SOURCE_TYPE;
use crate::common::document::DataSourceReference;
use crate::common::document::Document;
Expand All @@ -9,6 +8,7 @@ use crate::common::search::QueryResponse;
use crate::common::search::QuerySource;
use crate::common::search::SearchQuery;
use crate::common::traits::SearchSource;
use crate::extension::canonicalize_relative_icon_path;
use crate::extension::third_party::THIRD_PARTY_EXTENSIONS_DIRECTORY;
use crate::extension::Extension;
use crate::extension::PLUGIN_JSON_FILE_NAME;
Expand Down Expand Up @@ -104,7 +104,7 @@ pub(crate) async fn search_extension(
};

let response = CLIENT
.get("http://infini.tpddns.cn:27200/store/extension/_search")
.get("https://coco.infini.cloud/store/extension/_search")
.query(&query_params)
.send()
.await
Expand Down Expand Up @@ -238,18 +238,18 @@ pub(crate) async fn install_extension(id: String) -> Result<(), String> {
// Set IDs for commands
// Helper function to set IDs for array fields
fn set_ids_for_field(extension: &mut Json, field_name: &str, counter: &mut i32) {
if let Some(field) = extension.as_object_mut().unwrap().get_mut(field_name) {
if let Some(array) = field.as_array_mut() {
for item in array {
if let Some(item_obj) = item.as_object_mut() {
if !item_obj.contains_key("id") {
item_obj.insert("id".to_string(), Json::String(counter.to_string()));
*counter += 1;
}
if let Some(field) = extension.as_object_mut().unwrap().get_mut(field_name) {
if let Some(array) = field.as_array_mut() {
for item in array {
if let Some(item_obj) = item.as_object_mut() {
if !item_obj.contains_key("id") {
item_obj.insert("id".to_string(), Json::String(counter.to_string()));
*counter += 1;
}
}
}
}
}
}
}
}

// Set IDs for sub-extensions
Expand Down Expand Up @@ -283,37 +283,46 @@ pub(crate) async fn install_extension(id: String) -> Result<(), String> {

// Extract all files except plugin.json
for i in 0..archive.len() {
let mut file = archive.by_index(i).map_err(|e| e.to_string())?;
let outpath = match file.enclosed_name() {
Some(path) => extension_directory.join(path),
None => continue,
};

// Skip the plugin.json file as we'll create it from the extension variable
if file.name() == "plugin.json" {
continue;
}

if file.name().ends_with('/') {
tokio::fs::create_dir_all(&outpath).await.map_err(|e| e.to_string())?;
} else {
if let Some(p) = outpath.parent() {
if !p.exists() {
tokio::fs::create_dir_all(p).await.map_err(|e| e.to_string())?;
}
let mut file = archive.by_index(i).map_err(|e| e.to_string())?;
let outpath = match file.enclosed_name() {
Some(path) => extension_directory.join(path),
None => continue,
};

// Skip the plugin.json file as we'll create it from the extension variable
if file.name() == "plugin.json" {
continue;
}

if file.name().ends_with('/') {
tokio::fs::create_dir_all(&outpath)
.await
.map_err(|e| e.to_string())?;
} else {
if let Some(p) = outpath.parent() {
if !p.exists() {
tokio::fs::create_dir_all(p)
.await
.map_err(|e| e.to_string())?;
}
}
let mut outfile = tokio::fs::File::create(&outpath)
.await
.map_err(|e| e.to_string())?;
let mut content = Vec::new();
std::io::Read::read_to_end(&mut file, &mut content).map_err(|e| e.to_string())?;
tokio::io::AsyncWriteExt::write_all(&mut outfile, &content)
.await
.map_err(|e| e.to_string())?;
}
let mut outfile = tokio::fs::File::create(&outpath).await.map_err(|e| e.to_string())?;
let mut content = Vec::new();
std::io::Read::read_to_end(&mut file, &mut content).map_err(|e| e.to_string())?;
tokio::io::AsyncWriteExt::write_all(&mut outfile, &content).await.map_err(|e| e.to_string())?;
}
}

// Create plugin.json from the extension variable
let plugin_json_path = extension_directory.join(PLUGIN_JSON_FILE_NAME);
let extension_json = serde_json::to_string_pretty(&extension).map_err(|e| e.to_string())?;
tokio::fs::write(&plugin_json_path, extension_json).await.map_err(|e| e.to_string())?;

tokio::fs::write(&plugin_json_path, extension_json)
.await
.map_err(|e| e.to_string())?;

// Turn it into an absolute path if it is a valid relative path because frontend code need this.
canonicalize_relative_icon_path(&extension_directory, &mut extension)?;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Common/UI/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default function Footer({ setIsPinnedWeb }: FooterProps) {
if (visibleExtensionDetail && selectedExtension) {
return (
<div className="flex items-center gap-2">
<img src={selectedExtension.icon} />
<img src={selectedExtension.icon} className="size-5" />
<span className="text-sm">{selectedExtension.name}</span>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Search/AssistantManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export function useAssistantManager({

if (visibleExtensionStore) return;

if (selectedSearchContent?.id === "extension_store") {
if (selectedSearchContent?.id === "Extension Store") {
changeInput("");
setSearchValue("");
return setVisibleExtensionStore(true);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Search/ContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const ContextMenu = () => {
hide:
category === "Calculator" ||
type === "AI Assistant" ||
id === "extension_store",
id === "Extension Store",
clickEvent() {
copyToClipboard(url);
},
Expand Down
4 changes: 2 additions & 2 deletions src/components/Search/ExtensionDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ const ExtensionDetail: FC<ExtensionDetailProps> = (props) => {
{(selectedExtension.tags?.length ?? 0) > 0 && (
<>
<div className="mb-1">{t("extensionDetail.label.tags")}</div>
<div className="mb-4">
<div className="flex gap-2 mb-4">
{selectedExtension.tags?.map((item) => {
return (
<div
key={item}
className="h-6 px-2 rounded text-[#999] bg-[#E6E6E6] dark:bg-[#333]"
className="flex items-center h-6 px-2 rounded text-[#999] bg-[#E6E6E6] dark:bg-[#333]"
>
{item}
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/utils/tauriAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export const createTauriAdapter = (): TauriPlatformAdapter => {

console.log("data", data);

if (data?.type === "AI Assistant" || data?.id === "extension_store") {
if (data?.type === "AI Assistant" || data?.id === "Extension Store") {
const textarea = document.querySelector("#search-textarea");

if (!(textarea instanceof HTMLTextAreaElement)) return;
Expand Down