[262] Netzzugriffe: Inventar für die Release-Notes; Update-Check und Versionsverlauf respektieren den Offline-Modus, Overpass-Host in der Host-Liste, Bild-Fallback nicht mehr an netFetch vorbei

This commit is contained in:
Claude committed 2026-11-15 21:36:33 +00:00
1 parent 2b92b23d59
commit a5f6761917
12 files changed
+94 -11

No files matched your search

+1
View File
@@ -3234,6 +3234,7 @@ export const de = {
"update.title": "Update",
"update.upToDate": "Du hast bereits die aktuellste Version.",
"update.offline": "Offline-Modus ist an: Dossier fragt nicht nach Updates. Schalte ihn in den Einstellungen unter Allgemein aus, um zu prüfen.",
"update.availableBody": "Version {version} ist verfügbar. Jetzt herunterladen und installieren? Die App startet danach neu.",
"update.installNow": "Installieren",
"update.installLater": "Später",
+1
View File
@@ -3221,6 +3221,7 @@ export const en: Record<TranslationKey, string> = {
"update.title": "Update",
"update.upToDate": "You already have the latest version.",
"update.offline": "Offline mode is on: Dossier does not look for updates. Turn it off in Settings under General to check.",
"update.availableBody": "Version {version} is available. Download and install now? The app will restart afterwards.",
"update.installNow": "Install",
"update.installLater": "Later",
+2 -2
View File
@@ -17,8 +17,8 @@ import { bboxAround } from "./lv95";
import type { GeoCategory, GeoFeature } from "./geoContext";
import { viaProxy } from "./geoContext";
// Direkter Mirror mit CORS `*` (Fallback, falls kein Proxy konfiguriert ist).
const OVERPASS = "https://maps.mail.ru/osm/tools/overpass/api/interpreter";
// Direktabruf (Fallback, falls kein Proxy konfiguriert ist). Der Host muss in `ALLOWED_HOSTS` (net/net.ts) stehen, [262].
export const OVERPASS = "https://overpass-api.de/api/interpreter";
/** Welche OSM-Kategorien der Aufrufer möchte. */
export interface OsmSelection {
-1
View File
@@ -17,7 +17,6 @@ export const ALLOWED_HOSTS: readonly string[] = [
"wms.geo.admin.ch",
"data.geo.admin.ch",
"overpass-api.de",
"nominatim.openstreetmap.org",
"localhost",
"127.0.0.1",
];
+6
View File
@@ -6,6 +6,7 @@
import { ask, message } from "@tauri-apps/plugin-dialog";
import { t } from "../i18n";
import { isTauriRuntime } from "../native/projectFile";
import { isOffline } from "../net/net";
/** localStorage-Key fuer die Update-Pause (s. `getUpdateSnoozeUntil`). */
const SNOOZE_KEY = "dossier.updateSnoozeUntil";
@@ -37,6 +38,11 @@ export function setUpdateSnooze(untilMs: number | null): void {
*/
export async function checkForUpdate(silent: boolean): Promise<void> {
if (!isTauriRuntime()) return;
// Offline-Modus ([262]): der Update-Check geht am Tauri-Plugin vorbei an `netFetch`, prüft den Schalter also selbst.
if (isOffline()) {
if (!silent) await message(t("update.offline"), { title: t("update.title"), kind: "info" });
return;
}
if (silent && getUpdateSnoozeUntil() != null) return;
const { check } = await import("@tauri-apps/plugin-updater");
let update: Awaited<ReturnType<typeof check>>;
+52
View File
@@ -0,0 +1,52 @@
// [262] Update-Check und Versionsverlauf gehen am Tauri-Plugin vorbei an `netFetch` und prüfen den Offline-Modus selbst.
import { afterEach, describe, expect, it, vi } from "vitest";
import { OVERPASS } from "../io/osm";
import { netFetch, resetOfflineForTests, setOffline } from "../net/net";
const check = vi.fn(async () => null);
const tauriFetch = vi.fn(async () => new Response("[]"));
vi.mock("../native/projectFile", () => ({ isTauriRuntime: () => true }));
vi.mock("@tauri-apps/plugin-updater", () => ({ check }));
vi.mock("@tauri-apps/plugin-http", () => ({ fetch: tauriFetch }));
vi.mock("@tauri-apps/plugin-dialog", () => ({ ask: vi.fn(), message: vi.fn(async () => undefined) }));
afterEach(() => {
resetOfflineForTests();
check.mockClear();
tauriFetch.mockClear();
vi.unstubAllGlobals();
});
describe("[262] Offline-Modus", () => {
it("stiller Start-Check fragt offline nicht nach Updates, online schon", async () => {
vi.stubGlobal("localStorage", { getItem: () => null, setItem: () => {}, removeItem: () => {} });
const { checkForUpdate } = await import("./checkForUpdate");
setOffline(true);
await checkForUpdate(true);
await checkForUpdate(false);
expect(check).not.toHaveBeenCalled();
setOffline(false);
await checkForUpdate(true);
expect(check).toHaveBeenCalledTimes(1);
});
it("Versionsverlauf ruft offline nichts ab", async () => {
const { fetchVersionHistory } = await import("./versionHistory");
setOffline(true);
expect(await fetchVersionHistory()).toEqual([]);
expect(tauriFetch).not.toHaveBeenCalled();
setOffline(false);
await fetchVersionHistory();
expect(tauriFetch).toHaveBeenCalledTimes(1);
});
});
describe("[262] Overpass-Adresse", () => {
it("steht auf der Host-Liste (sonst scheitert der OSM-Import ohne Proxy)", async () => {
const f = vi.fn(async () => new Response("{}"));
vi.stubGlobal("fetch", f);
setOffline(false);
await netFetch(OVERPASS, { method: "POST" });
expect(f).toHaveBeenCalledTimes(1);
});
});
+2 -1
View File
@@ -6,6 +6,7 @@
// Eintrag nur den DMG-Download im System-Browser an — Installation bleibt
// der gewohnte manuelle Schritt (DMG oeffnen, App in Applications ersetzen).
import { isTauriRuntime } from "../native/projectFile";
import { isOffline } from "../net/net";
export interface VersionEntry {
version: string;
@@ -24,7 +25,7 @@ const VERSIONS_URL =
/** Leeres Array ausserhalb von Tauri oder bei Netzwerk-/Parsefehlern (keine
* Wurf-Semantik hier — der Aufrufer zeigt einfach eine leere Liste). */
export async function fetchVersionHistory(): Promise<VersionEntry[]> {
if (!isTauriRuntime()) return [];
if (!isTauriRuntime() || isOffline()) return []; // Offline-Modus: kein Abruf ([262])
try {
const { fetch: tauriFetch } = await import("@tauri-apps/plugin-http");
const res = await tauriFetch(VERSIONS_URL);
+4 -2
View File
@@ -18,7 +18,7 @@
* (`set_material_detail_textures`; fehlende bleiben schwarz = keine Karte).
*/
import { netFetch } from "../net/net";
import { HostNotAllowedError, OfflineError, netFetch } from "../net/net";
import type { Project } from "../model/types";
import { pathtraceMaterials, type PtMaterialEntry } from "../core";
@@ -103,7 +103,9 @@ async function loadImage(url: string): Promise<CanvasImageSource> {
const res = await netFetch(url);
const blob = await res.blob();
return await createImageBitmap(blob);
} catch {
} catch (err) {
// Offline-Modus und Host-Liste gelten auch für den Bild-Fallback unten ([262]).
if (err instanceof OfflineError || err instanceof HostNotAllowedError) throw err;
// Fallback unten (z. B. wenn fetch die URL nicht mag).
}
}