Repository navigation
fix mobile importJs - #1
Conversation
| public async importJs(path: string): Promise<any> { | ||
| const fullPath = this.app.vault.adapter.getResourcePath(path); | ||
| let fullPath = this.app.vault.adapter.getResourcePath(path); | ||
| if (!fullPath.includes('?')) { |
There was a problem hiding this comment.
What if the path on mobile includes a ? somewhere along the way?
There was a problem hiding this comment.
Something like this/is/a?path/foo.js
There was a problem hiding this comment.
Can it have one? Isn't ? an illegal character to have in a path or in a filename? If you're talking about a mobile path that already contains query parameters then It shouldn't be the case since on mobile, getResourcePath doesn't append anything at the end of the full path.
Edit: If you prefer I can construct an URL object with the full path and check whether or not it has a searchParams.size === 0
There was a problem hiding this comment.
https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/os/FileUtils.java;l=1008?q=isValidFatFilenameChar
Seems like you are correct and ? as an invalid character for file paths.
I'm gonna rewrite here what I've written on Discord to have the context of this PR:
DataAdapter.getResourcePathmethod doesn't have the same behavior on computer and on mobile. While they both returns the absolute path of the resource passed in parameter, the desktop version append a?mtimesuffix at the end, which correspond to the file's modified time. This let theimport(fullPath)inAPI.tsknow when the resource can be cached hit or not. Unfortunately since this suffix isn't added on mobile (I'd be interested to know the reason behind this), the import always return the cached version of the file. Thus, only a full reload of the app flush the cache on mobile (I guess)I think that using
getFirstLinkpathDest, to retrieve a TFile of the imported script is the cleanest workaround. That way I can append theTFile.mtimedirectly at the end of path to optimize cache hits.