fenjalien / obsidian-typst

Renders typst code blocks in Obsidian into images using Typst through the power of WASM!
Apache License 2.0
356 stars 16 forks source link

Cannot read files on iOS #38

Open Ce1este opened 1 year ago

Ce1este commented 1 year ago

All features work fine on my computer(windows) and Android phone. When it comes to the iPad, everything works fine when using only the features of Typst itself, but I get error when I use the files in the Obsidian library or import typst packages.

filed to load file (access denied)
    ╭─[/07 DataBase/Obsidian插件使用方法/85 Typst Renderer.md:33:9]
    │
 33 │   image("/Resource_Library/408/磁盘.svg", width: 70%),
    │         ────────────────────────────────────  
    │                                                
    │ 
    │ Help: cannot read file outside of project root
you can adjust the project root with the --root argument
────╯
filed to load file (access denied)
   ╭─[/04 学习笔记/考研/数学/三角函数.md:6:9]
   │
 6 │ #import "@preview/cetz:0.1.2"
   │         ─────────────────────  
   │                                 
   │ 
   │ Help: cannot read file outside of project root
you can adjust the project root with the --root argument
───╯

I've noticed that this problem seems to have been fixed in #9, is there something wrong with the way I'm using it on iPad?

Ce1este commented 1 year ago

By the way, on iPad this plugin didn't download the missing libraries like it did on the computer, so I manually imported all the library files to .obsidian\plugins\typst\packages\preview Could this be the cause of the problem?

fenjalien commented 1 year ago

Unfortunately I don't have access to an apple device so I haven't been able to do any testing on iOS. Could you give me some more details?

All features work fine on my computer(windows) and Android phone. When it comes to the iPad, everything works fine when using only the features of Typst itself, but I get error when I use the files in the Obsidian library or import typst packages.

Are you saying that with everything (and I mean EVERYTHING) the same except the platform is either iPad or Windows, it works on Windows but not iPad? If not what are the differences or what happens if everything is the same? Could show your iOS, Obsidian, plugin versions and any other plugins you have enabled?

With the errors I would guess its Typst refusing to access the file before actually attempting to read the file. Could you change the first file path to a file that doesn't exist but in the same folder? Something like "/Resource_Library/408/a.svg", it should hopefully give the same error. I'm not sure whats happening with the second error. Could you try moving the code to different places in the vault, diffierent folders or at the root?

By the way, on iPad this plugin didn't download the missing libraries like it did on the computer

How do you know this and what error does it give?

I manually imported all the library files to .obsidian\plugins\typst\packages\preview Could this be the cause of the problem?

I doubt this is the root cause but make sure they're in the same structure as in the computer.

Ce1este commented 1 year ago

First, I don't think this error is caused by other plugins, because when I disable all other plugins and only keep the Typst Renderer, I get the same error message.

But if you're going to need it, here's my list of plugins on the ipad. (from community-plugins.json)

[
  "dataview",
  "typst",
  "music-code-blocks",
  "adamantine-pick",
  "obsidian-admonition",
  "obsidian-advanced-uri",
  "aosr",
  "avatar",
  "obsidian-banners",
  "blur",
  "blindfold-obsidian",
  "buttons",
  "code-styler",
  "customizable-sidebar",
  "dbfolder",
  "new-tab-default-page",
  "obsidian-dynamic-background",
  "obsidian-dynamic-toc",
  "obsidian-excalidraw-plugin",
  "extract-url",
  "exercises",
  "file-tree-alternative",
  "home-tab",
  "vextab",
  "various-complements",
  "obsidian-title-serial-number-plugin",
  "obsidian-timeline",
  "obsidian-tikzjax",
  "templater-obsidian",
  "obsidian-style-settings",
  "table-extended",
  "sheets",
  "obsidian-read-it-later",
  "obsidian-quiet-outline",
  "pseudocode-in-obs",
  "obsidian42-brat",
  "obsidian-memos",
  "obsidian-markmind",
  "obsidian-functionplot",
  "obsidian-columns",
  "multi-column-markdown",
  "obsidian-minimal-settings",
  "mathlinks",
  "media-extended",
  "math-booster",
  "link-favicon",
  "language-translator",
  "obsidian-image-layouts",
  "obsidian-image-gallery",
  "obsidian-icon-shortcodes"
]

With the errors I would guess its Typst refusing to access the file before actually attempting to read the file. Could you change the first file path to a file that doesn't exist but in the same folder? Something like "/Resource_Library/408/a.svg", it should hopefully give the same error. I'm not sure whats happening with the second error. Could you try moving the code to different places in the vault, diffierent folders or at the root?

For /Resource_Library/408/a.svg, It does give the same error. And I move the code to different places in the vault, It still give the same error. I think your guess is right, Typst doesn't seem to have access to any files.


I'm using "Windows 11 Version 22H2 22621.1992" and "iPadOS 17.2". I use the git tool to synchronize the contents of files in the repository between the three platforms(Windows,Android,iPadOS), which ensures that the file structure is the same. In order to keep the settings of the three platforms from interfering with each other, I set up separate config folders for each of them. For windows is .obsidian, for iPad is .obsidian.iPad, for Android is .obsidian.android.

By the way, on iPad this plugin didn't download the missing libraries like it did on the computer

On the computer, typst automatically detected the missing libraries and then downloaded them automatically, on the iPad I waited for a long time and nothing happened, so I copied all contents from \.obsidian\plugins\typst\packages to \.obsidian.android\plugins\typst\packages and \.obsidian.iPad\plugins\typst\packages. This works on Android, so I think it's probably not due to a different file structure either.

I'm sorry that I don't know much about how the Obsidian plugin actually works, so I can only judge it superficially: it seems to me that the way access permissions to files are determined on iOS/iPadOS is not quite the same as on Windows/Android, which may be the cause of the problem.

Finally, thank you for your work on this plugin, it has helped me a lot. If you need any other information, I will try my best to provide it.

fenjalien commented 1 year ago

Thanks for the info! I've had a look at the code as an access denied error can't be thrown on mobile on a file read attempt, only before within the Typst compiler. Its a bug the wrong error is thrown however the actual error still gets printed to the console.

Would you be able to get access to the console on your iPad and show the error? I'm not sure how exactly to do this for apple devices as I only have android, but this: https://github.com/KjellConnelly/obsidian-dev-tools might be something. Could you also try in a new vault only on your iPad with only the plugin?

Ce1este commented 1 year ago

I'm not sure I'm using it the right way. Is this it?

Clipboard 2023年11月14日 20 11

blob:capacitor://localhost/4c89bc45-daf2-46bd-a015-ac7b8737e182:1:2529

Ce1este commented 1 year ago
图像

When the packages cannot be found, an error "package not found" will be reported. Manually importing the package files to the corresponding location will result in an error "failed to load file(access denied)".

It seems that Typst can detect whether the package exists, but it cannot proceed to the next step correctly?

From opening Obsidian and loading the plugin to opening the file containing Typst only these two types of errors occur.

fenjalien commented 1 year ago

Thank you! I'm not sure I can diagnose this issue without an apple device with me as there should be more error messages than this...

I have a bad feeling its because the way in which files are read is only available on android and not iOS. Which is a great shame as there was literally no other way to do it.

It seems that Typst can detect whether the package exists, but it cannot proceed to the next step correctly?

Yes, the compiler works on a separate thread where the file reading is different (and not working) but the main thread can read the file system fine and tell the compiler which packages are available. If the package isn't available the main thread attempts to download the package then restart the compiler. I'm assuming you do have an internet connection in which case its receiving a 404 error meaning the package doesn't exist (which it definitely does). Any other issues in fetching the package should result in a different error.

iamrecursion commented 5 months ago

Could you not get around this by allowing typst packages and the WASM bundle to be stored in a user-defined folder in the vault (#52)? Once that is done, they should be able to be read by the vault adapter just like any other file.

d-kaue commented 5 months ago

Could you not get around this by allowing typst packages and the WASM bundle to be stored in a user-defined folder in the vault (#52)? Once that is done, they should be able to be read by the vault adapter just like any other file.

You're right. But I think the wasm might still be in the plugin folder, because the plugin already checks if it exists.

An addition, I've noticed that it's not an iOS-only problem. The mobile device does not recognize the nodejs path library and we should avoid using this library in favor of the obsidian API.

Hey @fenjalien, I'm already working on implementing the change to the PackagePath. Should I make a separate PR or a single one including this one?

fenjalien commented 5 months ago

Could you not get around this by allowing typst packages and the WASM bundle to be stored in a user-defined folder in the vault (#52)? Once that is done, they should be able to be read by the vault adapter just like any other file.

Typst packages and the WASM bundle are being stored in the vault, its under .obsidian/plugins/typst/ but thats not the problem here.

I'm sure I've written this before but I'll reiterate, the biggest hurdle when reading files is that the Typst compiler calls the "read this file please" function synchronously but Obsidian mobile only provides asynchronous ways to read files. Thats all the problem is and its annoyingly difficult to solve in this case.

I'll now highlight the possible solutions I've tried and their problems:

I've already put a lot of time into solving this problem with very little to show for it, so I'm unwilling to try harder with all these ideas.

@d-kaue

An addition, I've noticed that it's not an iOS-only problem. The mobile device does not recognize the nodejs path library and we should avoid using this library in favor of the obsidian API.

You might have noticed by now but the mobile version should not be using the path library as its a Node module and is not available on mobile, there are checks in place to make sure it doesn't even try to use it.

I'm already working on implementing the change to the PackagePath. Should I make a separate PR or a single one including this one?

Make it separate, but I don't think it'll fix anything.

d-kaue commented 5 months ago

You might have noticed by now but the mobile version should not be using the path library as its a Node module and is not available on mobile, there are checks in place to make sure it doesn't even try to use it.

Yea, the this.app.emulate(true) now warns about that.

Edit

never mind, I can't reproduce it again. maybe it's the feature I'm implementing and I just ran into this error.