Skip to content
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
9 changes: 8 additions & 1 deletion src/lib/commands.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export class GlobalState {
selectedConfigDirectory: '',
yamlContent: '',
keywordDetected: false,
isRecording: false
isRecording: false,
keyword: ''
});
public isVoiceInput = $state(false);

Expand Down Expand Up @@ -57,6 +58,12 @@ export class GlobalState {
set isRecording(value: boolean) {
this._state.isRecording = value;
}
get keyword() {
return this._state.keyword;
}
set keyword(value: string) {
this._state.keyword = value;
}

// async submit() {
// this.greet = await invoke('greet', { name: this.prompt });
Expand Down
16 changes: 16 additions & 0 deletions src/lib/utils/fetchKeyword.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export async function fetchKeyword(): Promise<string> {
let keyword: string;
try {
const response = await fetch(`http://localhost:8000/config/keyword`, {
method: 'GET'
});
if (!response.ok) {
throw new Error(`HTTP error ${response.status}`);
}
keyword = await response.text();
return keyword;
} catch (error) {
console.error('Error fetching keyword:', error);
return 'Failed to fetch keyword. Is the go server running?';
}
}
8 changes: 8 additions & 0 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@
import SpeechInput from './SpeechInput.svelte';
import TextInput from './TextInput.svelte';
import * as Tooltip from '$lib/components/ui/tooltip';
import { fetchKeyword } from '$lib/utils/fetchKeyword';

const gs = new GlobalState();

async function refreshKeyword() {
const newKeyword = await fetchKeyword();
gs.keyword = newKeyword;
console.log('Refreshed keyword:', gs.keyword);
}

const onSwitch = () => {
let inputMode: string;
if (gs.isVoiceInput == true) {
inputMode = 'STT';
refreshKeyword();
} else {
inputMode = 'text';
}
Expand Down