// Shared helpers for the Tauri app updater. Used by the auto-check modal // (UpdateNotifier) and the manual check in Settings → Updates & Support. export const SKIP_KEY = "rapport_update_skipped_version"; export const LAST_CHECK_KEY = "rapport_update_last_check"; export function isTauri() { return typeof window !== "undefined" && !!window.__TAURI_INTERNALS__; } export async function checkForAppUpdate({ respectSkip = true } = {}) { if (!isTauri()) return { available: false, isTauri: false }; const { check } = await import("@tauri-apps/plugin-updater"); const result = await check(); localStorage.setItem(LAST_CHECK_KEY, new Date().toISOString()); if (!result?.available) return { available: false, update: null, isTauri: true }; if (respectSkip && localStorage.getItem(SKIP_KEY) === result.version) { return { available: false, update: result, isTauri: true, skipped: true }; } return { available: true, update: result, isTauri: true }; } export async function installAppUpdate(update, onProgress) { await update.downloadAndInstall(onProgress); const { relaunch } = await import("@tauri-apps/plugin-process"); await relaunch(); } export function skipUpdateVersion(version) { if (version) localStorage.setItem(SKIP_KEY, version); } export function getLastUpdateCheck() { return localStorage.getItem(LAST_CHECK_KEY); } export function formatLastCheck(iso) { if (!iso) return "noch nie"; try { const d = new Date(iso); return d.toLocaleString("de-CH", { day: "2-digit", month: "long", year: "numeric", hour: "2-digit", minute: "2-digit", }); } catch { return "—"; } }