Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 44 additions & 40 deletions LoopFollow.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

9 changes: 0 additions & 9 deletions LoopFollow/Alarm/AlarmsContainerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,10 @@
import SwiftUI

struct AlarmsContainerView: View {
var onBack: (() -> Void)?

var body: some View {
NavigationStack {
AlarmListView()
.toolbar {
if let onBack {
ToolbarItem(placement: .navigationBarLeading) {
Button(action: onBack) {
Image(systemName: "chevron.left")
}
}
}
ToolbarItem(placement: .navigationBarTrailing) {
NavigationLink {
AlarmSettingsView()
Expand Down
91 changes: 20 additions & 71 deletions LoopFollow/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// LoopFollow
// AppDelegate.swift

import CoreData
import AVFoundation
import EventKit
import UIKit
import UserNotifications

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
let notificationCenter = UNUserNotificationCenter.current()
private let speechSynthesizer = AVSpeechSynthesizer()

func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
LogManager.shared.log(category: .general, message: "App started")
Expand Down Expand Up @@ -111,85 +110,35 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
completionHandler(.newData)
}

// MARK: - URL handling

// Note: with scene-based lifecycle (iOS 13+), URLs are delivered to
// SceneDelegate.scene(_:openURLContexts:) — not here. The scene delegate
// handles <urlScheme>://la-tap for Live Activity tap navigation.

// MARK: UISceneSession Lifecycle

func application(_: UIApplication, willFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// set the "prevent screen lock" option when the app is started
// This method doesn't seem to be working anymore. Added to view controllers as solution offered on SO
UIApplication.shared.isIdleTimerDisabled = Storage.shared.screenlockSwitchState.value

return true
}

func application(_: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options _: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}

func application(_: UIApplication, didDiscardSceneSessions _: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}
// MARK: - Quick Actions

// MARK: - Core Data stack

lazy var persistentContainer: NSPersistentCloudKitContainer = {
/*
The persistent container for the application. This implementation
creates and returns a container, having loaded the store for the
application to it. This property is optional since there are legitimate
error conditions that could cause the creation of the store to fail.
*/
let container = NSPersistentCloudKitContainer(name: "LoopFollow")
container.loadPersistentStores(completionHandler: { _, error in
if let error = error as NSError? {
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.

/*
Typical reasons for an error here include:
* The parent directory does not exist, cannot be created, or disallows writing.
* The persistent store is not accessible, due to permissions or data protection when the device is locked.
* The device is out of space.
* The store could not be migrated to the current model version.
Check the error message to determine what the actual problem was.
*/
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
return container
}()

// MARK: - Core Data Saving support

func saveContext() {
let context = persistentContainer.viewContext
if context.hasChanges {
do {
try context.save()
} catch {
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
let nserror = error as NSError
fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
}
func application(_: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
guard let bundleIdentifier = Bundle.main.bundleIdentifier else {
completionHandler(false)
return
}
let expectedType = bundleIdentifier + ".toggleSpeakBG"
if shortcutItem.type == expectedType {
Storage.shared.speakBG.value.toggle()
let message = Storage.shared.speakBG.value ? "BG Speak is now on" : "BG Speak is now off"
let utterance = AVSpeechUtterance(string: message)
speechSynthesizer.speak(utterance)
completionHandler(true)
} else {
completionHandler(false)
}
}

func userNotificationCenter(_: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
if response.actionIdentifier == "OPEN_APP_ACTION" {
if let window {
window.rootViewController?.dismiss(animated: true, completion: nil)
window.rootViewController?.present(MainViewController(), animated: true, completion: nil)
}
// Dismiss any presented modal/sheet so the user actually sees Home
UIApplication.shared.topMost?.dismiss(animated: true)
Observable.shared.selectedTabIndex.value = 0
}

if response.actionIdentifier == "snooze" {
Expand Down
Loading
Loading