Fixes and improvements

release
Laurent 3 years ago
parent a85d23d18e
commit 7a26b67f57
  1. 4
      LeCountdown/LeCountdownApp.swift
  2. 42
      LeCountdown/Views/ContentView.swift
  3. 3
      LeCountdown/Views/NewCountdownView.swift

@ -26,7 +26,9 @@ struct LeCountdownApp: App {
}
fileprivate func _willEnterForegroundNotification() {
AppEnvironment.sun.cleanup()
DispatchQueue.main.async {
AppEnvironment.sun.cleanup()
}
}
}

@ -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 {

@ -218,6 +218,9 @@ struct CountdownEditView : View {
viewContext.delete(countdown)
self._saveContext()
WidgetCenter.shared.reloadAllTimelines() // refreshes the visual of existing widgets
self._popOrDismiss()
}

Loading…
Cancel
Save