This commit is contained in:
Timothy Jaeryang Baek
2026-03-19 17:56:05 -05:00
parent adcc50d337
commit 694fb3776f
2 changed files with 174 additions and 0 deletions
+50
View File
@@ -53,6 +53,12 @@
import { getSessionUser, userSignOut } from '$lib/apis/auths';
import { getAllTags, getChatList } from '$lib/apis/chats';
import { chatCompletion } from '$lib/apis/openai';
import {
addOpenAIConnection,
removeOpenAIConnection,
addTerminalConnection,
removeTerminalConnection
} from '$lib/utils/connections';
import { WEBUI_API_BASE_URL, WEBUI_BASE_URL, WEBUI_HOSTNAME } from '$lib/constants';
import { bestMatchingLanguage, displayFileHandler } from '$lib/utils';
@@ -692,6 +698,45 @@
}
};
const desktopEventHandler = async (event) => {
// Events that don't require auth
if (event.type === 'page:reload') {
location.reload();
return;
}
const token = localStorage.token;
if (!token) return;
// Only admins can modify system-level connections
if ($user?.role !== 'admin') return;
try {
if (event.type === 'connections:terminal') {
if (event.data.action === 'add') {
await addTerminalConnection(token, {
url: event.data.url,
key: event.data.key,
name: 'Local Open Terminal'
});
} else if (event.data.action === 'remove') {
await removeTerminalConnection(token, event.data.url);
}
} else if (event.type === 'connections:openai') {
if (event.data.action === 'add') {
await addOpenAIConnection(token, {
url: event.data.url,
key: event.data.key
});
} else if (event.data.action === 'remove') {
await removeOpenAIConnection(token, event.data.url);
}
}
} catch (e) {
console.error('Desktop connection update failed:', e);
}
};
const windowMessageEventHandler = async (event) => {
if (
!['https://openwebui.com', 'https://www.openwebui.com', 'http://localhost:9999'].includes(
@@ -767,6 +812,11 @@
appData.set(data);
}
}
// Listen for desktop service lifecycle events (scalable protocol)
if (window.electronAPI.onEvent) {
window.electronAPI.onEvent(desktopEventHandler);
}
}
// Listen for messages on the BroadcastChannel