mirror of
https://github.com/leonboe1/QuickDrop.git
synced 2026-11-11 02:51:11 +00:00
Fix error message on share extension disappearing too quickly
This commit is contained in:
1 parent
28178a7e6a
commit
f6588c3c43
2 files changed
+17
-5
No files matched your search
@@ -47,7 +47,9 @@ class ErrorAlertHandler {
|
|||||||
/// "download the app from Google Play" suggestion is omitted from the fix instructions (see
|
/// "download the app from Google Play" suggestion is omitted from the fix instructions (see
|
||||||
/// `fixInstructionsKey(isQuickDropPeer:)`). Defaults to `false` so callers without device context
|
/// `fixInstructionsKey(isQuickDropPeer:)`). Defaults to `false` so callers without device context
|
||||||
/// keep the full hint.
|
/// keep the full hint.
|
||||||
func showErrorAlert(for deviceName: String, error: Error, isQuickDropPeer: Bool = false) {
|
/// - Parameter completion: called after the macOS transfer alert is dismissed. For issue-specific
|
||||||
|
/// alerts and iOS alerts, it is called after presentation.
|
||||||
|
func showErrorAlert(for deviceName: String, error: Error, isQuickDropPeer: Bool = false, completion: (() -> Void)? = nil) {
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
NSApp.activate(ignoringOtherApps: true)
|
NSApp.activate(ignoringOtherApps: true)
|
||||||
#endif
|
#endif
|
||||||
@@ -63,6 +65,7 @@ class ErrorAlertHandler {
|
|||||||
case .packetFilterError:
|
case .packetFilterError:
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
openAlert(type: .NetworkFilter)
|
openAlert(type: .NetworkFilter)
|
||||||
|
completion?()
|
||||||
return
|
return
|
||||||
#else
|
#else
|
||||||
description = error.localizedDescription
|
description = error.localizedDescription
|
||||||
@@ -70,6 +73,7 @@ class ErrorAlertHandler {
|
|||||||
case .firewallError:
|
case .firewallError:
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
openAlert(type: .Firewall)
|
openAlert(type: .Firewall)
|
||||||
|
completion?()
|
||||||
return
|
return
|
||||||
#else
|
#else
|
||||||
description = error.localizedDescription
|
description = error.localizedDescription
|
||||||
@@ -95,6 +99,7 @@ class ErrorAlertHandler {
|
|||||||
// Prevent multiple alerts at the same time
|
// Prevent multiple alerts at the same time
|
||||||
if self.isAlertShown {
|
if self.isAlertShown {
|
||||||
log("Skipping alert for error \(error.localizedDescription) because one is already shown")
|
log("Skipping alert for error \(error.localizedDescription) because one is already shown")
|
||||||
|
completion?()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -110,9 +115,10 @@ class ErrorAlertHandler {
|
|||||||
// runModal(), which blocks the main run loop and would freeze the next incoming transfer's
|
// runModal(), which blocks the main run loop and would freeze the next incoming transfer's
|
||||||
// consent prompt until dismissed. Same window runModal() uses, so it looks identical.
|
// consent prompt until dismissed. Same window runModal() uses, so it looks identical.
|
||||||
self.isAlertShown = true
|
self.isAlertShown = true
|
||||||
presentTransferErrorAlert(title: title, description: description)
|
presentTransferErrorAlert(title: title, description: description, completion: completion)
|
||||||
#else
|
#else
|
||||||
showAlert(title: title, message: description)
|
showAlert(title: title, message: description)
|
||||||
|
completion?()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -200,7 +206,7 @@ class ErrorAlertHandler {
|
|||||||
/// incoming transfer's consent prompt can still appear while it's on screen. It's the same
|
/// incoming transfer's consent prompt can still appear while it's on screen. It's the same
|
||||||
/// `_NSAlertPanel` window `runModal()` would show, so it looks identical; we just route the button
|
/// `_NSAlertPanel` window `runModal()` would show, so it looks identical; we just route the button
|
||||||
/// clicks ourselves (there's no modal session to end) and reset state on dismissal.
|
/// clicks ourselves (there's no modal session to end) and reset state on dismissal.
|
||||||
private func presentTransferErrorAlert(title: String, description: String) {
|
private func presentTransferErrorAlert(title: String, description: String, completion: (() -> Void)? = nil) {
|
||||||
let alert = NSAlert()
|
let alert = NSAlert()
|
||||||
alert.alertStyle = .critical
|
alert.alertStyle = .critical
|
||||||
alert.messageText = title
|
alert.messageText = title
|
||||||
@@ -215,6 +221,7 @@ class ErrorAlertHandler {
|
|||||||
if response == .alertFirstButtonReturn {
|
if response == .alertFirstButtonReturn {
|
||||||
Self.presentLogUpload()
|
Self.presentLogUpload()
|
||||||
}
|
}
|
||||||
|
completion?()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -228,8 +228,13 @@ class ShareViewController: NSViewController, OutboundAppDelegate {
|
|||||||
progressProgressBar?.doubleValue = 0
|
progressProgressBar?.doubleValue = 0
|
||||||
lastError = error
|
lastError = error
|
||||||
|
|
||||||
ErrorAlertHandler.shared.showErrorAlert(for: chosenDevice?.name ?? "", error: error, isQuickDropPeer: chosenDevice?.isQuickDropPeer ?? false)
|
ErrorAlertHandler.shared.showErrorAlert(
|
||||||
self.extensionContext!.cancelRequest(withError: error)
|
for: chosenDevice?.name ?? "",
|
||||||
|
error: error,
|
||||||
|
isQuickDropPeer: chosenDevice?.isQuickDropPeer ?? false
|
||||||
|
) { [weak self] in
|
||||||
|
self?.extensionContext?.cancelRequest(withError: error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user