From 328e6e712c6d41310392dd4f71a90eba94aa7ca5 Mon Sep 17 00:00:00 2001 From: bjoern Date: Thu, 13 Feb 2025 11:36:08 +0100 Subject: [PATCH] share files generated by webxdc (#2606) * add option to share files generated by webxdc * display name correctly in the share dialog use temp. directory, this somehow displays the name correctly in the share dialog (we use the same for sharing log) * update CHANGELOG --- CHANGELOG.md | 1 + deltachat-ios/Controller/WebxdcViewController.swift | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5716690d..f57943dce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased 2025-02 +- Share files generated by webxdc apps directly (#2606) - Tweak menu order (#2604) - Fix: Preserve filenames on sharing (#2605) diff --git a/deltachat-ios/Controller/WebxdcViewController.swift b/deltachat-ios/Controller/WebxdcViewController.swift index 558bf6f2e..e43020680 100644 --- a/deltachat-ios/Controller/WebxdcViewController.swift +++ b/deltachat-ios/Controller/WebxdcViewController.swift @@ -528,6 +528,19 @@ extension WebxdcViewController: WKScriptMessageHandler { rootController.popToRootViewController(animated: false) } })) + + if let name = dict["name"] as? String { + alert.addAction(UIAlertAction(title: String.localized("menu_share"), style: .default, handler: { [weak self] _ in + guard let self else { return } + if let base64 = dict["base64"] as? String, let data = Data(base64Encoded: base64), let sourceItem = navigationItem.rightBarButtonItem { + let fileURL = FileManager.default.temporaryDirectory.appendingPathComponent(name) + try? FileManager.default.removeItem(at: fileURL) + try? data.write(to: fileURL) + Utils.share(url: fileURL, parentViewController: self, sourceItem: sourceItem) + } + })) + } + alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil)) self.present(alert, animated: true, completion: nil) }