diff --git a/apps/dm/src/lib/server.ts b/apps/dm/src/lib/server.ts index e543958..3a8140b 100644 --- a/apps/dm/src/lib/server.ts +++ b/apps/dm/src/lib/server.ts @@ -30,6 +30,8 @@ export interface UpdateInfo { latest?: string; /** Release notes of the newest release. */ url?: string; + /** Whether the server asks GitHub for new releases, so it can check now. */ + canCheck?: boolean; } /** The server's version and whether a newer release is out. */ @@ -55,6 +57,22 @@ export interface UpdaterInfo { /** Set when the server has an updater container, which enables the update button. */ export const updaterInfo = ref(); +/** Asks the server to look for a new release now; undefined if it could not ask. */ +export async function checkForUpdates(): Promise<'newer' | 'current' | 'unreachable' | undefined> { + try { + const response = await fetch('/api/updates/check', { method: 'POST' }); + if (!response.ok) return undefined; + const data = (await response.json()) as { + result: 'newer' | 'current' | 'unreachable'; + update: UpdateInfo; + }; + updateInfo.value = data.update; + return data.result; + } catch { + return undefined; + } +} + /** Asks the server to update itself; false if the updater could not start. */ export async function startUpdate(): Promise { try { diff --git a/apps/dm/src/locales/de.json b/apps/dm/src/locales/de.json index a6b1e18..e4a8eee 100644 --- a/apps/dm/src/locales/de.json +++ b/apps/dm/src/locales/de.json @@ -18,6 +18,11 @@ "devVersion": "Lorewarden, aus dem Quellcode gebaut. Aktualisieren mit git pull.", "updateAvailable": "Version {version} ist verfügbar.", "releaseNotes": "Was ist neu", + "checkForUpdates": "Nach Updates suchen", + "checkResult": { + "current": "Lorewarden ist auf dem neuesten Stand.", + "unreachable": "GitHub war nicht erreichbar. Versuch es später noch einmal." + }, "howToUpdate": "Wenn du Lorewarden mit Docker Compose betreibst, aktualisierst du es auf dem Server so:", "howToUpdateSource": "Wenn du es aus dem Quellcode startest, nimm git pull und pnpm start. Deine Abenteuer bleiben erhalten.", "combat": "Kampf", diff --git a/apps/dm/src/locales/en.json b/apps/dm/src/locales/en.json index 0e99cdb..dec58d8 100644 --- a/apps/dm/src/locales/en.json +++ b/apps/dm/src/locales/en.json @@ -18,6 +18,11 @@ "devVersion": "Lorewarden, built from source. Update with git pull.", "updateAvailable": "Version {version} is available.", "releaseNotes": "What's new", + "checkForUpdates": "Check for updates", + "checkResult": { + "current": "Lorewarden is up to date.", + "unreachable": "GitHub could not be reached. Try again later." + }, "howToUpdate": "If you run Lorewarden with Docker Compose, update it on the server with:", "howToUpdateSource": "If you run it from source, use git pull and pnpm start. Your adventures are kept.", "combat": "Combat", diff --git a/apps/dm/src/views/SettingsView.vue b/apps/dm/src/views/SettingsView.vue index 6f24771..bc97a5c 100644 --- a/apps/dm/src/views/SettingsView.vue +++ b/apps/dm/src/views/SettingsView.vue @@ -15,6 +15,7 @@ import { } from '../lib/auth'; import { languageOptions } from '../lib/languages'; import { + checkForUpdates, dataDir, setAutoUpdate, startUpdate, @@ -85,6 +86,18 @@ async function savePassword() { repeatedPassword.value = ''; } +const checking = ref(false); +/** What the last "Check for updates" found, unless it found a new release. */ +const checkResult = ref<'current' | 'unreachable'>(); + +async function checkNow() { + checking.value = true; + checkResult.value = undefined; + const result = await checkForUpdates(); + checking.value = false; + if (result !== 'newer') checkResult.value = result ?? 'unreachable'; +} + const updateRefused = ref(false); const updating = computed(() => updaterInfo.value?.status?.state === 'running'); @@ -252,6 +265,17 @@ function onLocale(event: Event) { : t('settings.currentVersion', { version: updateInfo.current }) }}

+