mirror of
https://github.com/leonboe1/QuickDrop.git
synced 2026-11-20 13:26:03 +00:00
Refactor UIAlertController Logic
This commit is contained in:
1 parent
21f0f865b6
commit
4e73fced74
8 files changed
+62
-41
No files matched your search
@@ -589,6 +589,13 @@ class InboundNearbyConnection: NearbyConnection {
|
|||||||
if storeInTemp {
|
if storeInTemp {
|
||||||
log("[InboundNearbyConnection \(self.id)] File transfer restrictions detected, storing files in temporary directory.")
|
log("[InboundNearbyConnection \(self.id)] File transfer restrictions detected, storing files in temporary directory.")
|
||||||
delegate?.showPlusScreen()
|
delegate?.showPlusScreen()
|
||||||
|
|
||||||
|
#if os(iOS)
|
||||||
|
// Continue transfer for macOS only
|
||||||
|
// On iOS, the transfer should be cancelled by user
|
||||||
|
rejectTransfer()
|
||||||
|
return
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
|||||||
@@ -111,14 +111,8 @@ extension String {
|
|||||||
|
|
||||||
|
|
||||||
public func fullVersion() -> Bool {
|
public func fullVersion() -> Bool {
|
||||||
|
|
||||||
#if os(macOS)
|
|
||||||
// Enable full functionality if app distributed directly
|
// Enable full functionality if app distributed directly
|
||||||
return Settings.shared.gotPlus || DistributionDetector.isDirectDistributionEnabled
|
return Settings.shared.gotPlus || DistributionDetector.isDirectDistributionEnabled
|
||||||
#else
|
|
||||||
// iOS
|
|
||||||
return true
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,7 @@
|
|||||||
EB16B77A2E59BAA1007D9792 /* AppGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB16B7762E59BA9F007D9792 /* AppGroup.swift */; };
|
EB16B77A2E59BAA1007D9792 /* AppGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB16B7762E59BA9F007D9792 /* AppGroup.swift */; };
|
||||||
EB2F9BFE2DA05F48004010A2 /* BezelNotification in Frameworks */ = {isa = PBXBuildFile; productRef = EB2F9BFD2DA05F48004010A2 /* BezelNotification */; };
|
EB2F9BFE2DA05F48004010A2 /* BezelNotification in Frameworks */ = {isa = PBXBuildFile; productRef = EB2F9BFD2DA05F48004010A2 /* BezelNotification */; };
|
||||||
EB3643602D73A2A2009CDFF8 /* AudioManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB36435F2D73A29F009CDFF8 /* AudioManager.swift */; };
|
EB3643602D73A2A2009CDFF8 /* AudioManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB36435F2D73A29F009CDFF8 /* AudioManager.swift */; };
|
||||||
|
EB4F9D1D2EC113EA00A74A0F /* DistributionDetector.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB704A812E4A7BAE008E608F /* DistributionDetector.swift */; };
|
||||||
EB5C36932E34EBBD0052EFD7 /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = EB5C36922E34EBBD0052EFD7 /* Localizable.xcstrings */; };
|
EB5C36932E34EBBD0052EFD7 /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = EB5C36922E34EBBD0052EFD7 /* Localizable.xcstrings */; };
|
||||||
EB5C36942E34EBBD0052EFD7 /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = EB5C36922E34EBBD0052EFD7 /* Localizable.xcstrings */; };
|
EB5C36942E34EBBD0052EFD7 /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = EB5C36922E34EBBD0052EFD7 /* Localizable.xcstrings */; };
|
||||||
EB5C36E42E34EC0E0052EFD7 /* License.txt in Resources */ = {isa = PBXBuildFile; fileRef = EB5C36E32E34EC0E0052EFD7 /* License.txt */; };
|
EB5C36E42E34EC0E0052EFD7 /* License.txt in Resources */ = {isa = PBXBuildFile; fileRef = EB5C36E32E34EC0E0052EFD7 /* License.txt */; };
|
||||||
@@ -1098,6 +1099,7 @@
|
|||||||
EB950B6F2E5206E2002D68FA /* ShareViewController.swift in Sources */,
|
EB950B6F2E5206E2002D68FA /* ShareViewController.swift in Sources */,
|
||||||
EB950B432E52038A002D68FA /* ContentView.swift in Sources */,
|
EB950B432E52038A002D68FA /* ContentView.swift in Sources */,
|
||||||
EB950B442E520414002D68FA /* License.swift in Sources */,
|
EB950B442E520414002D68FA /* License.swift in Sources */,
|
||||||
|
EB4F9D1D2EC113EA00A74A0F /* DistributionDetector.swift in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -32,8 +32,8 @@
|
|||||||
</TestAction>
|
</TestAction>
|
||||||
<LaunchAction
|
<LaunchAction
|
||||||
buildConfiguration = "Debug"
|
buildConfiguration = "Debug"
|
||||||
selectedDebuggerIdentifier = ""
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
launchStyle = "0"
|
launchStyle = "0"
|
||||||
useCustomWorkingDirectory = "NO"
|
useCustomWorkingDirectory = "NO"
|
||||||
ignoresPersistentStateOnLaunch = "NO"
|
ignoresPersistentStateOnLaunch = "NO"
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ struct CapsuleProgress: View {
|
|||||||
struct QuickDropToastView_Previews: PreviewProvider {
|
struct QuickDropToastView_Previews: PreviewProvider {
|
||||||
struct Demo: View {
|
struct Demo: View {
|
||||||
|
|
||||||
@State var model = ReceiveModel()
|
@State var model = ReceiveModel(controlPlusScreen: { _ in })
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
QuickDropToastView(
|
QuickDropToastView(
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import LUI
|
|||||||
|
|
||||||
class ReceiveModel: ObservableObject, InboundAppDelegate {
|
class ReceiveModel: ObservableObject, InboundAppDelegate {
|
||||||
|
|
||||||
|
|
||||||
/// For each connection ID, store the last reported progress value
|
/// For each connection ID, store the last reported progress value
|
||||||
private var processes: [String: Double] = [:]
|
private var processes: [String: Double] = [:]
|
||||||
|
|
||||||
@@ -29,7 +28,8 @@ class ReceiveModel: ObservableObject, InboundAppDelegate {
|
|||||||
|
|
||||||
let controlPlusScreen: (Bool) -> Void
|
let controlPlusScreen: (Bool) -> Void
|
||||||
|
|
||||||
init(controlPlusScreen: @escaping (Bool) -> Void = { _ in }) {
|
|
||||||
|
init(controlPlusScreen: @escaping (Bool) -> Void) {
|
||||||
self.controlPlusScreen = controlPlusScreen
|
self.controlPlusScreen = controlPlusScreen
|
||||||
NearbyConnectionManager.shared.addInboundAppDelegate(self)
|
NearbyConnectionManager.shared.addInboundAppDelegate(self)
|
||||||
NearbyConnectionManager.shared.becomeVisible()
|
NearbyConnectionManager.shared.becomeVisible()
|
||||||
@@ -103,8 +103,6 @@ class ReceiveModel: ObservableObject, InboundAppDelegate {
|
|||||||
case .Decline:
|
case .Decline:
|
||||||
secondaryButtonAction()
|
secondaryButtonAction()
|
||||||
}
|
}
|
||||||
} onCancel: {
|
|
||||||
NearbyConnectionManager.shared.cancelTransfer(id: transferID)
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -146,11 +144,6 @@ class ReceiveModel: ObservableObject, InboundAppDelegate {
|
|||||||
if transfer.type == .text {
|
if transfer.type == .text {
|
||||||
showAlert(title: "QuickDrop", message: mainMessage)
|
showAlert(title: "QuickDrop", message: mainMessage)
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
ProgressAlert.shared.showProgressAlert(onCancel: {
|
|
||||||
NearbyConnectionManager.shared.cancelTransfer(id: transfer.id)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,7 +158,9 @@ class ReceiveModel: ObservableObject, InboundAppDelegate {
|
|||||||
let averageProgress = totalProgress / Double(processes.count)
|
let averageProgress = totalProgress / Double(processes.count)
|
||||||
|
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
ProgressAlert.shared.updateProgress(averageProgress)
|
ProgressAlert.shared.updateProgress(averageProgress, onCancel: {
|
||||||
|
NearbyConnectionManager.shared.cancelTransfer(id: connectionID)
|
||||||
|
})
|
||||||
#else
|
#else
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.progress = averageProgress
|
self.progress = averageProgress
|
||||||
|
|||||||
@@ -41,9 +41,14 @@ struct DeviceListView: View {
|
|||||||
@State private var qrCode: Image? = nil
|
@State private var qrCode: Image? = nil
|
||||||
@StateObject var sendModel = SendModel()
|
@StateObject var sendModel = SendModel()
|
||||||
|
|
||||||
#if !EXTENSION
|
#if !EXTENSION
|
||||||
@StateObject var receiveModel = ReceiveModel()
|
@StateObject var receiveModel = ReceiveModel(controlPlusScreen: { show in
|
||||||
#endif
|
log("[DeviceListView] Setting showPlusScreen to \(show)")
|
||||||
|
DeviceListViewModel.sharedInstance.showPlusScreen = show
|
||||||
|
})
|
||||||
|
#endif
|
||||||
|
|
||||||
|
@ObservedObject var model = DeviceListViewModel.sharedInstance
|
||||||
|
|
||||||
@Environment(\.scenePhase) var scenePhase
|
@Environment(\.scenePhase) var scenePhase
|
||||||
@Environment(\.sheetActive) var sheetActive
|
@Environment(\.sheetActive) var sheetActive
|
||||||
@@ -54,7 +59,7 @@ struct DeviceListView: View {
|
|||||||
|
|
||||||
let showsLoadingIndicator = nearbyConnectionManager.hasLocalNetworkPermission && nearbyConnectionManager.isConnectedToLocalNetwork
|
let showsLoadingIndicator = nearbyConnectionManager.hasLocalNetworkPermission && nearbyConnectionManager.isConnectedToLocalNetwork
|
||||||
|
|
||||||
BottomBarView(header: "QuickDrop ", navigationBarLayout: isShareExtension() ? .SmallOnlyAlways : .Default, bottomViewHeight: 30) {
|
BottomBarView(header: "QuickDrop", navigationBarLayout: isShareExtension() ? .SmallOnlyAlways : .Default, bottomViewHeight: 30) {
|
||||||
VStack {
|
VStack {
|
||||||
|
|
||||||
VStack(alignment: .leading, spacing: 8) {
|
VStack(alignment: .leading, spacing: 8) {
|
||||||
@@ -185,7 +190,7 @@ struct DeviceListView: View {
|
|||||||
|
|
||||||
log("[ScenePhase] App became active")
|
log("[ScenePhase] App became active")
|
||||||
NearbyConnectionManager.shared.startDeviceDiscovery()
|
NearbyConnectionManager.shared.startDeviceDiscovery()
|
||||||
#if !EXTENSION
|
#if !EXTENSION
|
||||||
NearbyConnectionManager.shared.becomeVisible()
|
NearbyConnectionManager.shared.becomeVisible()
|
||||||
|
|
||||||
if Settings.shared.incomingTransmissionCount > 0 {
|
if Settings.shared.incomingTransmissionCount > 0 {
|
||||||
@@ -193,18 +198,21 @@ struct DeviceListView: View {
|
|||||||
requestReviewOnce()
|
requestReviewOnce()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if newValue == .background {
|
if newValue == .background {
|
||||||
|
|
||||||
log("[ScenePhase] App went to background")
|
log("[ScenePhase] App went to background")
|
||||||
#if !EXTENSION
|
#if !EXTENSION
|
||||||
NearbyConnectionManager.shared.becomeInvisible()
|
NearbyConnectionManager.shared.becomeInvisible()
|
||||||
#endif
|
#endif
|
||||||
NearbyConnectionManager.shared.stopDeviceDiscovery()
|
NearbyConnectionManager.shared.stopDeviceDiscovery()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if !EXTENSION
|
||||||
|
.modifier(PlusVersionSheetModifier(sheetActive: $model.showPlusScreen, isPlusVersion: $settings.gotPlus))
|
||||||
|
#endif
|
||||||
.animation(.smooth, value: nearbyConnectionManager.hasLocalNetworkPermission)
|
.animation(.smooth, value: nearbyConnectionManager.hasLocalNetworkPermission)
|
||||||
.animation(.smooth, value: nearbyConnectionManager.isConnectedToLocalNetwork)
|
.animation(.smooth, value: nearbyConnectionManager.isConnectedToLocalNetwork)
|
||||||
.navigationBarItems(trailing: ZStack {
|
.navigationBarItems(trailing: ZStack {
|
||||||
@@ -218,6 +226,12 @@ struct DeviceListView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final class DeviceListViewModel: SharedInstance {
|
||||||
|
static var sharedInstance = DeviceListViewModel()
|
||||||
|
|
||||||
|
@Published var showPlusScreen = false
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
struct DeviceFilePickerButton: View {
|
struct DeviceFilePickerButton: View {
|
||||||
|
|
||||||
@@ -297,11 +311,11 @@ struct DeviceButtonLabel: View {
|
|||||||
|
|
||||||
|
|
||||||
func isShareExtension() -> Bool {
|
func isShareExtension() -> Bool {
|
||||||
#if EXTENSION
|
#if EXTENSION
|
||||||
return true
|
return true
|
||||||
#else
|
#else
|
||||||
return false
|
return false
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ final class ProgressAlert {
|
|||||||
private weak var progressView: UIProgressView?
|
private weak var progressView: UIProgressView?
|
||||||
|
|
||||||
// MARK: - Initial Accept / Decline
|
// MARK: - Initial Accept / Decline
|
||||||
func askForUserPermission(title: String, message: String, acceptLabel: String, acceptAlwaysLabel: String?, rejectLabel: String, onAccept: @escaping (AcceptAction) -> Void, onCancel: @escaping () -> Void) {
|
func askForUserPermission(title: String, message: String, acceptLabel: String, acceptAlwaysLabel: String?, rejectLabel: String, onAccept: @escaping (AcceptAction) -> Void) {
|
||||||
guard let vc = topMostViewController() else { return }
|
guard let vc = topMostViewController() else { return }
|
||||||
|
|
||||||
let alert = UIAlertController(title: title,
|
let alert = UIAlertController(title: title,
|
||||||
@@ -31,13 +31,11 @@ final class ProgressAlert {
|
|||||||
|
|
||||||
alert.addAction(UIAlertAction(title: acceptLabel, style: .default, handler: { _ in
|
alert.addAction(UIAlertAction(title: acceptLabel, style: .default, handler: { _ in
|
||||||
onAccept(.Accept)
|
onAccept(.Accept)
|
||||||
self.showProgressAlert(on: vc, onCancel: onCancel)
|
|
||||||
}))
|
}))
|
||||||
|
|
||||||
if let acceptAlways = acceptAlwaysLabel {
|
if let acceptAlways = acceptAlwaysLabel {
|
||||||
alert.addAction(UIAlertAction(title: acceptAlways, style: .default, handler: { _ in
|
alert.addAction(UIAlertAction(title: acceptAlways, style: .default, handler: { _ in
|
||||||
onAccept(.AcceptAlways)
|
onAccept(.AcceptAlways)
|
||||||
self.showProgressAlert(on: vc, onCancel: onCancel)
|
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,14 +43,11 @@ final class ProgressAlert {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func showProgressAlert(onCancel: @escaping () -> Void) {
|
|
||||||
guard let vc = topMostViewController() else { return }
|
|
||||||
self.showProgressAlert(on: vc, onCancel: onCancel)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// MARK: - Progress Alert
|
// MARK: - Progress Alert
|
||||||
private func showProgressAlert(on vc: UIViewController, onCancel: @escaping () -> Void) {
|
private func showProgressAlert(onCancel: @escaping () -> Void) {
|
||||||
|
|
||||||
|
guard let vc = topMostViewController() else { return }
|
||||||
|
|
||||||
let alert = UIAlertController(title: "Receiving".localized(),
|
let alert = UIAlertController(title: "Receiving".localized(),
|
||||||
message: "\n\n",
|
message: "\n\n",
|
||||||
preferredStyle: .alert)
|
preferredStyle: .alert)
|
||||||
@@ -78,10 +73,24 @@ final class ProgressAlert {
|
|||||||
vc.present(alert, animated: true)
|
vc.present(alert, animated: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: - Update Progress
|
// MARK: - Update Progress
|
||||||
// progress: 0…1 → update progress, nil → finished
|
// progress: 0…1 → update progress, nil → finished
|
||||||
func updateProgress(_ progress: Double?, completion: @escaping () -> Void = {}) {
|
func updateProgress(_ progress: Double?, onCancel: @escaping () -> Void, completion: @escaping () -> Void = {}) {
|
||||||
|
|
||||||
|
// No progress to show, nothing shown currently → just complete
|
||||||
|
if progressAlert == nil && progress == nil {
|
||||||
|
completion()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
|
||||||
|
// Show progress if not shown yet
|
||||||
|
if self.progressAlert == nil {
|
||||||
|
self.showProgressAlert(onCancel: onCancel)
|
||||||
|
}
|
||||||
|
|
||||||
if let p = progress {
|
if let p = progress {
|
||||||
self.progressView?.setProgress(Float(p), animated: true)
|
self.progressView?.setProgress(Float(p), animated: true)
|
||||||
completion()
|
completion()
|
||||||
|
|||||||
Reference in new issue
Block a user