[PR #25466] fix(mobile): cancel share download when dialog is dismissed #18236

Open
opened 2026-02-05 16:34:58 +03:00 by OVERLORD · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/immich-app/immich/pull/25466
Author: @cmdPromptCritical
Created: 1/23/2026
Status: 🔄 Open

Base: mainHead: fix/share-cancellation-bug


📝 Commits (4)

  • 6514b20 fix(mobile): cancel share download when dialog is dismissed
  • c9683a2 refactor: centralize temporary file cleanup logic
  • 4ef0ce7 Merge branch 'main' into fix/share-cancellation-bug
  • bb2d79b refactor: replace CancellationToken with Completer<void> for asset sharing cancellation

📊 Changes

4 files changed (+64 additions, -22 deletions)

View changed files

📝 mobile/lib/presentation/widgets/action_buttons/share_action_button.widget.dart (+17 -6)
📝 mobile/lib/providers/infrastructure/action.provider.dart (+6 -2)
📝 mobile/lib/repositories/asset_media.repository.dart (+35 -12)
📝 mobile/lib/services/action.service.dart (+6 -2)

📄 Description

Description

This PR fixes a bug where interrupting the share process (e.g., by pressing the Android back button or using the back gesture during the "Preparing" stage) would not stop the asset download. This caused the system share sheet to pop up unexpectedly later once the download finished, even if the user had moved on from that intent.

Changes made:

  • Added a CancellationToken into the sharing flow to allow for explicit termination.
  • Updated AssetMediaRepository.shareAssets to check the cancellation status within the download loop and before triggering the system share sheet.
  • Immediate cleanup of temporary files if the operation is cancelled.
  • updated ShareActionButton to prevent a "Bad state: Cannot use 'ref' after the widget was disposed" crash by checking context.mounted and the cancellation status before accessing the Provider reference.

Fixes #22353

How Has This Been Tested?

  • Test A (Cancellation): Initiated a share for a large remote video. Pressed the back button during the "Preparing" dialog. Verified that the dialog disappeared and the system share sheet did not appear later.
  • Test B (Normal Share): Initiated a share and waited for the download to complete. Verified that the system share sheet appeared correctly with the file.

Screenshots (if appropriate)

Checklist:

  •  I have performed a self-review of my own code
  •  I have made corresponding changes to the documentation if applicable
  •  I have no unrelated changes in the PR.
  •  I have confirmed that any new dependencies are strictly necessary.
  •  I have written tests for new code (if applicable)
  •  I have followed naming conventions/patterns in the surrounding code
  • All code in src/services/ uses repositories implementations for database calls, filesystem operations, etc.
  • All code in src/repositories/ is pretty basic/simple and does not have any immich specific logic (that belongs in src/services/)

Please describe to which degree, if any, an LLM was used in creating this pull request.

  • I used it to query the app structure and provide suggested solution strategies
  • Used it to help debug error messages while implementing the solution

...


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/immich-app/immich/pull/25466 **Author:** [@cmdPromptCritical](https://github.com/cmdPromptCritical) **Created:** 1/23/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/share-cancellation-bug` --- ### 📝 Commits (4) - [`6514b20`](https://github.com/immich-app/immich/commit/6514b206c2f800ec4ae3980b33135724d3fc5f29) fix(mobile): cancel share download when dialog is dismissed - [`c9683a2`](https://github.com/immich-app/immich/commit/c9683a2aa43af6127d40a35eec5f4ff2a4dff51a) refactor: centralize temporary file cleanup logic - [`4ef0ce7`](https://github.com/immich-app/immich/commit/4ef0ce711cca87e478970bc71710737997cbcb22) Merge branch 'main' into fix/share-cancellation-bug - [`bb2d79b`](https://github.com/immich-app/immich/commit/bb2d79b4cd544b9edff3a7867619deb11383a901) refactor: replace `CancellationToken` with `Completer<void>` for asset sharing cancellation ### 📊 Changes **4 files changed** (+64 additions, -22 deletions) <details> <summary>View changed files</summary> 📝 `mobile/lib/presentation/widgets/action_buttons/share_action_button.widget.dart` (+17 -6) 📝 `mobile/lib/providers/infrastructure/action.provider.dart` (+6 -2) 📝 `mobile/lib/repositories/asset_media.repository.dart` (+35 -12) 📝 `mobile/lib/services/action.service.dart` (+6 -2) </details> ### 📄 Description ## Description This PR fixes a bug where interrupting the share process (e.g., by pressing the Android back button or using the back gesture during the "Preparing" stage) would not stop the asset download. This caused the system share sheet to pop up unexpectedly later once the download finished, even if the user had moved on from that intent. Changes made: - Added a CancellationToken into the sharing flow to allow for explicit termination. - Updated AssetMediaRepository.shareAssets to check the cancellation status within the download loop and before triggering the system share sheet. - Immediate cleanup of temporary files if the operation is cancelled. - updated ShareActionButton to prevent a "Bad state: Cannot use 'ref' after the widget was disposed" crash by checking context.mounted and the cancellation status before accessing the Provider reference. Fixes #22353 ## How Has This Been Tested? - [x] Test A (Cancellation): Initiated a share for a large remote video. Pressed the back button during the "Preparing" dialog. Verified that the dialog disappeared and the system share sheet did not appear later. - [x] Test B (Normal Share): Initiated a share and waited for the download to complete. Verified that the system share sheet appeared correctly with the file. <details><summary><h2>Screenshots (if appropriate)</h2></summary> </details> <!-- API endpoint changes (if relevant) ## API Changes - None --> ## Checklist: - [x]  I have performed a self-review of my own code - [x]  I have made corresponding changes to the documentation if applicable - [x]  I have no unrelated changes in the PR. - [x]  I have confirmed that any new dependencies are strictly necessary. - [ ]  I have written tests for new code (if applicable) - [x]  I have followed naming conventions/patterns in the surrounding code - [x] All code in `src/services/` uses repositories implementations for database calls, filesystem operations, etc. - [x] All code in `src/repositories/` is pretty basic/simple and does not have any immich specific logic (that belongs in `src/services/`) ## Please describe to which degree, if any, an LLM was used in creating this pull request. - I used it to query the app structure and provide suggested solution strategies - Used it to help debug error messages while implementing the solution ... --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
OVERLORD added the pull-request label 2026-02-05 16:34:58 +03:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: immich-app/immich#18236