Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.
Rust chatgptclaudeclidesktopdesktop-appelectron-alternativegeminilinuxmacosnativefierno-electronrusttauriweb-to-desktopwebsite-to-appwebviewwindowsyoutube
fix: stop treating /assets/ SPA routes as downloads
Tw93f61b32679220
diff --git a/src-tauri/src/app/invoke.rs b/src-tauri/src/app/invoke.rsindex 1cf668fd..875d67de 100644--- a/src-tauri/src/app/invoke.rs+++ b/src-tauri/src/app/invoke.rs@@ -114,8 +114,18 @@ pub async fn download_file(app: AppHandle, params: DownloadFileParams) -> Resultmatch response {Ok(mut res) => {+ // Transport success is not download success: 403/404 HTML error pages+ // must not be written as files or toasted as successful downloads.+ if !res.status().is_success() {+ show_toast(+ &window,+ &get_download_message_with_lang(MessageType::Failure, params.language),+ );+ return Err(format!("Download failed with HTTP status {}", res.status()));+ }+let mut file =- File::create(file_path).map_err(|e| format!("Failed to create file: {}", e))?;+ File::create(&file_path).map_err(|e| format!("Failed to create file: {}", e))?;while let Some(chunk) = res.chunk()diff --git a/src-tauri/src/inject/event.js b/src-tauri/src/inject/event.jsindex 154e83a4..3d030f69 100644--- a/src-tauri/src/inject/event.js+++ b/src-tauri/src/inject/event.js@@ -446,12 +446,15 @@ const PREVIEWABLE_MEDIA_EXTENSIONS = ["m4a",];+// Path fragments that often host real file downloads. Do not add broad static+// asset roots such as "/assets/" or "/dist/": many SPAs use those as in-app+// routes (e.g. MEXC /assets/future) and would be intercepted as downloads.+// Extensionless links under these paths still match; prefer real extensions,+// download attributes, or ?download / ?attachment query hints when possible.const DOWNLOAD_PATH_PATTERNS = ["/download/","/files/","/attachments/",- "/assets/",- "/dist/",];// Language detection utilitiesdiff --git a/tests/unit/download-http-status.test.ts b/tests/unit/download-http-status.test.tsnew file mode 100644index 00000000..ea49673a--- /dev/null+++ b/tests/unit/download-http-status.test.ts@@ -0,0 +1,40 @@+import fs from 'node:fs';+import path from 'node:path';+import { describe, expect, it } from 'vitest';++const invokeSource = fs.readFileSync(+ path.join(process.cwd(), 'src-tauri', 'src', 'app', 'invoke.rs'),+ 'utf8',+);++const eventSource = fs.readFileSync(+ path.join(process.cwd(), 'src-tauri', 'src', 'inject', 'event.js'),+ 'utf8',+);++describe('download HTTP status handling', () => {+ it('rejects non-success HTTP responses before writing the file', () => {+ expect(invokeSource).toContain('res.status().is_success()');+ expect(invokeSource).toMatch(+ /if !res\.status\(\)\.is_success\(\) \{[\s\S]*?MessageType::Failure/,+ );+ // File creation must come after the status gate so 403 bodies are not saved.+ const statusIdx = invokeSource.indexOf('res.status().is_success()');+ const createIdx = invokeSource.indexOf('File::create');+ expect(statusIdx).toBeGreaterThan(-1);+ expect(createIdx).toBeGreaterThan(statusIdx);+ });++ it('no longer treats /assets/ as a download path heuristic', () => {+ const patternsBlock = eventSource.match(+ /const DOWNLOAD_PATH_PATTERNS = \[([\s\S]*?)\];/,+ )?.[1];+ expect(patternsBlock).toBeTruthy();+ expect(patternsBlock).not.toContain('/assets/');+ expect(patternsBlock).not.toContain('/dist/');+ expect(patternsBlock).toContain('/download/');+ expect(patternsBlock).toContain('/files/');+ expect(patternsBlock).toContain('/attachments/');+ });+});+diff --git a/tests/unit/event-link-guard.test.js b/tests/unit/event-link-guard.test.jsindex a6fbe1f3..f615e6cd 100644--- a/tests/unit/event-link-guard.test.js+++ b/tests/unit/event-link-guard.test.js@@ -227,6 +227,56 @@ describe("event link guard", () => {]);});+ it("navigates SPA routes under /assets/ instead of treating them as downloads", () => {+ const context = loadEventHelpers({ withTauri: true });+ context.window.location.href = "https://www.mexc.com/";+ context.window.location.origin = "https://www.mexc.com";+ context.window.location.pathname = "/";+ runDomReady(context);++ const event = makeClickEvent(+ makeAnchor("https://www.mexc.com/assets/future", "_self"),+ );+ getClickGuard(context)(event);++ expect(event.preventDefault).not.toHaveBeenCalled();+ expect(context.invokeCalls).not.toContainEqual([+ "download_file",+ expect.anything(),+ ]);+ expect(context.isDownloadableFile("https://www.mexc.com/assets/future")).toBe(+ false,+ );+ });++ it("still downloads real files that live under /assets/ by extension", () => {+ const { isDownloadableFile } = loadEventHelpers();++ expect(+ isDownloadableFile("https://cdn.example.com/assets/export/report.pdf"),+ ).toBe(true);+ expect(+ isDownloadableFile("https://cdn.example.com/assets/pkg/app.zip"),+ ).toBe(true);+ });++ it("keeps intentional download-path interception for extensionless /download/ links", () => {+ const { isDownloadableFile } = loadEventHelpers();++ expect(+ isDownloadableFile("https://example.com/download/export"),+ ).toBe(true);+ expect(isDownloadableFile("https://example.com/files/report.pdf")).toBe(+ true,+ );+ });++ it("does not treat static /dist/ SPA paths as downloads without a file extension", () => {+ const { isDownloadableFile } = loadEventHelpers();++ expect(isDownloadableFile("https://example.com/dist/app")).toBe(false);+ });+it("navigates macOS auth URLs in the current window", () => {const { openAuthNavigation, window } = loadEventHelpers({userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 15_5)",