Fix: app quit on playlist close, request screen capture permission, playlist as panel
This commit is contained in:
parent
a90a60437b
commit
35de7263e9
@ -2,9 +2,20 @@ import SwiftUI
|
||||
import AVFoundation
|
||||
import Combine
|
||||
import SwiftBricks
|
||||
#if os(macOS)
|
||||
import AppKit
|
||||
|
||||
// 防止关闭所有窗口时退出应用
|
||||
class AppDel: NSObject, NSApplicationDelegate {
|
||||
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { false }
|
||||
}
|
||||
#endif
|
||||
|
||||
@main
|
||||
struct MiniPlayerApp: App {
|
||||
#if os(macOS)
|
||||
@NSApplicationDelegateAdaptor(AppDel.self) var appDelegate
|
||||
#endif
|
||||
@StateObject private var bridge = PlayerBridge()
|
||||
@StateObject private var engine = BricksEngine()
|
||||
|
||||
|
||||
@ -434,16 +434,19 @@ final class PlayerBridge: ObservableObject {
|
||||
if let win = playlistWindow, win.isVisible {
|
||||
win.close(); playlistWindow = nil; return
|
||||
}
|
||||
let win = NSWindow(
|
||||
let panel = NSPanel(
|
||||
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))"
|
||||
win.isReleasedWhenClosed = false
|
||||
win.center()
|
||||
win.contentView = NSHostingView(rootView: PlaylistWindowView(bridge: self))
|
||||
win.makeKeyAndOrderFront(nil)
|
||||
playlistWindow = win
|
||||
panel.title = "\(L.playlist) (\(queue.count))"
|
||||
panel.isReleasedWhenClosed = false
|
||||
panel.isMovableByWindowBackground = true
|
||||
panel.hidesOnDeactivate = false
|
||||
panel.becomesKeyOnlyIfNeeded = true
|
||||
panel.center()
|
||||
panel.contentView = NSHostingView(rootView: PlaylistWindowView(bridge: self))
|
||||
panel.makeKeyAndOrderFront(NSApp)
|
||||
playlistWindow = panel
|
||||
#else
|
||||
showPlaylistSheet.toggle()
|
||||
#endif
|
||||
|
||||
@ -104,9 +104,11 @@ final class ScreenRecorder: NSObject, AVCaptureFileOutputRecordingDelegate {
|
||||
self.fileOutput = output
|
||||
|
||||
// 请求屏幕录制权限(macOS 10.15+)
|
||||
// CGPreflightScreenCaptureAccess 在首次调用时触发权限弹窗
|
||||
// CGRequestScreenCaptureAccess 在首次调用时触发权限弹窗
|
||||
#if canImport(ScreenCaptureKit)
|
||||
CGPreflightScreenCaptureAccess()
|
||||
if !CGPreflightScreenCaptureAccess() {
|
||||
CGRequestScreenCaptureAccess()
|
||||
}
|
||||
#endif
|
||||
|
||||
return true
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user