Fix: app quit on playlist close, request screen capture permission, playlist as panel

This commit is contained in:
yumoqing 2026-06-24 19:50:54 +08:00
parent a90a60437b
commit 35de7263e9
3 changed files with 26 additions and 10 deletions

View File

@ -2,9 +2,20 @@ import SwiftUI
import AVFoundation import AVFoundation
import Combine import Combine
import SwiftBricks import SwiftBricks
#if os(macOS)
import AppKit
// 退
class AppDel: NSObject, NSApplicationDelegate {
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { false }
}
#endif
@main @main
struct MiniPlayerApp: App { struct MiniPlayerApp: App {
#if os(macOS)
@NSApplicationDelegateAdaptor(AppDel.self) var appDelegate
#endif
@StateObject private var bridge = PlayerBridge() @StateObject private var bridge = PlayerBridge()
@StateObject private var engine = BricksEngine() @StateObject private var engine = BricksEngine()

View File

@ -434,16 +434,19 @@ final class PlayerBridge: ObservableObject {
if let win = playlistWindow, win.isVisible { if let win = playlistWindow, win.isVisible {
win.close(); playlistWindow = nil; return win.close(); playlistWindow = nil; return
} }
let win = NSWindow( let panel = NSPanel(
contentRect: NSRect(x: 0, y: 0, width: 400, height: 500), contentRect: NSRect(x: 0, y: 0, width: 400, height: 500),
styleMask: [.titled, .closable, .resizable], backing: .buffered, defer: false styleMask: [.titled, .closable, .resizable, .utilityWindow], backing: .buffered, defer: false
) )
win.title = "\(L.playlist) (\(queue.count))" panel.title = "\(L.playlist) (\(queue.count))"
win.isReleasedWhenClosed = false panel.isReleasedWhenClosed = false
win.center() panel.isMovableByWindowBackground = true
win.contentView = NSHostingView(rootView: PlaylistWindowView(bridge: self)) panel.hidesOnDeactivate = false
win.makeKeyAndOrderFront(nil) panel.becomesKeyOnlyIfNeeded = true
playlistWindow = win panel.center()
panel.contentView = NSHostingView(rootView: PlaylistWindowView(bridge: self))
panel.makeKeyAndOrderFront(NSApp)
playlistWindow = panel
#else #else
showPlaylistSheet.toggle() showPlaylistSheet.toggle()
#endif #endif

View File

@ -104,9 +104,11 @@ final class ScreenRecorder: NSObject, AVCaptureFileOutputRecordingDelegate {
self.fileOutput = output self.fileOutput = output
// macOS 10.15+ // macOS 10.15+
// CGPreflightScreenCaptureAccess // CGRequestScreenCaptureAccess
#if canImport(ScreenCaptureKit) #if canImport(ScreenCaptureKit)
CGPreflightScreenCaptureAccess() if !CGPreflightScreenCaptureAccess() {
CGRequestScreenCaptureAccess()
}
#endif #endif
return true return true