Skip to content

Android: Fix sharing items from Joplin#4718

Merged
laurent22 merged 10 commits intolaurent22:devfrom
roman-r-m:android-share-fix-III
Apr 7, 2021
Merged

Android: Fix sharing items from Joplin#4718
laurent22 merged 10 commits intolaurent22:devfrom
roman-r-m:android-share-fix-III

Conversation

@roman-r-m
Copy link
Copy Markdown
Contributor

@roman-r-m roman-r-m commented Mar 21, 2021

This is prompted by this bug report on the forum: https://discourse.joplinapp.org/t/android-lost-access-to-resources/15716/4

The issue here is a combination of 2 older bugs I've fixed before: #4557 & #4373 and a quirk in how Joplin handles deletion.

  • Because of one of the above bugs, a resource ended up stored in Joplin with an empty title.

  • When the user shared the resource, Joplin tried to copy the resource to give it the original name (taken from the title), but since the title was empty the copy failed.

    const filename = resource.file_name ?
    `${resource.file_name}.${resource.file_extension}` :
    resource.title;
    const targetPath = `${Setting.value('resourceDir')}/${filename}`;
    await shim.fsDriver().copy(Resource.fullPath(resource), targetPath);

  • For some reason RN copy implementation deletes the target in case of an error:

    public async copy(source: string, dest: string) {
    let retry = false;
    try {
    await RNFS.copyFile(source, dest);
    } catch (error) {
    // On iOS it will throw an error if the file already exist
    retry = true;
    await this.unlink(dest);
    }

  • In this case the target was the resource dir and this is how the user lost all his resources.

Changes in this PR:

  • make sure the target name is never empty, if it is, use the default untitled
  • instead of creating a copy in the same dir where all resources are stored, use the cache dir, presumably these files are less sensitive
  • while fixing this I've noticed that when sharing to some apps (e.g. X-Plore File Manager) the call to Share.Open returns before the user has confirmed sharing, so Joplin deletes the file, and when the user finally confirms, the file is already gone. To fix this I've removed deletion. However according to Android docs the cache is not cleaned automatically so I've added a cleanup step on the app startup.
  • Finally, I noticed that the new version of react-native-share has a bug (which I've introduced there myself), until it's fixed (in Android: fix sharing a single file react-native-share/react-native-share#984) I downgraded the version With it sharing works even though there's an exception in Android log

While there is no such bug on iOS, as far as I know, these changes use only the API available on both platforms, so I believe it should be compatible with iOS.

@roman-r-m
Copy link
Copy Markdown
Contributor Author

roman-r-m commented Mar 22, 2021

* Finally, I noticed that the new version of `react-native-share` has a bug (which I've introduced there myself), until it's fixed (in [react-native-share/react-native-share#984](https://github.com/react-native-share/react-native-share/pull/984)) I downgraded the version With it sharing works even though there's an exception in Android log

This has been fixed in the latest version, I've updated the PR

@laurent22
Copy link
Copy Markdown
Owner

Thanks for the update @roman-r-m!

@laurent22 laurent22 merged commit e3efe70 into laurent22:dev Apr 7, 2021
@roman-r-m roman-r-m deleted the android-share-fix-III branch April 7, 2021 19:34
@PetrVladimirov
Copy link
Copy Markdown

@laurent22 - it is quite critical to have sharing functionality, especially while on travel... When to expect to have it rolled out to production? Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants