chhoumann / quickadd Public
generated from obsidianmd/obsidian-sample-pluginNew issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] User scripts errors on Mobile (QuickAdd 0.5.0) #195
Comments
|
Hi @Elaws, Thank you for reporting this! For script 1, I've updated to use For script 2, that function doesn't seem to be available on mobile, just as you wrote. And I'm glad to hear script 3 works entirely! :) |
|
Thanks for your quick reply @chhoumann ! I've tested the following : var basePath = QuickAdd.app.vault.basePath;Unfortunately, it returns |
|
Sure thing, @Elaws :) My mistake, I believe it's actually: |
|
Thanks a lot @chhoumann, it seems to work ^^ Unfortunately, I get stuck a few lines later at : const path = require('path');
[...]
var basePath = QuickAdd.app.vault.adapter.basePath;
var relativePath = QuickAdd.app.vault.configDir;
savePath = path.normalize(`${basePath}/${relativePath}/igdbToken.json`);Where I get the following error :
For better cross-platform compatibility, I suppose it's better to use that |
|
Awesome! I think anything node.js doesn't work on mobile. |
|
Oh you are right, it seems there is : /**
* @public
*/
export function normalizePath(path: string): string;However, I'm unsure how to invoke this in a QuickAdd script, I've tried : async function start(params, settings) {
QuickAdd = params;
[...]
savePath = QuickAdd.app.normalizePath(...);But it leads to |
|
@Elaws Exactly that function is actually a bit harder, I believe. It's not accessible from the window object, unlike I just released a version which exposed the Obsidian API in scripts. Then you should be able to access the function like so: module.exports = async (params) => {
// params.obsidian.normalizePath
} |
|
Wow @chhoumann, this is great : thank you very much ! Thanks to your help, I've finally been able to make script n°2 work on mobile, using the following (approximately) : async function start(params, settings) {
[...]
var relativePath = params.app.vault.configDir;
savePath = params.obsidian.normalizePath(`${relativePath}/fileName.json`);
[...]
if(await params.app.vault.adapter.exists(savePath))
{
userData = JSON.parse(await params.app.vault.adapter.read(savePath));
}
else {
[...]
await params.app.vault.adapter.write(savePath, JSON.stringify(userData));
}Not sure if this is clean, but it seems to work on Windows, Android 12 and iPad ^^ I thought I'd need full Obsidian API access to read/write file, but these functions are part of |
Description
On two scripts, I've noticed errors when trying to launch them on mobile.
To reproduce
Script 1
When launching your Movie and Series script, I get the following error :
Error: Failed to load. Cleartext HTTP traffic to www.omdbapi.com not permittedIt seems that writing :
const API_URL = "https://www.omdbapi.com/";Instead of :
const API_URL = "http://www.omdbapi.com/";At line 5 of your script solves the problem ?
Script 2
When launching my Video game script, I get the following error :
TypeError: QuickAdd.app.vault.adapter.getBasePath is not a functionApparently there is a problem with line 46 :
var basePath = QuickAdd.app.vault.adapter.getBasePath();Maybe this does not exist on mobile ? How could I solve this issue so that it works both on mobile and still on PC ? I need to write some data to obsidian configuration folder and thus need vault path to navigate to it.
Script 3
My books script works perfectly fine on mobile (Android 12 - One UI 3.0) thanks to your 0.5.0 update !
Environment:
The text was updated successfully, but these errors were encountered: