refactor: don't hide pinned window on search result open (#662)

* refactor: don't hide pinned window on search result open

* refactor: update
This commit is contained in:
ayangweb
2025-06-11 15:26:06 +08:00
committed by GitHub
parent be3cae36e2
commit 44ca66259c
8 changed files with 55 additions and 64 deletions

View File

@@ -1,8 +1,6 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::collections::HashMap; use std::collections::HashMap;
use crate::hide_coco;
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichLabel { pub struct RichLabel {
pub label: Option<String>, pub label: Option<String>,
@@ -93,7 +91,6 @@ pub(crate) async fn open(on_opened: OnOpened) -> Result<(), String> {
} }
} }
hide_coco(global_tauri_app_handle.clone()).await;
Ok(()) Ok(())
} }

View File

@@ -8,7 +8,7 @@ import { Input } from "@headlessui/react";
import { useOSKeyPress } from "@/hooks/useOSKeyPress"; import { useOSKeyPress } from "@/hooks/useOSKeyPress";
import { useSearchStore } from "@/stores/searchStore"; import { useSearchStore } from "@/stores/searchStore";
import { copyToClipboard, OpenURLWithBrowser } from "@/utils"; import { copyToClipboard } from "@/utils";
import { isMac } from "@/utils/platform"; import { isMac } from "@/utils/platform";
import { CONTEXT_MENU_PANEL_ID } from "@/constants"; import { CONTEXT_MENU_PANEL_ID } from "@/constants";
import { useShortcutsStore } from "@/stores/shortcutsStore"; import { useShortcutsStore } from "@/stores/shortcutsStore";
@@ -51,7 +51,7 @@ const ContextMenu: FC<ContextMenuProps> = () => {
const menus = useCreation(() => { const menus = useCreation(() => {
if (isNil(selectedSearchContent)) return []; if (isNil(selectedSearchContent)) return [];
const { url, category, payload, on_opened } = selectedSearchContent; const { url, category, payload } = selectedSearchContent;
const { query, result } = payload ?? {}; const { query, result } = payload ?? {};
if (category === "AI Overview") { if (category === "AI Overview") {
@@ -68,15 +68,7 @@ const ContextMenu: FC<ContextMenuProps> = () => {
shortcut: "enter", shortcut: "enter",
hide: category === "Calculator", hide: category === "Calculator",
clickEvent: () => { clickEvent: () => {
if (on_opened) { platformAdapter.openSearchItem(selectedSearchContent as any);
return platformAdapter.invokeBackend("open", {
onOpened: on_opened,
});
}
if (url) {
OpenURLWithBrowser(url);
}
}, },
}, },
{ {

View File

@@ -11,7 +11,6 @@ import platformAdapter from "@/utils/platformAdapter";
import { Get } from "@/api/axiosRequest"; import { Get } from "@/api/axiosRequest";
import { useAppStore } from "@/stores/appStore"; import { useAppStore } from "@/stores/appStore";
import { useConnectStore } from "@/stores/connectStore"; import { useConnectStore } from "@/stores/connectStore";
import { OpenURLWithBrowser } from "@/utils";
interface DocumentListProps { interface DocumentListProps {
onSelectDocument: (id: string) => void; onSelectDocument: (id: string) => void;
@@ -170,15 +169,8 @@ export const DocumentList: React.FC<DocumentListProps> = ({
const handleEnter = () => { const handleEnter = () => {
if (selectedItem === null) return; if (selectedItem === null) return;
const item = data.list[selectedItem]?.document; const item = data.list[selectedItem]?.document;
if (item?.on_opened) {
return platformAdapter.invokeBackend("open", {
onOpened: item.on_opened,
});
}
if (item?.url) { platformAdapter.openSearchItem(item);
OpenURLWithBrowser(item.url);
}
}; };
switch (e.key) { switch (e.key) {
@@ -242,15 +234,7 @@ export const DocumentList: React.FC<DocumentListProps> = ({
currentIndex={index} currentIndex={index}
onMouseEnter={() => onMouseEnter(index, hit.document)} onMouseEnter={() => onMouseEnter(index, hit.document)}
onItemClick={() => { onItemClick={() => {
if (hit.document?.on_opened) { platformAdapter.openSearchItem(hit.document);
return platformAdapter.invokeBackend("open", {
onOpened: hit.document.on_opened,
});
}
if (hit.document?.url) {
OpenURLWithBrowser(hit.document.url);
}
}} }}
showListRight={viewMode === "list"} showListRight={viewMode === "list"}
/> />

View File

@@ -16,7 +16,6 @@ import { useKeyboardNavigation } from "@/hooks/useKeyboardNavigation";
import { SearchSource } from "./SearchSource"; import { SearchSource } from "./SearchSource";
import DropdownListItem from "./DropdownListItem"; import DropdownListItem from "./DropdownListItem";
import platformAdapter from "@/utils/platformAdapter"; import platformAdapter from "@/utils/platformAdapter";
import { OpenURLWithBrowser } from "@/utils";
type ISearchData = Record<string, QueryHits[]>; type ISearchData = Record<string, QueryHits[]>;
@@ -82,15 +81,7 @@ function DropdownList({
setSelectedSearchContent(item); setSelectedSearchContent(item);
}, },
onItemClick: (item: SearchDocument) => { onItemClick: (item: SearchDocument) => {
if (item?.on_opened) { platformAdapter.openSearchItem(item);
return platformAdapter.invokeBackend("open", {
onOpened: item.on_opened,
});
}
if (item?.url) {
OpenURLWithBrowser(item.url);
}
}, },
goToTwoPage: (item: SearchDocument) => { goToTwoPage: (item: SearchDocument) => {
setSourceData(item); setSourceData(item);

View File

@@ -1,7 +1,6 @@
import { useCallback, useEffect } from "react"; import { useCallback, useEffect } from "react";
import { useShortcutsStore } from "@/stores/shortcutsStore"; import { useShortcutsStore } from "@/stores/shortcutsStore";
import { copyToClipboard, OpenURLWithBrowser } from "@/utils/index";
import type { QueryHits, SearchDocument } from "@/types/search"; import type { QueryHits, SearchDocument } from "@/types/search";
import platformAdapter from "@/utils/platformAdapter"; import platformAdapter from "@/utils/platformAdapter";
import { useSearchStore } from "@/stores/searchStore"; import { useSearchStore } from "@/stores/searchStore";
@@ -88,17 +87,8 @@ export function useKeyboardNavigation({
if (e.key === "Enter" && !e.shiftKey && selectedIndex !== null) { if (e.key === "Enter" && !e.shiftKey && selectedIndex !== null) {
const item = globalItemIndexMap[selectedIndex]; const item = globalItemIndexMap[selectedIndex];
if (item?.on_opened) {
return platformAdapter.invokeBackend("open", {
onOpened: item.on_opened,
});
}
if (item?.url) { return platformAdapter.openSearchItem(item);
return OpenURLWithBrowser(item.url);
}
copyToClipboard(item?.payload?.result?.value);
} }
if (e.key >= "0" && e.key <= "9" && showIndex && modifierKeyPressed) { if (e.key >= "0" && e.key <= "9" && showIndex && modifierKeyPressed) {
@@ -110,15 +100,7 @@ export function useKeyboardNavigation({
const item = globalItemIndexMap[index]; const item = globalItemIndexMap[index];
if (item?.on_opened) { platformAdapter.openSearchItem(item);
return platformAdapter.invokeBackend("open", {
onOpened: item.on_opened,
});
}
if (item?.url) {
OpenURLWithBrowser(item.url);
}
} }
}, },
[suggests, selectedIndex, showIndex, globalItemIndexMap, openPopover] [suggests, selectedIndex, showIndex, globalItemIndexMap, openPopover]

View File

@@ -4,6 +4,7 @@ import { IExtensionsStore } from "@/stores/extensionsStore";
import { IShortcutsStore } from "@/stores/shortcutsStore"; import { IShortcutsStore } from "@/stores/shortcutsStore";
import { IStartupStore } from "@/stores/startupStore"; import { IStartupStore } from "@/stores/startupStore";
import { AppTheme } from "@/types/index"; import { AppTheme } from "@/types/index";
import { SearchDocument } from "./search";
export interface EventPayloads { export interface EventPayloads {
"language-changed": { "language-changed": {
@@ -102,10 +103,11 @@ export interface SystemOperations {
checkUpdate: () => Promise<any>; checkUpdate: () => Promise<any>;
relaunchApp: () => Promise<void>; relaunchApp: () => Promise<void>;
isTauri: () => boolean; isTauri: () => boolean;
openUrl: (url: string) => Promise<void>; openUrl: (url: string) => Promise<unknown>;
commands: <T>(commandName: string, ...args: any[]) => Promise<T>; commands: <T>(commandName: string, ...args: any[]) => Promise<T>;
isWindows10: () => Promise<boolean>; isWindows10: () => Promise<boolean>;
revealItemInDir: (path: string) => Promise<void>; revealItemInDir: (path: string) => Promise<unknown>;
openSearchItem: (data: SearchDocument) => Promise<unknown>;
} }
// Base platform adapter interface // Base platform adapter interface

View File

@@ -12,6 +12,8 @@ import {
import type { BasePlatformAdapter } from "@/types/platform"; import type { BasePlatformAdapter } from "@/types/platform";
import type { AppTheme } from "@/types/index"; import type { AppTheme } from "@/types/index";
import { useAppearanceStore } from "@/stores/appearanceStore"; import { useAppearanceStore } from "@/stores/appearanceStore";
import { copyToClipboard, OpenURLWithBrowser } from ".";
import { useAppStore } from "@/stores/appStore";
export interface TauriPlatformAdapter extends BasePlatformAdapter { export interface TauriPlatformAdapter extends BasePlatformAdapter {
openFileDialog: ( openFileDialog: (
@@ -229,5 +231,35 @@ export const createTauriAdapter = (): TauriPlatformAdapter => {
revealItemInDir(path); revealItemInDir(path);
}, },
async openSearchItem(data) {
const { invoke } = await import("@tauri-apps/api/core");
const hideCoco = () => {
const isPinned = useAppStore.getState().isPinned;
if (isPinned) return;
return invoke("hide_coco");
};
if (data?.on_opened) {
await invoke("open", {
onOpened: data.on_opened,
});
return hideCoco();
}
if (data?.url) {
OpenURLWithBrowser(data.url);
return hideCoco();
}
if (data?.payload?.result?.value) {
return copyToClipboard(data.payload.result.value);
}
},
}; };
}; };

View File

@@ -1,4 +1,5 @@
import type { BasePlatformAdapter } from "@/types/platform"; import type { BasePlatformAdapter } from "@/types/platform";
import { copyToClipboard, OpenURLWithBrowser } from ".";
export interface WebPlatformAdapter extends BasePlatformAdapter { export interface WebPlatformAdapter extends BasePlatformAdapter {
// Add web-specific methods here // Add web-specific methods here
@@ -188,5 +189,15 @@ export const createWebAdapter = (): WebPlatformAdapter => {
async revealItemInDir(path) { async revealItemInDir(path) {
console.log("revealItemInDir is not supported in web environment", path); console.log("revealItemInDir is not supported in web environment", path);
}, },
async openSearchItem(data) {
if (data?.url) {
return OpenURLWithBrowser(data.url);
}
if (data?.payload?.result?.value) {
return copyToClipboard(data.payload.result.value);
}
},
}; };
}; };