mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-10 20:35:17 +02:00
fix: move quickAskMode to IPC to prevent sessionStorage leak between windows
This commit is contained in:
parent
9f13da3fd1
commit
58ac17fb81
7 changed files with 32 additions and 11 deletions
|
|
@ -3,5 +3,7 @@ export const IPC_CHANNELS = {
|
|||
GET_APP_VERSION: 'get-app-version',
|
||||
DEEP_LINK: 'deep-link',
|
||||
QUICK_ASK_TEXT: 'quick-ask-text',
|
||||
SET_QUICK_ASK_MODE: 'set-quick-ask-mode',
|
||||
GET_QUICK_ASK_MODE: 'get-quick-ask-mode',
|
||||
REPLACE_TEXT: 'replace-text',
|
||||
} as const;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import { getServerPort } from './server';
|
|||
const SHORTCUT = 'CommandOrControl+Option+S';
|
||||
let quickAskWindow: BrowserWindow | null = null;
|
||||
let pendingText = '';
|
||||
let pendingMode = '';
|
||||
let sourceApp = '';
|
||||
let savedClipboard = '';
|
||||
|
||||
|
|
@ -15,6 +16,7 @@ function destroyQuickAsk(): void {
|
|||
quickAskWindow.close();
|
||||
}
|
||||
quickAskWindow = null;
|
||||
pendingMode = '';
|
||||
}
|
||||
|
||||
function clampToScreen(x: number, y: number, w: number, h: number): { x: number; y: number } {
|
||||
|
|
@ -102,6 +104,14 @@ export function registerQuickAsk(): void {
|
|||
return pendingText;
|
||||
});
|
||||
|
||||
ipcMain.handle(IPC_CHANNELS.SET_QUICK_ASK_MODE, (_event, mode: string) => {
|
||||
pendingMode = mode;
|
||||
});
|
||||
|
||||
ipcMain.handle(IPC_CHANNELS.GET_QUICK_ASK_MODE, () => {
|
||||
return pendingMode;
|
||||
});
|
||||
|
||||
ipcMain.handle(IPC_CHANNELS.REPLACE_TEXT, async (_event, text: string) => {
|
||||
if (!sourceApp) return;
|
||||
|
||||
|
|
|
|||
|
|
@ -18,5 +18,7 @@ contextBridge.exposeInMainWorld('electronAPI', {
|
|||
};
|
||||
},
|
||||
getQuickAskText: () => ipcRenderer.invoke(IPC_CHANNELS.QUICK_ASK_TEXT),
|
||||
setQuickAskMode: (mode: string) => ipcRenderer.invoke(IPC_CHANNELS.SET_QUICK_ASK_MODE, mode),
|
||||
getQuickAskMode: () => ipcRenderer.invoke(IPC_CHANNELS.GET_QUICK_ASK_MODE),
|
||||
replaceText: (text: string) => ipcRenderer.invoke(IPC_CHANNELS.REPLACE_TEXT, text),
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1621,4 +1621,4 @@ export default function NewChatPage() {
|
|||
</div>
|
||||
</AssistantRuntimeProvider>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -35,16 +35,16 @@ export default function QuickAskPage() {
|
|||
});
|
||||
}, []);
|
||||
|
||||
const navigateToChat = (prompt: string, mode: string) => {
|
||||
sessionStorage.setItem("quickAskMode", mode);
|
||||
const navigateToChat = async (prompt: string, mode: string) => {
|
||||
await window.electronAPI?.setQuickAskMode(mode);
|
||||
sessionStorage.setItem("quickAskAutoSubmit", "true");
|
||||
const encoded = encodeURIComponent(prompt);
|
||||
window.location.href = `/dashboard?quickAskPrompt=${encoded}`;
|
||||
};
|
||||
|
||||
const navigateWithInitialText = () => {
|
||||
const navigateWithInitialText = async () => {
|
||||
if (!clipboardText) return;
|
||||
sessionStorage.setItem("quickAskMode", "explore");
|
||||
await window.electronAPI?.setQuickAskMode("explore");
|
||||
sessionStorage.setItem("quickAskAutoSubmit", "false");
|
||||
sessionStorage.setItem("quickAskInitialText", clipboardText);
|
||||
window.location.href = `/dashboard?quickAskPrompt=${encodeURIComponent(clipboardText)}`;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import {
|
|||
import { useAtomValue } from "jotai";
|
||||
import { CheckIcon, ClipboardPaste, CopyIcon, DownloadIcon, MessageSquare, RefreshCwIcon } from "lucide-react";
|
||||
import type { FC } from "react";
|
||||
import { useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { commentsEnabledAtom, targetCommentIdAtom } from "@/atoms/chat/current-thread.atom";
|
||||
import { activeSearchSpaceIdAtom } from "@/atoms/search-spaces/search-space-query.atoms";
|
||||
import { MarkdownText } from "@/components/assistant-ui/markdown-text";
|
||||
|
|
@ -274,11 +274,16 @@ export const AssistantMessage: FC = () => {
|
|||
const AssistantActionBar: FC = () => {
|
||||
const isLast = useAuiState((s) => s.message.isLast);
|
||||
const aui = useAui();
|
||||
const isTransform =
|
||||
isLast &&
|
||||
typeof window !== "undefined" &&
|
||||
!!window.electronAPI?.replaceText &&
|
||||
sessionStorage.getItem("quickAskMode") === "transform";
|
||||
const [quickAskMode, setQuickAskMode] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
if (!isLast || !window.electronAPI?.getQuickAskMode) return;
|
||||
window.electronAPI.getQuickAskMode().then((mode) => {
|
||||
if (mode) setQuickAskMode(mode);
|
||||
});
|
||||
}, [isLast]);
|
||||
|
||||
const isTransform = isLast && !!window.electronAPI?.replaceText && quickAskMode === "transform";
|
||||
|
||||
return (
|
||||
<ActionBarPrimitive.Root
|
||||
|
|
|
|||
2
surfsense_web/types/window.d.ts
vendored
2
surfsense_web/types/window.d.ts
vendored
|
|
@ -11,6 +11,8 @@ interface ElectronAPI {
|
|||
getAppVersion: () => Promise<string>;
|
||||
onDeepLink: (callback: (url: string) => void) => () => void;
|
||||
getQuickAskText: () => Promise<string>;
|
||||
setQuickAskMode: (mode: string) => Promise<void>;
|
||||
getQuickAskMode: () => Promise<string>;
|
||||
replaceText: (text: string) => Promise<void>;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue