Skip to content

Commit 002de06

Browse files
authored
Fix desktop app not being able to load pdfium (Stirling-Tools#6575)
# Description of Changes The changes in [Stirling-Tools#6279](Stirling-Tools#6279) broke the desktop app because the wasm URL handling didn't deal with `tauri://` paths. Also I noticed that `task desktop:build:dev:mac` failed locally because it was attempting to sign the app with credentials that developers won't have (and shouldn't need), so I fixed that too.
1 parent 51478e5 commit 002de06

2 files changed

Lines changed: 13 additions & 16 deletions

File tree

.taskfiles/desktop.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,21 @@ tasks:
6262
deps: [prepare]
6363
dir: editor
6464
cmds:
65-
- npx tauri build --bundles app
65+
- npx tauri build --bundles app --config '{"bundle":{"createUpdaterArtifacts":false}}'
6666

6767
build:dev:windows:
6868
desc: "Build Tauri desktop NSIS installer (Windows)"
6969
deps: [prepare]
7070
dir: editor
7171
cmds:
72-
- npx tauri build --bundles nsis
72+
- npx tauri build --bundles nsis --config '{"bundle":{"createUpdaterArtifacts":false}}'
7373

7474
build:dev:linux:
7575
desc: "Build Tauri desktop AppImage (Linux)"
7676
deps: [prepare]
7777
dir: editor
7878
cmds:
79-
- npx tauri build --bundles appimage
79+
- npx tauri build --bundles appimage --config '{"bundle":{"createUpdaterArtifacts":false}}'
8080

8181
test:
8282
desc: "Run Tauri/Cargo tests"

frontend/editor/src/core/services/wasmPrecompiler.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,19 @@ import { BASE_PATH } from "@app/constants/app";
22
import pdfiumWasmAssetUrl from "@embedpdf/pdfium/pdfium.wasm?url";
33

44
const getWasmUrl = (): string => {
5-
if (
6-
pdfiumWasmAssetUrl.startsWith("http://") ||
7-
pdfiumWasmAssetUrl.startsWith("https://") ||
8-
pdfiumWasmAssetUrl.startsWith("//")
9-
) {
10-
return pdfiumWasmAssetUrl;
11-
}
12-
13-
const origin = typeof window !== "undefined" ? window.location.origin : "";
5+
// In dev, Vite serves the statically-copied asset from the dev server root.
146
if (import.meta.env.DEV) {
7+
const origin = typeof window !== "undefined" ? window.location.origin : "";
158
return `${origin}${BASE_PATH}/pdfium/pdfium.wasm`;
169
}
17-
const cleanAssetUrl = pdfiumWasmAssetUrl
18-
.replace(/^\.\//, "")
19-
.replace(/^\//, "");
20-
return `${origin}${BASE_PATH}/${cleanAssetUrl}`;
10+
11+
// Vite has already produced a base-aware asset URL (absolute under a relative
12+
// base, root-relative under an absolute base). Resolve it against the document
13+
// to get a fetchable absolute URL that is also safe to pass to Web Workers.
14+
if (typeof window !== "undefined") {
15+
return new URL(pdfiumWasmAssetUrl, window.location.href).href;
16+
}
17+
return pdfiumWasmAssetUrl;
2118
};
2219

2320
export const pdfiumWasmUrl = getWasmUrl();

0 commit comments

Comments
 (0)