Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 33 additions & 21 deletions AKPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,29 @@ import Foundation
// Add a lightweight struct so we can decode only the flag we care about
private struct AKAppSettingsData: Codable {
var hideTitleBar: Bool?
var floatingWindow: Bool?
}

class AKPlugin: NSObject, Plugin {
required override init() {
super.init()
if hideTitleBarSetting == false {
return
}
if let window = NSApplication.shared.windows.first {
// Enable all window management features
window.styleMask.insert([.resizable, .fullSizeContentView])
window.styleMask.insert([.resizable])
window.collectionBehavior = [.fullScreenPrimary, .managed, .participatesInCycle]

// Enable automatic window management
window.isMovable = true
window.isMovableByWindowBackground = true
window.titlebarAppearsTransparent = true
window.titleVisibility = .hidden
window.toolbar = nil
window.title = ""

if self.hideTitleBarSetting == true {
window.styleMask.insert([.fullSizeContentView])
window.titlebarAppearsTransparent = true
window.titleVisibility = .hidden
window.toolbar = nil
window.title = ""
}

if self.floatingWindowSetting == true {
window.level = .floating
}
NSWindow.allowsAutomaticWindowTabbing = true
}

Expand All @@ -40,12 +43,20 @@ class AKPlugin: NSObject, Plugin {
forName: NSWindow.didBecomeKeyNotification,
object: nil,
queue: .main) { notif in
guard let win = notif.object as? NSWindow else { return }
win.styleMask.insert([.resizable, .fullSizeContentView])
win.titlebarAppearsTransparent = true
win.titleVisibility = .hidden
win.toolbar = nil
win.title = ""
guard let win = notif.object as? NSWindow else { return }
win.styleMask.insert([.resizable])

if self.hideTitleBarSetting == true {
win.styleMask.insert([.fullSizeContentView])
win.titlebarAppearsTransparent = true
win.titleVisibility = .hidden
win.toolbar = nil
win.title = ""
}

if self.floatingWindowSetting == true {
win.level = .floating
}
}
}

Expand Down Expand Up @@ -265,17 +276,18 @@ class AKPlugin: NSObject, Plugin {
}

/// Convenience instance property that exposes the cached static preference.
private var hideTitleBarSetting: Bool { Self.hideTitleBarPreference }
private var hideTitleBarSetting: Bool { Self.akAppSettingsData?.hideTitleBar ?? false }
private var floatingWindowSetting: Bool { Self.akAppSettingsData?.floatingWindow ?? false }

fileprivate static var hideTitleBarPreference: Bool = {
fileprivate static var akAppSettingsData: AKAppSettingsData? = {
let bundleIdentifier = Bundle.main.bundleIdentifier ?? ""
let settingsURL = URL(fileURLWithPath: "/Users/\(NSUserName())/Library/Containers/io.playcover.PlayCover")
.appendingPathComponent("App Settings")
.appendingPathComponent("\(bundleIdentifier).plist")
guard let data = try? Data(contentsOf: settingsURL),
let decoded = try? PropertyListDecoder().decode(AKAppSettingsData.self, from: data) else {
return false
return nil
}
return decoded.hideTitleBar ?? false
return decoded
}()
}
3 changes: 3 additions & 0 deletions PlayTools/PlaySettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ let settings = PlaySettings.shared

@objc lazy var hideTitleBar = settingsData.hideTitleBar

@objc lazy var floatingWindow = settingsData.floatingWindow

@objc lazy var checkMicPermissionSync = settingsData.checkMicPermissionSync
}

Expand All @@ -110,5 +112,6 @@ struct AppSettingsData: Codable {
var noKMOnInput = false
var enableScrollWheel = true
var hideTitleBar = false
var floatingWindow = false
var checkMicPermissionSync = false
}