|
|
|
|
@ -50,7 +50,8 @@ struct ContentView: View { |
|
|
|
|
@State private var isShowingNewCountdown = false |
|
|
|
|
|
|
|
|
|
@State var error: Error? |
|
|
|
|
@State var showAlert: Bool = false |
|
|
|
|
@State var showDefaultAlert: Bool = false |
|
|
|
|
@State var showPermissionAlert: Bool = false |
|
|
|
|
|
|
|
|
|
private var columns: [GridItem] = [ |
|
|
|
|
GridItem(spacing: 10.0), |
|
|
|
|
@ -96,9 +97,15 @@ struct ContentView: View { |
|
|
|
|
|
|
|
|
|
}.padding(itemSpacing) |
|
|
|
|
.navigationTitle("Youpi") |
|
|
|
|
.alert(error?.localizedDescription ?? "missing error", isPresented: $showAlert) { |
|
|
|
|
Button("OK", role: .none) { } |
|
|
|
|
.alert(error?.localizedDescription ?? "missing error", isPresented: $showDefaultAlert) { |
|
|
|
|
Button("OK", role: .cancel) { } |
|
|
|
|
} |
|
|
|
|
.alert("You need to accept notifications, please check your settings", isPresented: $showPermissionAlert, actions: { |
|
|
|
|
Button("Show permissions") { |
|
|
|
|
self._showPermissionSettings() |
|
|
|
|
} |
|
|
|
|
Button("OK", role: .cancel) { } |
|
|
|
|
}) |
|
|
|
|
.sheet(isPresented: self.$isShowingNewCountdown, content: { |
|
|
|
|
NewCountdownView(isPresented: $isShowingNewCountdown) .environment(\.managedObjectContext, viewContext) |
|
|
|
|
}) |
|
|
|
|
@ -141,13 +148,22 @@ struct ContentView: View { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileprivate func _launchCountdown(_ countdown: Countdown) { |
|
|
|
|
CountdownScheduler.master.scheduleIfPossible(countdown: countdown) { result in |
|
|
|
|
switch result { |
|
|
|
|
case .success(_): |
|
|
|
|
break |
|
|
|
|
case .failure(let failure): |
|
|
|
|
self.error = failure |
|
|
|
|
self.showAlert = true |
|
|
|
|
|
|
|
|
|
UNUserNotificationCenter.current().getNotificationSettings { settings in |
|
|
|
|
|
|
|
|
|
switch settings.authorizationStatus { |
|
|
|
|
case .notDetermined, .denied: |
|
|
|
|
self.showPermissionAlert = true |
|
|
|
|
default: |
|
|
|
|
CountdownScheduler.master.scheduleIfPossible(countdown: countdown) { result in |
|
|
|
|
switch result { |
|
|
|
|
case .success(_): |
|
|
|
|
break |
|
|
|
|
case .failure(let failure): |
|
|
|
|
self.error = failure |
|
|
|
|
self.showDefaultAlert = true |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -158,6 +174,12 @@ struct ContentView: View { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileprivate func _showPermissionSettings() { |
|
|
|
|
if let url = URL(string: UIApplication.openNotificationSettingsURLString) { |
|
|
|
|
UIApplication.shared.open(url) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileprivate extension Countdown { |
|
|
|
|
|