Use app.vault.adapter in dataviewjs queries to do more complex actions, such as creating and modifying notes. On Desktop this all works, and it used to work on mobile as well.
But first, path was no longer available on mobile. Now, I don’t have access to app.vault.adapter.getBasePath() and app.vault.adapter.fs contains no functions, it only has uri and dir, so I can’t use fs.readFileSync or fs.writeFileSync.
Things I have tried
Wrote a function to substitute the use of path, since it’s not available on mobile
function pathJoin(...paths) {
return paths.join('/').replace(/\/\/+/g, '/');
}
Wrote a function to get base path differently, based on what is still available on mobile
function getVaultAbsolutePath() {
return adapter.getBasePath?.() || adapter.basePath;
}
I am at my wit’s end. I don’t understand why the interface keeps changing on mobile. Please stop doing this.
Check out Why does fs.writeFile not save file? - #2 by joethei where joethei talks about how fs is not present on mobile platforms. So part of your issue is to be expected, although not documented on the Obsidian documentation site.
Not sure if something or what has happened to the path functions, but if we’re using parts of the API not documented, I’m thinking that’s a risk we’re taking. If it’s documented though, then deviations from the API could be considered a bug (or possibly unannounced change to the API).
We haven’t changed anything about the adapter interface in a long time.
There are actually two adapters, one for desktop, one for mobile.
fs is a thing on desktop, but that’s just an implementation detail, it’s not publicly exposed in the API and should not be used.
I see, thank you. So I should be using read and write from app.vault.adapter. However, I can’t seem to be able to access normalizePath inside of a dataviewjs query. Is it not possible?