chore: clean up code comments

This commit is contained in:
edde746
2026-08-10 20:28:41 +02:00
parent 5611c6785a
commit 69fadc220d
170 changed files with 324 additions and 1765 deletions
-8
View File
@@ -1,14 +1,6 @@
// Application-level settings for the Runner target.
//
// This may be replaced with something auto-generated from metadata (e.g., pubspec.yaml) in the
// future. If not, the values below would default to using the project name when this becomes a
// 'flutter create' template.
// The application's name. By default this is also the title of the Flutter window.
PRODUCT_NAME = Plezy
// The application's bundle identifier
PRODUCT_BUNDLE_IDENTIFIER = com.edde746.plezy
// The copyright displayed in application information
PRODUCT_COPYRIGHT = Copyright © 2025 edde746
+1 -7
View File
@@ -16,8 +16,7 @@ class MainFlutterWindow: NSWindow {
self.contentViewController = flutterViewController
self.setFrame(windowFrame, display: true)
// Apply initial window configuration BEFORE frame restoration
// This prevents the window from shrinking on launch
// Configure window chrome before restoring the saved frame.
self.titlebarAppearsTransparent = true
self.titleVisibility = .hidden
self.styleMask.insert(.fullSizeContentView)
@@ -26,28 +25,23 @@ class MainFlutterWindow: NSWindow {
let toolbar = ForwardingToolbar(flutterViewController: flutterViewController)
self.toolbar = toolbar
// Register MPV player plugin for video playback
MpvPlayerPlugin.register(
with: flutterViewController.registrar(forPlugin: "MpvPlayerPlugin"))
// Register the audio-only MPV player plugin for music playback
MpvAudioPlayerPlugin.register(
with: flutterViewController.registrar(forPlugin: "MpvAudioPlayerPlugin"))
// Register window utils plugin for dynamic titlebar/fullscreen control from Dart
WindowUtilsPlugin.register(
with: flutterViewController.registrar(forPlugin: "WindowUtilsPlugin"))
WindowUtilsPlugin.setWindow(self)
WindowUtilsPlugin.installWindowDelegate()
WindowUtilsPlugin.syncWindowChrome()
// Register Launch Services lookups used to detect installed external players
AppLookupPlugin.register(
with: flutterViewController.registrar(forPlugin: "AppLookupPlugin"))
RegisterGeneratedPlugins(registry: flutterViewController)
// Enable window position/size persistence
self.setFrameAutosaveName("com.edde746.plezy.MainWindow")
WindowUtilsPlugin.syncWindowChrome()
@@ -47,8 +47,6 @@ class MpvPipController: NSObject, PIPViewControllerDelegate {
sourceWindow = window
// Create a layer-hosting wrapper view for the Metal layer.
// PIPViewController resizes the view (and its root layer) as the PiP window resizes.
let videoView = NSView(frame: NSRect(origin: .zero, size: aspectRatio))
videoView.wantsLayer = true
videoView.layer = metalLayer
@@ -57,14 +55,12 @@ class MpvPipController: NSObject, PIPViewControllerDelegate {
// Without this, the explicit main-window drawableSize persists in PiP.
metalLayer.drawableSize = .zero
// Create a view controller for PIPViewController
let vc = NSViewController()
vc.view = videoView
pipVideoVC = vc
pipVideoView = videoView
// Configure PiP
pip.playing = delegate?.isPipPlaying ?? false
pip.aspectRatio = aspectRatio
pip.replacementWindow = window
@@ -72,7 +68,6 @@ class MpvPipController: NSObject, PIPViewControllerDelegate {
delegate?.pipWillStart()
// Present PiP
pip.presentAsPicture(inPicture: vc)
isActive = true
delegate?.pipDidStart()
+1 -17
View File
@@ -11,14 +11,12 @@ class MpvPlayerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, MpvPluginS
private weak var registrar: FlutterPluginRegistrar?
var nameToId: [String: Int] = [:]
// MpvPluginShared conformance
var coreBase: MpvPlayerCoreBase? { playerCore }
func setPlayerVisible(_ visible: Bool, restoreOnWindowVisible: Bool) {
playerCore?.setVisible(visible, restoreOnWindowVisible: restoreOnWindowVisible)
}
func updatePlayerFrame() { playerCore?.updateFrame() }
// PiP
private var pipController: MpvPipController?
private var pipChannel: FlutterMethodChannel?
private var autoPipEnabled = false
@@ -27,13 +25,11 @@ class MpvPlayerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, MpvPluginS
// MARK: - FlutterPlugin Registration
static func register(with registrar: FlutterPluginRegistrar) {
// Method channel for commands
let methodChannel = FlutterMethodChannel(
name: "com.plezy/mpv_player",
binaryMessenger: registrar.messenger
)
// Event channel for state updates
let eventChannel = FlutterEventChannel(
name: "com.plezy/mpv_player/events",
binaryMessenger: registrar.messenger
@@ -110,7 +106,6 @@ class MpvPlayerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, MpvPluginS
}
}
// MARK: - PiP
private func ensurePipController() -> MpvPipController {
if let existing = pipController { return existing }
@@ -135,13 +130,11 @@ class MpvPlayerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, MpvPluginS
let pip = ensurePipController()
pip.setAutoStart(ready)
if ready {
// Observe app resigning active to auto-enter PiP
NotificationCenter.default.removeObserver(
self, name: NSApplication.didResignActiveNotification, object: nil)
NotificationCenter.default.addObserver(
self, selector: #selector(appDidResignActive),
name: NSApplication.didResignActiveNotification, object: nil)
// Observe app becoming active to auto-exit PiP
NotificationCenter.default.removeObserver(
self, name: NSApplication.didBecomeActiveNotification, object: nil)
NotificationCenter.default.addObserver(
@@ -184,8 +177,7 @@ class MpvPlayerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, MpvPluginS
return
}
// Get video dimensions for aspect ratio
var aspectRatio = NSSize(width: 16, height: 9) // default
var aspectRatio = NSSize(width: 16, height: 9)
if let videoSize = playerCore.videoSize {
aspectRatio = NSSize(width: videoSize.width, height: videoSize.height)
}
@@ -226,14 +218,12 @@ class MpvPlayerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, MpvPluginS
return
}
// Check if already initialized
if self.playerCore?.isInitialized == true {
print("[MpvPlayerPlugin] Already initialized")
result(true)
return
}
// Find the Flutter window
guard let (window, _, _) = self.findFlutterWindow() else {
print("[MpvPlayerPlugin] Failed to find Flutter window")
result(
@@ -242,7 +232,6 @@ class MpvPlayerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, MpvPluginS
return
}
// Create and initialize player core
let core = MpvPlayerCore()
core.delegate = self
@@ -256,7 +245,6 @@ class MpvPlayerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, MpvPluginS
self.playerCore = core
// Start hidden
core.setVisible(false)
print("[MpvPlayerPlugin] Initialized successfully")
@@ -303,7 +291,6 @@ class MpvPlayerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, MpvPluginS
}
}
// Fallback
for window in NSApplication.shared.windows {
if let contentView = window.contentView,
let contentVC = window.contentViewController
@@ -334,13 +321,10 @@ extension MpvPlayerPlugin: MpvPipDelegate {
playerCore?.isPipActive = false
enteredPipViaAuto = false
// Detach the Metal layer from the PiP wrapper view
pipController?.detachLayer()
// Re-attach the Metal layer to the main window
playerCore?.reattachMetalLayer()
// Force a redraw if paused (prevents black frame after PiP exit)
if playerCore?.isPaused == true {
playerCore?.forceDraw()
}
-4
View File
@@ -5,8 +5,6 @@ class WindowDelegate: NSObject, NSWindowDelegate {
weak var channel: FlutterMethodChannel?
weak var window: NSWindow?
// Hardcoded presentation options for fullscreen mode
// Auto-hide toolbar, menu bar, and dock when in fullscreen
private let fullScreenPresentationOptions: NSApplication.PresentationOptions = [
.fullScreen,
.autoHideToolbar,
@@ -62,7 +60,6 @@ class WindowDelegate: NSObject, NSWindowDelegate {
func windowWillEnterFullScreen(_ notification: Notification) {
guard let window = window else { return }
applyFullScreenChrome(to: window)
// Notify Dart for state management only
emit("windowWillEnterFullScreen")
}
@@ -72,7 +69,6 @@ class WindowDelegate: NSObject, NSWindowDelegate {
func windowWillExitFullScreen(_ notification: Notification) {
guard let window = window else { return }
// Hide title and make titlebar transparent BEFORE exiting
window.titleVisibility = .hidden
window.titlebarAppearsTransparent = true
emit("windowWillExitFullScreen")
+1 -12
View File
@@ -1,8 +1,6 @@
import Cocoa
import FlutterMacOS
// MARK: - ForwardingView
// A view that forwards mouse events to the Flutter view controller
class ForwardingView: NSView {
weak var flutterViewController: NSViewController?
@@ -15,8 +13,6 @@ class ForwardingView: NSView {
}
}
// MARK: - ForwardingToolbar
// A custom toolbar that forwards mouse events from the toolbar area to Flutter
class ForwardingToolbar: NSToolbar, NSToolbarDelegate {
let flutterViewController: NSViewController
@@ -26,7 +22,6 @@ class ForwardingToolbar: NSToolbar, NSToolbarDelegate {
self.delegate = self
self.showsBaselineSeparator = false
// Prevent toolbar customization UI (the "rounded box")
self.allowsUserCustomization = false
self.allowsExtensionItems = false
if #available(macOS 15.0, *) {
@@ -48,11 +43,11 @@ class ForwardingToolbar: NSToolbar, NSToolbarDelegate {
) -> NSToolbarItem? {
if itemIdentifier == NSToolbarItem.Identifier("ForwardingItem") {
let item = NSToolbarItem(itemIdentifier: itemIdentifier)
item.isBordered = false // Remove the rounded box appearance
let view = ForwardingView()
view.flutterViewController = flutterViewController
view.widthAnchor.constraint(lessThanOrEqualToConstant: 100000).isActive = true
view.widthAnchor.constraint(greaterThanOrEqualToConstant: 1).isActive = true
item.isBordered = false
item.view = view
return item
}
@@ -68,7 +63,6 @@ class WindowUtilsPlugin: NSObject, FlutterPlugin {
private var windowDelegate: WindowDelegate?
private var originalButtonConstraints: [NSWindow.ButtonType: [NSLayoutConstraint]] = [:]
// Centralized traffic light positions - the single source of truth
private static let customButtonPositions: [(NSWindow.ButtonType, CGPoint)] = [
(.closeButton, CGPoint(x: 20, y: 21)),
(.miniaturizeButton, CGPoint(x: 40, y: 21)),
@@ -224,7 +218,6 @@ class WindowUtilsPlugin: NSObject, FlutterPlugin {
window: NSWindow, buttonType: NSWindow.ButtonType, offset: CGPoint
) {
withButton(buttonType, in: window) { button, superview in
// Store original constraints if not already stored
if originalButtonConstraints[buttonType] == nil {
let constraints = superview.constraints.filter { constraint in
(constraint.firstItem as? NSButton) == button
@@ -233,12 +226,10 @@ class WindowUtilsPlugin: NSObject, FlutterPlugin {
originalButtonConstraints[buttonType] = constraints
}
// Remove existing position constraints
superview.removeConstraints(positionConstraints(for: button, in: superview))
button.translatesAutoresizingMaskIntoConstraints = false
// Add new positioning constraints
superview.addConstraints([
button.leftAnchor.constraint(equalTo: superview.leftAnchor, constant: offset.x),
button.topAnchor.constraint(equalTo: superview.topAnchor, constant: offset.y),
@@ -249,10 +240,8 @@ class WindowUtilsPlugin: NSObject, FlutterPlugin {
private func resetButtonPosition(window: NSWindow, buttonType: NSWindow.ButtonType) {
withButton(buttonType, in: window) { button, superview in
// Remove custom constraints
superview.removeConstraints(positionConstraints(for: button, in: superview))
// Restore original constraints if we have them
if let originalConstraints = originalButtonConstraints[buttonType] {
superview.addConstraints(originalConstraints)
originalButtonConstraints.removeValue(forKey: buttonType)