Skip to content

Commit 436409d

Browse files
committed
chore: match asset protocol handling in electron to tauris impl
1 parent 07cf7ac commit 436409d

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

src-electron/main.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,11 @@ app.whenReady().then(async () => {
266266
try {
267267
const url = new URL(request.url);
268268
// Decode the path from URL encoding
269-
const requestedPath = decodeURIComponent(url.pathname.substring(1)); // Remove leading /
269+
let requestedPath = decodeURIComponent(url.pathname);
270+
// On Windows, URL pathname has extra leading / before drive letter (e.g., /C:/...)
271+
if (/^\/[A-Z]:/i.test(requestedPath)) {
272+
requestedPath = requestedPath.substring(1);
273+
}
270274
const normalizedRequested = path.normalize(requestedPath);
271275
const normalizedAssetsDir = path.normalize(assetsDir);
272276

src-electron/preload.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ contextBridge.exposeInMainWorld('electronAPI', {
7171
if (!platformPath) return null;
7272
// Normalize path separators to forward slashes for URL
7373
const normalizedPath = platformPath.replace(/\\/g, '/');
74-
return `asset://localhost/${encodeURIComponent(normalizedPath)}`;
74+
// Encode each path segment individually to preserve URL path structure (like Tauri's convertFileSrc)
75+
const encodedPath = normalizedPath.split('/').map(segment => encodeURIComponent(segment)).join('/');
76+
return `asset://localhost${encodedPath}`;
7577
},
7678

7779
// Set zoom factor on the webview (mirrors Tauri's zoom_window)

0 commit comments

Comments
 (0)