-
Notifications
You must be signed in to change notification settings - Fork 82
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
benma
wants to merge
1
commit into
BitBoxSwiss:master
Choose a base branch
from
benma:ios-export
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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!) | ||
return fileURL.path | ||
} | ||
|
||
func auth() { | ||
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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) | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
@@ -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 | ||
} | ||
|
@@ -123,7 +158,7 @@ struct BitBoxAppApp: App { | |
} | ||
} | ||
} | ||
|
||
func setupGoAPI(goAPI: MobileserverGoAPIInterfaceProtocol) { | ||
let appSupportDirectory = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first! | ||
do { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 insystemOpen
for the urlString