Multiple bug fixes + new settings for volume

main
Laurent 2 years ago
parent 927fbef4e6
commit 4902513bd9
  1. 5
      LeCountdown/AppDelegate.swift
  2. 23
      LeCountdown/Conductor.swift
  3. 2
      LeCountdown/Utils/Preferences.swift
  4. 5
      LeCountdown/Views/Reusable/VolumeView.swift
  5. 27
      LeCountdown/Views/SettingsView.swift

@ -46,6 +46,10 @@ class AppDelegate : NSObject, UIApplicationDelegate {
func applicationWillTerminate(_ application: UIApplication) { func applicationWillTerminate(_ application: UIApplication) {
Logger.log("applicationWillTerminate") Logger.log("applicationWillTerminate")
FileLogger.log("applicationWillTerminate") FileLogger.log("applicationWillTerminate")
Conductor.removeLiveActivities()
// Conductor.maestro.removeLiveActivities()
} }
func applicationDidReceiveMemoryWarning(_ application: UIApplication) { func applicationDidReceiveMemoryWarning(_ application: UIApplication) {
@ -66,7 +70,6 @@ class AppDelegate : NSObject, UIApplicationDelegate {
} }
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool { func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
if userActivity.interaction == nil { if userActivity.interaction == nil {
Logger.log("restorationHandler called! interaction is nil") Logger.log("restorationHandler called! interaction is nil")
return false return false

@ -206,8 +206,11 @@ class Conductor: ObservableObject {
FileLogger.log("Cancel \(self._timerName(id))") FileLogger.log("Cancel \(self._timerName(id))")
CountdownScheduler.master.cancelCurrentNotifications(countdownId: id) CountdownScheduler.master.cancelCurrentNotifications(countdownId: id)
self.currentCountdowns.removeValue(forKey: id)
self.removeLiveTimer(id: id)
self.cancelSoundPlayer(id: id) self.cancelSoundPlayer(id: id)
self.cancelledCountdowns.append(id)
self._recordAndRemoveCountdown(countdownId: id, cancel: true) self._recordAndRemoveCountdown(countdownId: id, cancel: true)
self.pausedCountdowns.removeValue(forKey: id) self.pausedCountdowns.removeValue(forKey: id)
@ -496,7 +499,23 @@ class Conductor: ObservableObject {
} }
} }
class func removeLiveActivities() {
print("Ending Live Activities")
let semaphore = DispatchSemaphore(value: 0)
Task.detached(priority: .high) {
print("Task")
for activity in ActivityKit.Activity<LaunchWidgetAttributes>.activities {
print("Ending Live Activity: \(activity.id)")
if #available(iOS 16.2, *) {
await activity.end(nil, dismissalPolicy: .immediate)
}
}
semaphore.signal()
}
semaphore.wait()
}
fileprivate func _liveActivity(timerId: String) -> [ActivityKit.Activity<LaunchWidgetAttributes>] { fileprivate func _liveActivity(timerId: String) -> [ActivityKit.Activity<LaunchWidgetAttributes>] {
return ActivityKit.Activity<LaunchWidgetAttributes>.activities.filter { $0.attributes.id == timerId } return ActivityKit.Activity<LaunchWidgetAttributes>.activities.filter { $0.attributes.id == timerId }
} }

@ -23,6 +23,7 @@ enum PreferenceKey: String {
case timerSiriTips case timerSiriTips
case cloudKitSchemaInitialized case cloudKitSchemaInitialized
case defaultVolume case defaultVolume
case raiseSoundOnLaunch
} }
class Preferences { class Preferences {
@ -40,6 +41,7 @@ class Preferences {
@UserDefault(PreferenceKey.defaultVolume.rawValue, defaultValue: 0.5) static var defaultVolume: Float @UserDefault(PreferenceKey.defaultVolume.rawValue, defaultValue: 0.5) static var defaultVolume: Float
@UserDefault(PreferenceKey.installDate.rawValue, defaultValue: nil) static var installDate: Date? @UserDefault(PreferenceKey.installDate.rawValue, defaultValue: nil) static var installDate: Date?
@UserDefault(PreferenceKey.hasShownStartView.rawValue, defaultValue: false) static var hasShownStartView: Bool @UserDefault(PreferenceKey.hasShownStartView.rawValue, defaultValue: false) static var hasShownStartView: Bool
@UserDefault(PreferenceKey.raiseSoundOnLaunch.rawValue, defaultValue: false) static var raiseSoundOnLaunch: Bool
static var hideSilentModeAlerts: Bool { static var hideSilentModeAlerts: Bool {
return UserDefaults.standard.bool(forKey: PreferenceKey.showSilentModeAlert.rawValue) return UserDefaults.standard.bool(forKey: PreferenceKey.showSilentModeAlert.rawValue)

@ -36,6 +36,11 @@ struct VolumeView: UIViewRepresentable {
} }
fileprivate func _setVolume(volumeView: MPVolumeView) { fileprivate func _setVolume(volumeView: MPVolumeView) {
guard Preferences.raiseSoundOnLaunch else {
return
}
if let slider = volumeView.subviews.first(where: { $0 is UISlider }) as? UISlider { if let slider = volumeView.subviews.first(where: { $0 is UISlider }) as? UISlider {
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.1) { DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.1) {

@ -11,6 +11,7 @@ import MessageUI
struct SettingsView: View { struct SettingsView: View {
@State var confirmationSound = Preferences.playConfirmationSound @State var confirmationSound = Preferences.playConfirmationSound
@State var raiseSoundOnLaunch = Preferences.raiseSoundOnLaunch
@State var cancellationSound = Preferences.playCancellationSound @State var cancellationSound = Preferences.playCancellationSound
@State var defaultVolume: Float = Preferences.defaultVolume @State var defaultVolume: Float = Preferences.defaultVolume
@ -29,14 +30,24 @@ struct SettingsView: View {
// .onChange(of: self.cancellationSound) { newValue in // .onChange(of: self.cancellationSound) { newValue in
// Preferences.playCancellationSound = newValue // Preferences.playCancellationSound = newValue
// } // }
HStack {
Text("Default Volume")
Spacer() Toggle("Raise sound on launch", isOn: self.$raiseSoundOnLaunch)
Slider(value: self.$defaultVolume) .onChange(of: self.raiseSoundOnLaunch) { newValue in
.onChange(of: self.defaultVolume, perform: { newValue in Preferences.raiseSoundOnLaunch = newValue
Preferences.defaultVolume = self.defaultVolume }
})
.frame(width: 120.0)
if self.raiseSoundOnLaunch {
HStack {
Text("Default Volume")
Spacer()
Slider(value: self.$defaultVolume)
.onChange(of: self.defaultVolume, perform: { newValue in
Preferences.defaultVolume = self.defaultVolume
})
.frame(width: 120.0)
}
} }
if MFMailComposeViewController.canSendMail() { if MFMailComposeViewController.canSendMail() {

Loading…
Cancel
Save