Fixes and improvements

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

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

@ -50,7 +50,8 @@ struct ContentView: View {
@State private var isShowingNewCountdown = false @State private var isShowingNewCountdown = false
@State var error: Error? @State var error: Error?
@State var showAlert: Bool = false @State var showDefaultAlert: Bool = false
@State var showPermissionAlert: Bool = false
private var columns: [GridItem] = [ private var columns: [GridItem] = [
GridItem(spacing: 10.0), GridItem(spacing: 10.0),
@ -96,9 +97,15 @@ struct ContentView: View {
}.padding(itemSpacing) }.padding(itemSpacing)
.navigationTitle("Youpi") .navigationTitle("Youpi")
.alert(error?.localizedDescription ?? "missing error", isPresented: $showAlert) { .alert(error?.localizedDescription ?? "missing error", isPresented: $showDefaultAlert) {
Button("OK", role: .none) { } 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: { .sheet(isPresented: self.$isShowingNewCountdown, content: {
NewCountdownView(isPresented: $isShowingNewCountdown) .environment(\.managedObjectContext, viewContext) NewCountdownView(isPresented: $isShowingNewCountdown) .environment(\.managedObjectContext, viewContext)
}) })
@ -141,13 +148,22 @@ struct ContentView: View {
} }
fileprivate func _launchCountdown(_ countdown: Countdown) { fileprivate func _launchCountdown(_ countdown: Countdown) {
UNUserNotificationCenter.current().getNotificationSettings { settings in
switch settings.authorizationStatus {
case .notDetermined, .denied:
self.showPermissionAlert = true
default:
CountdownScheduler.master.scheduleIfPossible(countdown: countdown) { result in CountdownScheduler.master.scheduleIfPossible(countdown: countdown) { result in
switch result { switch result {
case .success(_): case .success(_):
break break
case .failure(let failure): case .failure(let failure):
self.error = failure self.error = failure
self.showAlert = true 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 { fileprivate extension Countdown {

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

Loading…
Cancel
Save