Skip to content

Commit 4b8e331

Browse files
committed
refac
1 parent cb0fd6e commit 4b8e331

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

src/lib/components/chat/Chat.svelte

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
selectedTerminalId,
4747
showFileNavPath,
4848
showFileNavDir,
49-
chatRequestQueues
49+
chatRequestQueues,
50+
desktopEvent
5051
} from '$lib/stores';
5152
5253
import { WEBUI_API_BASE_URL } from '$lib/constants';
@@ -1225,7 +1226,19 @@
12251226
showControls.set(true);
12261227
}
12271228
1228-
if ($page.url.searchParams.get('q')) {
1229+
// Consume one-shot desktop event (e.g. Spotlight query + attachments)
1230+
if ($desktopEvent) {
1231+
const { query, files: eventFiles } = $desktopEvent;
1232+
desktopEvent.set(null);
1233+
1234+
// TODO: handle eventFiles (attach to chat)
1235+
1236+
if (query) {
1237+
messageInput?.setText(query);
1238+
await tick();
1239+
submitHandler(query);
1240+
}
1241+
} else if ($page.url.searchParams.get('q')) {
12291242
const q = $page.url.searchParams.get('q') ?? '';
12301243
messageInput?.setText(q);
12311244

src/lib/stores/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ export const artifactContents = writable(null);
111111
export const embed = writable(null);
112112

113113
export const temporaryChatEnabled = writable(false);
114+
115+
// Transient one-shot event from the desktop shell (Spotlight, drag-and-drop, etc.).
116+
// Set by +layout.svelte, consumed and cleared by Chat.svelte.
117+
export type DesktopEventFile = { name: string; mimeType: string; dataUrl: string };
118+
export type DesktopEvent = {
119+
query?: string;
120+
files?: DesktopEventFile[];
121+
};
122+
export const desktopEvent: Writable<DesktopEvent | null> = writable(null);
114123
export const scrollPaginationEnabled = writable(false);
115124
export const currentChatPage = writable(1);
116125

src/routes/+layout.svelte

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
showControls,
3636
showFileNavPath,
3737
showFileNavDir,
38-
pyodideWorker
38+
pyodideWorker,
39+
desktopEvent
3940
} from '$lib/stores';
4041
import { getFileContentById } from '$lib/apis/files';
4142
import { goto } from '$app/navigation';
@@ -711,7 +712,8 @@
711712
return;
712713
}
713714
if (event.type === 'query' && event.data?.query) {
714-
await goto(`/?q=${encodeURIComponent(event.data.query)}`);
715+
desktopEvent.set({ query: event.data.query });
716+
await goto('/');
715717
return;
716718
}
717719
if (event.type === 'theme:update' && event.data?.theme) {

0 commit comments

Comments
 (0)