Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ios: fix exporting files (CSV exports, log export, notes export) #2939

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 46 additions & 11 deletions frontends/ios/BitBoxApp/BitBoxApp/BitBoxAppApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ protocol SetMessageHandlersProtocol {
func setMessageHandlers(handlers: MessageHandlersProtocol)
}

class GoEnvironment: NSObject, MobileserverGoEnvironmentInterfaceProtocol {
func getSaveFilename(_ p0: String?) -> String {
// TODO
return ""
class GoEnvironment: NSObject, MobileserverGoEnvironmentInterfaceProtocol, UIDocumentInteractionControllerDelegate {
func getSaveFilename(_ fileName: String?) -> String {
let tempDirectory = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
let fileURL = tempDirectory.appendingPathComponent(fileName!)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need a guard for fileName, like the one used in systemOpen for the urlString

return fileURL.path
}

func auth() {
Expand Down Expand Up @@ -75,10 +76,44 @@ class GoEnvironment: NSObject, MobileserverGoEnvironmentInterfaceProtocol {
func setDarkTheme(_ p0: Bool) {
}

func systemOpen(_ url: String?) throws {
guard let url = URL(string: url!) else { return }
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url)
// Helper method to get the root view controller
private func getRootViewController() -> UIViewController? {
guard let scene = UIApplication.shared.connectedScenes
.filter({ $0.activationState == .foregroundActive })
.first as? UIWindowScene else {
return nil
}

return scene.windows.first(where: { $0.isKeyWindow })?.rootViewController
}

func systemOpen(_ urlString: String?) throws {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function doesn't throw any exception, I think you can remove the throws keyword

guard let urlString = urlString else { return }
// Check if it's a local file path (not a URL)
var url: URL
if urlString.hasPrefix("/") {
// This is a local file path, construct a file URL
url = URL(fileURLWithPath: urlString)
} else if let potentialURL = URL(string: urlString), potentialURL.scheme != nil {
// This is already a valid URL with a scheme
url = potentialURL
} else {
// Invalid URL or path
return
}
// Ensure we run on the main thread
DispatchQueue.main.async {
if url.isFileURL {
// Local file path, use UIDocumentInteractionController
if let rootViewController = self.getRootViewController() {
let activityViewController = UIActivityViewController(activityItems: [url], applicationActivities: nil)
rootViewController.present(activityViewController, animated: true, completion: nil)
}
} else {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url)
}
}
}
}

Expand All @@ -91,15 +126,15 @@ class GoEnvironment: NSObject, MobileserverGoEnvironmentInterfaceProtocol {

class GoAPI: NSObject, MobileserverGoAPIInterfaceProtocol, SetMessageHandlersProtocol {
var handlers: MessageHandlersProtocol?

func pushNotify(_ msg: String?) {
self.handlers?.pushNotificationHandler(msg: msg!)
}

func respond(_ queryID: Int, response: String?) {
self.handlers?.callResponseHandler(queryID: queryID, response: response!)
}

func setMessageHandlers(handlers: MessageHandlersProtocol) {
self.handlers = handlers
}
Expand All @@ -123,7 +158,7 @@ struct BitBoxAppApp: App {
}
}
}

func setupGoAPI(goAPI: MobileserverGoAPIInterfaceProtocol) {
let appSupportDirectory = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first!
do {
Expand Down
4 changes: 2 additions & 2 deletions util/config/appdir.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ func AppDir() string {

// ExportsDir returns the absolute path to the folder which can be used to export files.
func ExportsDir() (string, error) {
if runtime.GOOS == "android" {
// Android apps are sandboxed, we don't need to specify a folder.
if runtime.GOOS == "android" || runtime.GOOS == "ios" {
// Android/iOS apps are sandboxed, we don't need to specify a folder.
return "", nil
}
homeFolder := os.Getenv("HOME")
Expand Down
Loading