Skip to content

Commit 72ad0e0

Browse files
committed
refactor: asset url apis prepare for electron migration
1 parent 36bf65e commit 72ad0e0

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

src/phoenix/init_vfs.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ let extensionDIR,
3939
tempDIR,
4040
userProjectsDir;
4141

42+
function _getNativeAssetUrl(fullFilePath) {
43+
if(window.__TAURI__) {
44+
if(fullFilePath.startsWith(tauriAssetServeDir)){
45+
const platformPath = fs.getTauriPlatformPath(fullFilePath)
46+
.replace(/\\/g, "/"); // windows style paths to unix style c:\x\y to c:/x/y
47+
return decodeURIComponent(window.__TAURI__.tauri.convertFileSrc(platformPath));
48+
}
49+
return null;
50+
}
51+
return null;
52+
}
53+
4254
function _setupVFS(fsLib, pathLib){
4355
Phoenix.VFS = {
4456
getRootDir: () => '/fs/',
@@ -129,12 +141,7 @@ function _setupVFS(fsLib, pathLib){
129141
},
130142
getVirtualServingURLForPath: function (fullPath) {
131143
if(Phoenix.isNativeApp) {
132-
if(fullPath.startsWith(tauriAssetServeDir)){
133-
const platformPath = fs.getTauriPlatformPath(fullPath)
134-
.replace(/\\/g, "/"); // windows style paths to unix style c:\x\y to c:/x/y
135-
return decodeURIComponent(window.__TAURI__.tauri.convertFileSrc(platformPath));
136-
}
137-
return null;
144+
return _getNativeAssetUrl(fullPath);
138145
}
139146
return window.fsServerUrl.slice(0, -1) + fullPath;
140147
},
@@ -275,9 +282,7 @@ async function setupAppSupportAndExtensionsDir() {
275282
appSupportDIR = `${appSupportDIR}/`;
276283
}
277284
tauriAssetServeDir = `${appSupportDIR}assets/`;
278-
tauriAssetServeBaseURL = decodeURIComponent(window.__TAURI__.tauri.convertFileSrc(
279-
fs.getTauriPlatformPath(tauriAssetServeDir)))
280-
.replace(/\\/g, "/"); // windows style paths to unix style c:\x\y to c:/x/y
285+
tauriAssetServeBaseURL = _getNativeAssetUrl(tauriAssetServeDir);
281286
extensionDIR = `${tauriAssetServeDir}extensions/`;
282287
// in tauri, the /fs/ folder is not a requirement for boot, so we won't fait for it.
283288
// also this creates wired indexed db lock bugs in tauri where the boot leads to a blank screen.

0 commit comments

Comments
 (0)