Compare commits

...

2 Commits

3 changed files with 31 additions and 10 deletions

View File

@ -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()

View File

@ -89,6 +89,11 @@ final class PlayerBridge: ObservableObject {
// MARK: - 初始化
func setup() {
#if os(macOS)
// 设置为正常 GUI 应用,显示在 Dock 中
NSApp.setActivationPolicy(.regular)
#endif
player.volume = volume
setupTimeObserver()
@ -429,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

View File

@ -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