amake / orgro

An Org Mode app for iOS and Android
https://orgro.org
GNU General Public License v3.0
503 stars 23 forks source link

On iOS after sync with icloud, Orgro does not update file contents #108

Closed bgro closed 1 month ago

bgro commented 1 month ago

Changes of an org-file carried out on the PC and synced via icloud do not show up in Orgro when reopening the file via the Recent files screen -- only opening the file via the iOS Files up does show the changes (which then results in the same file listed with two different time-stamps in the Recent files screen.

Would it be possible for Orgro to check for synced changes and reload the file?

amake commented 1 month ago

Orgro already does the only thing it can do, as far as I know, to ask the OS to get the latest file content: it calls NSFileCoordinator.coordinate when reading the file.

https://github.com/amake/file_picker_writable/blob/641fad56c557e0f5fc1c61d847a1a266b2e44c34/ios/Classes/SwiftFilePickerWritablePlugin.swift#L306-L310

In my testing, this does correctly pick up file changes even when opening from Recent Files:

  1. In Orgro, I open a file stored in iCloud Drive and then close it. This results in an entry on the Recent Files screen.
  2. On my Mac I open the same file, edit its contents, and save
  3. I observe the iCloud Drive sync indicator in the Finder's sidebar proceed to completion (a circled check mark)
  4. I wait a few seconds
  5. I open the file from Orgro's Recent Files screen
  6. The content is consistent with the changes in step 2 above

When the amount of time I wait in step 4 is particularly short, I have observed that the changes in step 2 are not yet reflected. I haven't tried to measure the exact amount of time required, because it probably depends on a lot of factors like your iOS device's network connectivity, its CPU load, whether you've allowed background tasks, whether you're on Low Power Mode, etc.

I note that the iOS file access features can be flaky. When going to test the above I found that the OS file picker as presented from Orgro was misbehaving: it showed no files, buttons were unresponsive, the Locations listing on the top screen of the Browse tab was entirely missing, etc. I found this to be the case also in the Files app, and it persisted across multiple force-quits of the Files app. Ultimately a device restart was the only way I could get it working again.

I recommend that you restart all devices involved, and then try to provide a repeatable set of steps to reproduce your issue. If I can reproduce your issue on my end then maybe I can do something about it. But at the moment all I can say is that Orgro seems to be working correctly within the confines of the OS, which is somewhat unreliable in this area.

amake commented 1 month ago

which then results in the same file listed with two different time-stamps in the Recent files screen.

This is not intended. It seems that the identifier Orgro obtains to ensure persistent access to the file can change over time, even when pointing to the same file:

  1. In Orgro open an iCloud Drive file via the file picker. The file is shown in Recent Files.
  2. Open and close same file again via the file picker. This does not result in a duplicate entry (the identifier is unchanged).
  3. Edit file on Mac and wait for iCloud Drive to sync
  4. Open the file again via the file picker. A duplicate entry is shown in Recent Files.

This I can fix. Look for v1.42.3 which will be available for testing shortly:

bgro commented 1 month ago

Thank you very much for the lightning-fast, very detailed response and the fix for the "sub issue" I had observed.

Interestingly, when testing v1.42.3 regarding the fix for the two different timestamps, my main issue did not occur anymore: changes made on the PC and synced via icloud now are reliably picked up by Orgro.

In case these problems do reappear, I shall try to get something reproducible, but I have the feeling that you are right and the root cause most likely would lie in some iOS problems that you/Ogro have no control over.

Thanks again!

amake commented 1 month ago

@bgro Was this your feedback from TestFlight? Sorry I just noticed it (I never got any notifications or anything; I just happened to see it on App Store Connect)

image Is it intended that the same file is now shown twice? Wasn’t that the bug removed in the previous version?

The fact that only one of the two files is stored in iCloud Drive indicates to me two possibilities:

  1. They aren't the same file. I can programmatically determine when a file is stored in iCloud Drive, but if it came from any other app then Apple intentionally makes it impossible for me to figure out what app that is, for privacy reasons.
  2. The entry not marked as being from iCloud Drive was added in Orgro 1.42.2 or earlier, before Orgro started retaining file URIs. In that case you can simply remove that entry, and reopening the file should not cause any more duplicates.
bgro commented 4 weeks ago

Hi @amake, yes, that was my feedback. Thank you for your response, I guess what happened was the second option, I cannot recall opening the file with a different app. I will remove the file as you suggested.

Thanks again!