mirror of
https://github.com/open-webui/computer.git
synced 2026-11-19 04:11:57 +03:00
refac
This commit is contained in:
+29
@@ -215,6 +215,35 @@ async def get_changelog():
|
||||
return {key: CHANGELOG[key] for idx, key in enumerate(CHANGELOG) if idx < 5}
|
||||
|
||||
|
||||
@app.get("/api/version/updates")
|
||||
async def get_version_updates(request: Request):
|
||||
"""Check GitHub for the latest release. Admin-only."""
|
||||
from cptr.routers.admin import require_admin
|
||||
from importlib.metadata import version as pkg_version
|
||||
|
||||
require_admin(request)
|
||||
|
||||
try:
|
||||
current = pkg_version("cptr")
|
||||
except Exception:
|
||||
current = "dev"
|
||||
|
||||
try:
|
||||
import httpx
|
||||
|
||||
async with httpx.AsyncClient(timeout=2) as client:
|
||||
r = await client.get(
|
||||
"https://api.github.com/repos/open-webui/computer/releases/latest",
|
||||
headers={"Accept": "application/vnd.github+json"},
|
||||
)
|
||||
r.raise_for_status()
|
||||
tag = r.json().get("tag_name", "")
|
||||
latest = tag.lstrip("v") if tag else current
|
||||
return {"current": current, "latest": latest}
|
||||
except Exception:
|
||||
return {"current": current, "latest": current}
|
||||
|
||||
|
||||
# PWA manifest (backend-driven so each instance has its own identity)
|
||||
@app.get("/manifest.json")
|
||||
async def pwa_manifest():
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { t } from '$lib/i18n';
|
||||
import { appVersion, showChangelog } from '$lib/stores';
|
||||
import { appVersion, showChangelog, updateAvailable, latestVersion } from '$lib/stores';
|
||||
</script>
|
||||
|
||||
<h2 class="text-sm font-medium text-gray-900 dark:text-white mb-4">
|
||||
@@ -23,6 +23,18 @@
|
||||
>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#if $updateAvailable}
|
||||
<a
|
||||
href="https://github.com/open-webui/computer/releases"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
class="inline-block mt-1 text-[11px] text-blue-500 dark:text-blue-400 hover:text-blue-600 dark:hover:text-blue-300 transition-colors"
|
||||
>
|
||||
{$t('update.updateAvailable', { version: $latestVersion })}
|
||||
</a>
|
||||
{/if}
|
||||
|
||||
<p class="text-[13px] text-gray-500 mt-0.5 mb-4">{$t('app.tagline')}</p>
|
||||
|
||||
<h3 class="text-xs text-gray-400 dark:text-gray-600 mb-1">
|
||||
@@ -44,3 +56,4 @@
|
||||
<p class="text-[11px] text-gray-300 dark:text-gray-700 pt-8">
|
||||
{$t('about.createdBy')}
|
||||
</p>
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<script lang="ts">
|
||||
import { t } from '$lib/i18n';
|
||||
import { latestVersion } from '$lib/stores';
|
||||
import Icon from './Icon.svelte';
|
||||
import { fade } from 'svelte/transition';
|
||||
|
||||
let { onclose }: { onclose: () => void } = $props();
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="fixed bottom-4 right-4 z-50"
|
||||
in:fade={{ duration: 100 }}
|
||||
out:fade={{ duration: 75 }}
|
||||
>
|
||||
<div
|
||||
class="flex items-center gap-2 rounded-lg border border-gray-200 dark:border-white/6 bg-white dark:bg-[#1a1a1a] px-3 py-2"
|
||||
>
|
||||
<span class="text-[11px] text-gray-500 dark:text-gray-400">
|
||||
{$t('update.available', { version: $latestVersion })}
|
||||
</span>
|
||||
|
||||
<a
|
||||
href="https://github.com/open-webui/computer/releases"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
class="text-[11px] text-gray-900 dark:text-white hover:underline font-medium"
|
||||
>
|
||||
{$t('update.viewRelease')}
|
||||
</a>
|
||||
|
||||
<button
|
||||
onclick={onclose}
|
||||
class="ml-0.5 flex items-center justify-center w-5 h-5 rounded text-gray-300 hover:text-gray-500 dark:text-gray-600 dark:hover:text-gray-400 transition-colors duration-75"
|
||||
aria-label="Dismiss"
|
||||
>
|
||||
<Icon name="xmark" size={12} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -297,5 +297,9 @@
|
||||
"models.systemPromptHint": "Default instructions sent to the model. Use {{VARIABLES}} for dynamic content.",
|
||||
"models.systemPromptInherited": "Inherits global default",
|
||||
"models.templateVariables": "Variables",
|
||||
"models.resetToDefault": "Reset"
|
||||
"models.resetToDefault": "Reset",
|
||||
|
||||
"update.available": "A new version (v{{version}}) is available.",
|
||||
"update.viewRelease": "View release notes →",
|
||||
"update.updateAvailable": "Update available: v{{version}}"
|
||||
}
|
||||
|
||||
@@ -139,6 +139,20 @@ export const planMode = writable(false);
|
||||
export const requestParams = writable<Record<string, unknown>>({});
|
||||
export const appVersion = writable('');
|
||||
export const lastSeenVersion = writable('');
|
||||
export const latestVersion = writable('');
|
||||
export const updateAvailable = derived(
|
||||
[appVersion, latestVersion],
|
||||
([$app, $latest]) => {
|
||||
if (!$app || !$latest || $app === 'dev' || $app === '0.0.0') return false;
|
||||
return (
|
||||
$app.localeCompare($latest, undefined, {
|
||||
numeric: true,
|
||||
sensitivity: 'case',
|
||||
caseFirst: 'upper'
|
||||
}) < 0
|
||||
);
|
||||
}
|
||||
);
|
||||
export const showChangelog = writable(false);
|
||||
export const showSearch = writable(false);
|
||||
/** @deprecated Use toolApprovalMode */
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
import SettingsModal from '$lib/components/SettingsModal.svelte';
|
||||
import AuthScreen from '$lib/components/AuthScreen.svelte';
|
||||
import ChangelogModal from '$lib/components/ChangelogModal.svelte';
|
||||
import UpdateToast from '$lib/components/UpdateToast.svelte';
|
||||
import { Toaster } from 'svelte-sonner';
|
||||
import {
|
||||
activeTab,
|
||||
@@ -26,20 +27,24 @@
|
||||
closeGroup,
|
||||
appVersion,
|
||||
lastSeenVersion,
|
||||
latestVersion,
|
||||
updateAvailable,
|
||||
showChangelog,
|
||||
showSearch
|
||||
} from '$lib/stores';
|
||||
import { matchKeybinding, executeAction } from '$lib/stores/keybindings';
|
||||
import { systemEvents } from '$lib/stores/systemEvents.svelte';
|
||||
import { socketStore } from '$lib/stores/socket.svelte';
|
||||
import { setSession, clearSession } from '$lib/session';
|
||||
import { setSession, clearSession, session } from '$lib/session';
|
||||
import { getSession, getConfig } from '$lib/apis/auth';
|
||||
import { fetchJSON } from '$lib/apis';
|
||||
import { gitStatusStore } from '$lib/stores/gitStatus.svelte';
|
||||
import { t } from '$lib/i18n';
|
||||
import { refreshChatState, bindGlobalChatListener } from '$lib/stores/chat';
|
||||
|
||||
let { children } = $props();
|
||||
let showSettings = $state(false);
|
||||
let showUpdateToast = $state(false);
|
||||
|
||||
// Auth state
|
||||
type AuthState = 'checking' | 'needs_setup' | 'needs_login' | 'authenticated';
|
||||
@@ -141,6 +146,9 @@
|
||||
authState = 'authenticated';
|
||||
initState();
|
||||
refreshChatState();
|
||||
|
||||
// Check for version updates (admin only, after session is set)
|
||||
checkForUpdates();
|
||||
} else {
|
||||
const cfg = await getConfig();
|
||||
authMode = cfg.auth_mode || 'password';
|
||||
@@ -174,6 +182,29 @@
|
||||
authState = 'needs_login';
|
||||
}
|
||||
|
||||
async function checkForUpdates() {
|
||||
try {
|
||||
const sess = $session;
|
||||
if (!sess || sess.role !== 'admin') return;
|
||||
|
||||
// 24-hour dismiss cooldown
|
||||
const dismissed = localStorage.getItem('dismissedUpdateToast');
|
||||
if (dismissed) {
|
||||
const elapsed = Date.now() - Number(dismissed);
|
||||
if (elapsed < 24 * 60 * 60 * 1000) return;
|
||||
}
|
||||
|
||||
const data = await fetchJSON<{ current: string; latest: string }>('/api/version/updates');
|
||||
latestVersion.set(data.latest);
|
||||
// Show toast if update is available (reactive via $updateAvailable)
|
||||
if (data.current !== data.latest) {
|
||||
showUpdateToast = true;
|
||||
}
|
||||
} catch {
|
||||
// Silently ignore (non-admin, network error, etc.)
|
||||
}
|
||||
}
|
||||
|
||||
function handleKeydown(e: KeyboardEvent) {
|
||||
const action = matchKeybinding(e);
|
||||
if (!action) return;
|
||||
@@ -286,6 +317,14 @@
|
||||
<SettingsModal onclose={() => (showSettings = false)} />
|
||||
{/if}
|
||||
<ChangelogModal />
|
||||
{#if $updateAvailable && showUpdateToast}
|
||||
<UpdateToast
|
||||
onclose={() => {
|
||||
showUpdateToast = false;
|
||||
localStorage.setItem('dismissedUpdateToast', Date.now().toString());
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
{:else}
|
||||
<div class="flex items-center justify-center h-dvh bg-white dark:bg-black">
|
||||
<Spinner size={20} />
|
||||
|
||||
Reference in New Issue
Block a user