Skip to content

Commit 1c0ed1c

Browse files
authored
Merge pull request #2 from kushalpandya/kp-sqlite-driven-library
Use SQLite for library management
2 parents 06c70cd + 6acb2cb commit 1c0ed1c

31 files changed

Lines changed: 2514 additions & 883 deletions

Application/AppCoordinator.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import SwiftUI
22

33
class AppCoordinator: ObservableObject {
44
// MARK: - Managers
5+
static var shared: AppCoordinator?
56
let libraryManager: LibraryManager
67
let playlistManager: PlaylistManager
78
let audioPlayerManager: AudioPlayerManager
@@ -24,5 +25,6 @@ class AppCoordinator: ObservableObject {
2425
// Setup now playing
2526
nowPlayingManager = NowPlayingManager()
2627
nowPlayingManager.connectRemoteCommandCenter(audioPlayer: audioPlayerManager, playlistManager: playlistManager)
28+
Self.shared = self
2729
}
2830
}

Application/AppDelegate.swift

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,32 @@ class AppDelegate: NSObject, NSApplicationDelegate {
1414

1515
func applicationWillTerminate(_ notification: Notification) {
1616
print("App is terminating...")
17-
// Any cleanup code can go here
17+
// Stop audio playback cleanly
18+
if let coordinator = AppCoordinator.shared {
19+
coordinator.audioPlayerManager.stop()
20+
}
1821
}
1922

2023
func applicationDidFinishLaunching(_ notification: Notification) {
2124
print("App finished launching")
25+
26+
// Ensure main window is visible
27+
if let window = NSApp.windows.first {
28+
window.makeKeyAndOrderFront(nil)
29+
}
30+
}
31+
32+
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
33+
// If no windows are visible, show the main window
34+
if !flag {
35+
// Create a new window if needed
36+
if NSApp.windows.isEmpty {
37+
// The window should be created by SwiftUI, just make it visible
38+
NSApp.activate(ignoringOtherApps: true)
39+
} else if let window = NSApp.windows.first {
40+
window.makeKeyAndOrderFront(nil)
41+
}
42+
}
43+
return true
2244
}
2345
}

Managers/AudioPlayerManager.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ class AudioPlayerManager: ObservableObject {
2727
}
2828

2929
deinit {
30+
stop()
3031
timer?.invalidate()
32+
timer = nil
3133
}
3234

3335
// MARK: - Playback Controls

0 commit comments

Comments
 (0)