Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Fix #3323: Fix issue with temporary files not stored properly the fir…
Browse files Browse the repository at this point in the history
…st time
  • Loading branch information
cuba committed Mar 3, 2022
1 parent cddfa18 commit 52e0ab1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
20 changes: 11 additions & 9 deletions Client/Frontend/Browser/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2636,15 +2636,17 @@ extension BrowserViewController: WKUIDelegate {
let touchSize = CGSize(width: 0, height: 16)
let touchRect = CGRect(origin: touchPoint, size: touchSize)

// TODO: Find a way to support "Save to files" (Similar to Fix #3323):
// Normally we use `tab.temporaryDocument` for the downloaded file on the tab
// tab.temporaryDocument returns the downloaded image file to disk on the current tab.
// A downloaded file then in turn uses standard share items
// This results in having functions like "Save to files" available.
// Since this is not a tab but a standalone web view, the downloaded temporary file is not available.
// Other possibilities to fix this exist, including:
// - Allow share extension helper to download the file itself.
// - Add custom "Save to file" functionality (needs investigation)
// TODO: Find a way to add fixes #3323 and #2961 here:
// Normally we use `tab.temporaryDocument` for the downloaded file on the tab.
// `temporaryDocument` returns the downloaded image file to disk on the current tab.
// Using a downloaded file url results in having functions like "Save to files" available.
// It also attaches the file (image, pdf, etc) and not the url to emails, slack, etc.
// Since this is **not** a tab but a standalone web view, the downloaded temporary file is **not** available.
// This results in the fixes for #3323 and #2961 not being included in this share scenario.
// This is not a regression, we simply never handled this scenario in both fixes.
// Some possibile fixes include:
// - Detect the file type and download it if necessary and don't rely on the `tab.temporaryDocument`.
// - Add custom "Save to file" functionality (needs investigation).
self.presentActivityViewController(url, sourceView: self.view,
sourceRect: touchRect,
arrowDirection: .any)
Expand Down
7 changes: 6 additions & 1 deletion Client/Frontend/Browser/TemporaryDocument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ class TemporaryDocument: NSObject {

do {
try FileManager.default.createDirectory(at: tempDirectory, withIntermediateDirectories: true, attributes: nil)
try FileManager.default.removeItem(at: url)

// Delete the file if there is already one. We will replace it with a new file
if FileManager.default.fileExists(atPath: url.absoluteString) {
try FileManager.default.removeItem(at: url)
}

try data.write(to: url, options: [.atomic])

localFileURL = url
Expand Down

0 comments on commit 52e0ab1

Please # to comment.