enh: force refresh page on update

This commit is contained in:
Timothy Jaeryang Baek 2025-11-03 13:43:07 -05:00
parent 67aa1b028d
commit 989f192c92
4 changed files with 53 additions and 13 deletions

View file

@ -23,6 +23,7 @@ from open_webui.config import (
) )
from open_webui.env import ( from open_webui.env import (
VERSION,
ENABLE_WEBSOCKET_SUPPORT, ENABLE_WEBSOCKET_SUPPORT,
WEBSOCKET_MANAGER, WEBSOCKET_MANAGER,
WEBSOCKET_REDIS_URL, WEBSOCKET_REDIS_URL,

View file

@ -1401,6 +1401,33 @@ export const getChangelog = async () => {
return res; return res;
}; };
export const getVersion = async (token: string) => {
let error = null;
const res = await fetch(`${WEBUI_BASE_URL}/api/version`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`
}
})
.then(async (res) => {
if (!res.ok) throw await res.json();
return res.json();
})
.catch((err) => {
console.error(err);
error = err;
return null;
});
if (error) {
throw error;
}
return res?.version ?? null;
};
export const getVersionUpdates = async (token: string) => { export const getVersionUpdates = async (token: string) => {
let error = null; let error = null;

View file

@ -8,6 +8,7 @@ import emojiShortCodes from '$lib/emoji-shortcodes.json';
// Backend // Backend
export const WEBUI_NAME = writable(APP_NAME); export const WEBUI_NAME = writable(APP_NAME);
export const WEBUI_VERSION = writable(null);
export const config: Writable<Config | undefined> = writable(undefined); export const config: Writable<Config | undefined> = writable(undefined);
export const user: Writable<SessionUser | undefined> = writable(undefined); export const user: Writable<SessionUser | undefined> = writable(undefined);

View file

@ -2,6 +2,7 @@
import { io } from 'socket.io-client'; import { io } from 'socket.io-client';
import { spring } from 'svelte/motion'; import { spring } from 'svelte/motion';
import PyodideWorker from '$lib/workers/pyodide.worker?worker'; import PyodideWorker from '$lib/workers/pyodide.worker?worker';
import { Toaster, toast } from 'svelte-sonner';
let loadingProgress = spring(0, { let loadingProgress = spring(0, {
stiffness: 0.05 stiffness: 0.05
@ -14,6 +15,7 @@
settings, settings,
theme, theme,
WEBUI_NAME, WEBUI_NAME,
WEBUI_VERSION,
mobile, mobile,
socket, socket,
chatId, chatId,
@ -29,26 +31,25 @@
} from '$lib/stores'; } from '$lib/stores';
import { goto } from '$app/navigation'; import { goto } from '$app/navigation';
import { page } from '$app/stores'; import { page } from '$app/stores';
import { Toaster, toast } from 'svelte-sonner'; import { beforeNavigate } from '$app/navigation';
import { updated } from '$app/state';
import { executeToolServer, getBackendConfig } from '$lib/apis'; import i18n, { initI18n, getLanguages, changeLanguage } from '$lib/i18n';
import { getSessionUser, userSignOut } from '$lib/apis/auths';
import '../tailwind.css'; import '../tailwind.css';
import '../app.css'; import '../app.css';
import 'tippy.js/dist/tippy.css'; import 'tippy.js/dist/tippy.css';
import { WEBUI_BASE_URL, WEBUI_HOSTNAME } from '$lib/constants'; import { executeToolServer, getBackendConfig, getVersion } from '$lib/apis';
import i18n, { initI18n, getLanguages, changeLanguage } from '$lib/i18n'; import { getSessionUser, userSignOut } from '$lib/apis/auths';
import { bestMatchingLanguage } from '$lib/utils';
import { getAllTags, getChatList } from '$lib/apis/chats'; import { getAllTags, getChatList } from '$lib/apis/chats';
import NotificationToast from '$lib/components/NotificationToast.svelte';
import AppSidebar from '$lib/components/app/AppSidebar.svelte';
import { chatCompletion } from '$lib/apis/openai'; import { chatCompletion } from '$lib/apis/openai';
import { beforeNavigate } from '$app/navigation'; import { WEBUI_BASE_URL, WEBUI_HOSTNAME } from '$lib/constants';
import { updated } from '$app/state'; import { bestMatchingLanguage } from '$lib/utils';
import NotificationToast from '$lib/components/NotificationToast.svelte';
import AppSidebar from '$lib/components/app/AppSidebar.svelte';
import Spinner from '$lib/components/common/Spinner.svelte'; import Spinner from '$lib/components/common/Spinner.svelte';
// handle frontend updates (https://svelte.dev/docs/kit/configuration#version) // handle frontend updates (https://svelte.dev/docs/kit/configuration#version)
@ -79,15 +80,25 @@
transports: enableWebsocket ? ['websocket'] : ['polling', 'websocket'], transports: enableWebsocket ? ['websocket'] : ['polling', 'websocket'],
auth: { token: localStorage.token } auth: { token: localStorage.token }
}); });
await socket.set(_socket); await socket.set(_socket);
_socket.on('connect_error', (err) => { _socket.on('connect_error', (err) => {
console.log('connect_error', err); console.log('connect_error', err);
}); });
_socket.on('connect', () => { _socket.on('connect', async () => {
console.log('connected', _socket.id); console.log('connected', _socket.id);
const version = await getVersion(localStorage.token);
if (version !== null) {
if ($WEBUI_VERSION !== null && version !== $WEBUI_VERSION) {
location.href = location.href;
} else {
WEBUI_VERSION.set(version);
}
}
console.log('version', version);
if (localStorage.getItem('token')) { if (localStorage.getItem('token')) {
// Emit user-join event with auth token // Emit user-join event with auth token
_socket.emit('user-join', { auth: { token: localStorage.token } }); _socket.emit('user-join', { auth: { token: localStorage.token } });