fix: cap file not appearing

This commit is contained in:
kwaroran
2024-05-24 23:28:19 +09:00
parent 2798e23447
commit 125018bc7e
2 changed files with 18 additions and 17 deletions

View File

@@ -32,6 +32,7 @@ import { language } from "src/lang";
import { startObserveDom } from "../observer";
import { removeDefaultHandler } from "src/main";
import { updateGuisize } from "../gui/guisize";
import { encodeCapKeySafe } from "./mobileStorage";
//@ts-ignore
export const isTauri = !!window.__TAURI__
@@ -87,16 +88,16 @@ let checkedPaths:string[] = []
async function checkCapFileExists(getUriOptions: CapFS.GetUriOptions): Promise<boolean> {
try {
await CapFS.Filesystem.stat(getUriOptions);
return true;
await CapFS.Filesystem.stat(getUriOptions);
return true;
} catch (checkDirException) {
if (checkDirException.message === 'File does not exist') {
return false;
} else {
throw checkDirException;
}
if (checkDirException.message === 'File does not exist') {
return false;
} else {
throw checkDirException;
}
}
}
}
export async function getFileSrc(loc:string) {
if(isTauri){
if(loc.startsWith('assets')){
@@ -120,13 +121,13 @@ export async function getFileSrc(loc:string) {
}
if(Capacitor.isNativePlatform()){
if(!await checkCapFileExists({
path: loc,
path: encodeCapKeySafe(loc),
directory: CapFS.Directory.External
})){
return ''
}
const uri = await CapFS.Filesystem.getUri({
path: loc,
path: encodeCapKeySafe(loc),
directory: CapFS.Directory.External
})
return Capacitor.convertFileSrc(uri.uri)