mirror of
https://github.com/infinilabs/coco-app.git
synced 2025-12-23 14:59:24 +01:00
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:
@@ -1,8 +1,6 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::hide_coco;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct RichLabel {
|
||||
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(())
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import { Input } from "@headlessui/react";
|
||||
|
||||
import { useOSKeyPress } from "@/hooks/useOSKeyPress";
|
||||
import { useSearchStore } from "@/stores/searchStore";
|
||||
import { copyToClipboard, OpenURLWithBrowser } from "@/utils";
|
||||
import { copyToClipboard } from "@/utils";
|
||||
import { isMac } from "@/utils/platform";
|
||||
import { CONTEXT_MENU_PANEL_ID } from "@/constants";
|
||||
import { useShortcutsStore } from "@/stores/shortcutsStore";
|
||||
@@ -51,7 +51,7 @@ const ContextMenu: FC<ContextMenuProps> = () => {
|
||||
const menus = useCreation(() => {
|
||||
if (isNil(selectedSearchContent)) return [];
|
||||
|
||||
const { url, category, payload, on_opened } = selectedSearchContent;
|
||||
const { url, category, payload } = selectedSearchContent;
|
||||
const { query, result } = payload ?? {};
|
||||
|
||||
if (category === "AI Overview") {
|
||||
@@ -68,15 +68,7 @@ const ContextMenu: FC<ContextMenuProps> = () => {
|
||||
shortcut: "enter",
|
||||
hide: category === "Calculator",
|
||||
clickEvent: () => {
|
||||
if (on_opened) {
|
||||
return platformAdapter.invokeBackend("open", {
|
||||
onOpened: on_opened,
|
||||
});
|
||||
}
|
||||
|
||||
if (url) {
|
||||
OpenURLWithBrowser(url);
|
||||
}
|
||||
platformAdapter.openSearchItem(selectedSearchContent as any);
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -11,7 +11,6 @@ import platformAdapter from "@/utils/platformAdapter";
|
||||
import { Get } from "@/api/axiosRequest";
|
||||
import { useAppStore } from "@/stores/appStore";
|
||||
import { useConnectStore } from "@/stores/connectStore";
|
||||
import { OpenURLWithBrowser } from "@/utils";
|
||||
|
||||
interface DocumentListProps {
|
||||
onSelectDocument: (id: string) => void;
|
||||
@@ -170,15 +169,8 @@ export const DocumentList: React.FC<DocumentListProps> = ({
|
||||
const handleEnter = () => {
|
||||
if (selectedItem === null) return;
|
||||
const item = data.list[selectedItem]?.document;
|
||||
if (item?.on_opened) {
|
||||
return platformAdapter.invokeBackend("open", {
|
||||
onOpened: item.on_opened,
|
||||
});
|
||||
}
|
||||
|
||||
if (item?.url) {
|
||||
OpenURLWithBrowser(item.url);
|
||||
}
|
||||
platformAdapter.openSearchItem(item);
|
||||
};
|
||||
|
||||
switch (e.key) {
|
||||
@@ -242,15 +234,7 @@ export const DocumentList: React.FC<DocumentListProps> = ({
|
||||
currentIndex={index}
|
||||
onMouseEnter={() => onMouseEnter(index, hit.document)}
|
||||
onItemClick={() => {
|
||||
if (hit.document?.on_opened) {
|
||||
return platformAdapter.invokeBackend("open", {
|
||||
onOpened: hit.document.on_opened,
|
||||
});
|
||||
}
|
||||
|
||||
if (hit.document?.url) {
|
||||
OpenURLWithBrowser(hit.document.url);
|
||||
}
|
||||
platformAdapter.openSearchItem(hit.document);
|
||||
}}
|
||||
showListRight={viewMode === "list"}
|
||||
/>
|
||||
|
||||
@@ -16,7 +16,6 @@ import { useKeyboardNavigation } from "@/hooks/useKeyboardNavigation";
|
||||
import { SearchSource } from "./SearchSource";
|
||||
import DropdownListItem from "./DropdownListItem";
|
||||
import platformAdapter from "@/utils/platformAdapter";
|
||||
import { OpenURLWithBrowser } from "@/utils";
|
||||
|
||||
type ISearchData = Record<string, QueryHits[]>;
|
||||
|
||||
@@ -82,15 +81,7 @@ function DropdownList({
|
||||
setSelectedSearchContent(item);
|
||||
},
|
||||
onItemClick: (item: SearchDocument) => {
|
||||
if (item?.on_opened) {
|
||||
return platformAdapter.invokeBackend("open", {
|
||||
onOpened: item.on_opened,
|
||||
});
|
||||
}
|
||||
|
||||
if (item?.url) {
|
||||
OpenURLWithBrowser(item.url);
|
||||
}
|
||||
platformAdapter.openSearchItem(item);
|
||||
},
|
||||
goToTwoPage: (item: SearchDocument) => {
|
||||
setSourceData(item);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { useCallback, useEffect } from "react";
|
||||
|
||||
import { useShortcutsStore } from "@/stores/shortcutsStore";
|
||||
import { copyToClipboard, OpenURLWithBrowser } from "@/utils/index";
|
||||
import type { QueryHits, SearchDocument } from "@/types/search";
|
||||
import platformAdapter from "@/utils/platformAdapter";
|
||||
import { useSearchStore } from "@/stores/searchStore";
|
||||
@@ -88,17 +87,8 @@ export function useKeyboardNavigation({
|
||||
|
||||
if (e.key === "Enter" && !e.shiftKey && selectedIndex !== null) {
|
||||
const item = globalItemIndexMap[selectedIndex];
|
||||
if (item?.on_opened) {
|
||||
return platformAdapter.invokeBackend("open", {
|
||||
onOpened: item.on_opened,
|
||||
});
|
||||
}
|
||||
|
||||
if (item?.url) {
|
||||
return OpenURLWithBrowser(item.url);
|
||||
}
|
||||
|
||||
copyToClipboard(item?.payload?.result?.value);
|
||||
return platformAdapter.openSearchItem(item);
|
||||
}
|
||||
|
||||
if (e.key >= "0" && e.key <= "9" && showIndex && modifierKeyPressed) {
|
||||
@@ -110,15 +100,7 @@ export function useKeyboardNavigation({
|
||||
|
||||
const item = globalItemIndexMap[index];
|
||||
|
||||
if (item?.on_opened) {
|
||||
return platformAdapter.invokeBackend("open", {
|
||||
onOpened: item.on_opened,
|
||||
});
|
||||
}
|
||||
|
||||
if (item?.url) {
|
||||
OpenURLWithBrowser(item.url);
|
||||
}
|
||||
platformAdapter.openSearchItem(item);
|
||||
}
|
||||
},
|
||||
[suggests, selectedIndex, showIndex, globalItemIndexMap, openPopover]
|
||||
|
||||
@@ -4,6 +4,7 @@ import { IExtensionsStore } from "@/stores/extensionsStore";
|
||||
import { IShortcutsStore } from "@/stores/shortcutsStore";
|
||||
import { IStartupStore } from "@/stores/startupStore";
|
||||
import { AppTheme } from "@/types/index";
|
||||
import { SearchDocument } from "./search";
|
||||
|
||||
export interface EventPayloads {
|
||||
"language-changed": {
|
||||
@@ -102,10 +103,11 @@ export interface SystemOperations {
|
||||
checkUpdate: () => Promise<any>;
|
||||
relaunchApp: () => Promise<void>;
|
||||
isTauri: () => boolean;
|
||||
openUrl: (url: string) => Promise<void>;
|
||||
openUrl: (url: string) => Promise<unknown>;
|
||||
commands: <T>(commandName: string, ...args: any[]) => Promise<T>;
|
||||
isWindows10: () => Promise<boolean>;
|
||||
revealItemInDir: (path: string) => Promise<void>;
|
||||
revealItemInDir: (path: string) => Promise<unknown>;
|
||||
openSearchItem: (data: SearchDocument) => Promise<unknown>;
|
||||
}
|
||||
|
||||
// Base platform adapter interface
|
||||
|
||||
@@ -12,6 +12,8 @@ import {
|
||||
import type { BasePlatformAdapter } from "@/types/platform";
|
||||
import type { AppTheme } from "@/types/index";
|
||||
import { useAppearanceStore } from "@/stores/appearanceStore";
|
||||
import { copyToClipboard, OpenURLWithBrowser } from ".";
|
||||
import { useAppStore } from "@/stores/appStore";
|
||||
|
||||
export interface TauriPlatformAdapter extends BasePlatformAdapter {
|
||||
openFileDialog: (
|
||||
@@ -229,5 +231,35 @@ export const createTauriAdapter = (): TauriPlatformAdapter => {
|
||||
|
||||
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);
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { BasePlatformAdapter } from "@/types/platform";
|
||||
import { copyToClipboard, OpenURLWithBrowser } from ".";
|
||||
|
||||
export interface WebPlatformAdapter extends BasePlatformAdapter {
|
||||
// Add web-specific methods here
|
||||
@@ -188,5 +189,15 @@ export const createWebAdapter = (): WebPlatformAdapter => {
|
||||
async revealItemInDir(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);
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user