mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-27 23:24:32 +00:00
Half baked changes
This commit is contained in:
parent
3eb82a02a5
commit
f79898d65e
4 changed files with 78 additions and 41 deletions
57
DynamicIsland/helpers/DisplayServicesDynamic.swift
Normal file
57
DynamicIsland/helpers/DisplayServicesDynamic.swift
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
//
|
||||
// DisplayServicesDynamic.swift
|
||||
// DynamicIsland
|
||||
//
|
||||
// Created by AI Assistant on 25/12/2025.
|
||||
//
|
||||
// Lightweight wrapper that resolves DisplayServices symbols at runtime so we
|
||||
// can call the private brightness APIs without linking against the framework.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Darwin
|
||||
|
||||
final class DisplayServicesDynamic {
|
||||
static let shared = DisplayServicesDynamic()
|
||||
|
||||
private let handle: UnsafeMutableRawPointer?
|
||||
|
||||
private typealias GetBrightnessFn = @convention(c) (UInt32, UnsafeMutablePointer<Float>) -> Int32
|
||||
private typealias SetBrightnessFn = @convention(c) (UInt32, Float) -> Int32
|
||||
|
||||
private let getBrightnessFn: GetBrightnessFn?
|
||||
private let setBrightnessFn: SetBrightnessFn?
|
||||
|
||||
private init() {
|
||||
handle = dlopen("/System/Library/PrivateFrameworks/DisplayServices.framework/DisplayServices", RTLD_NOW)
|
||||
|
||||
if handle == nil, let errorPointer = dlerror() {
|
||||
let message = String(cString: errorPointer)
|
||||
NSLog("⚠️ DisplayServicesDynamic: dlopen failed - %@", message)
|
||||
}
|
||||
|
||||
getBrightnessFn = handle.flatMap { dlsym($0, "DisplayServicesGetBrightness") }
|
||||
.map { unsafeBitCast($0, to: GetBrightnessFn.self) }
|
||||
|
||||
setBrightnessFn = handle.flatMap { dlsym($0, "DisplayServicesSetBrightness") }
|
||||
.map { unsafeBitCast($0, to: SetBrightnessFn.self) }
|
||||
}
|
||||
|
||||
func setBrightness(displayID: UInt32, value: Float) -> Int32? {
|
||||
guard let fn = setBrightnessFn else { return nil }
|
||||
return fn(displayID, value)
|
||||
}
|
||||
|
||||
func getBrightness(displayID: UInt32) -> (status: Int32, value: Float)? {
|
||||
guard let fn = getBrightnessFn else { return nil }
|
||||
var brightness: Float = 0
|
||||
let status = fn(displayID, &brightness)
|
||||
return (status, brightness)
|
||||
}
|
||||
|
||||
deinit {
|
||||
if let handle {
|
||||
dlclose(handle)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -18,7 +18,8 @@ final class MediaChecker: Sendable {
|
|||
func checkDeprecationStatus() async throws -> Bool {
|
||||
guard let scriptURL = Bundle.main.url(forResource: "mediaremote-adapter", withExtension: "pl"),
|
||||
let nowPlayingTestClientPath = Bundle.main.url(forResource: "MediaRemoteAdapterTestClient", withExtension: nil)?.path,
|
||||
let frameworkPath = Bundle.main.privateFrameworksPath?.appending("/MediaRemoteAdapter.framework")
|
||||
//let frameworkPath = Bundle.main.privateFrameworksPath?.appending("/MediaRemoteAdapter.framework")
|
||||
let frameworkPath = Optional("/System/Library/PrivateFrameworks/MediaRemoteAdapter.framework")
|
||||
else {
|
||||
throw MediaCheckerError.missingResources
|
||||
}
|
||||
|
|
|
|||
|
|
@ -606,13 +606,18 @@ final class SystemBrightnessController {
|
|||
}
|
||||
|
||||
private func setBrightnessViaDisplayServices(_ value: Float) -> Bool {
|
||||
let status = DisplayServicesSetBrightness(displayID, value)
|
||||
guard let status = DisplayServicesDynamic.shared.setBrightness(displayID: displayID, value: value) else {
|
||||
return false
|
||||
}
|
||||
if status == kIOReturnSuccess {
|
||||
return true
|
||||
}
|
||||
// Attempt to refresh display ID in case the main display changed
|
||||
displayID = CGMainDisplayID()
|
||||
let retry = DisplayServicesSetBrightness(displayID, value)
|
||||
guard let retry = DisplayServicesDynamic.shared.setBrightness(displayID: displayID, value: value) else {
|
||||
NSLog("⚠️ DisplayServicesSetBrightness unavailable after display refresh")
|
||||
return false
|
||||
}
|
||||
if retry != kIOReturnSuccess {
|
||||
NSLog("⚠️ DisplayServicesSetBrightness failed: \(retry)")
|
||||
return false
|
||||
|
|
@ -621,17 +626,21 @@ final class SystemBrightnessController {
|
|||
}
|
||||
|
||||
private func getBrightnessViaDisplayServices() -> Float? {
|
||||
var brightness: Float = 0
|
||||
let status = DisplayServicesGetBrightness(displayID, &brightness)
|
||||
if status == kIOReturnSuccess {
|
||||
return brightness
|
||||
guard let result = DisplayServicesDynamic.shared.getBrightness(displayID: displayID) else {
|
||||
return nil
|
||||
}
|
||||
if result.status == kIOReturnSuccess {
|
||||
return result.value
|
||||
}
|
||||
displayID = CGMainDisplayID()
|
||||
let retry = DisplayServicesGetBrightness(displayID, &brightness)
|
||||
if retry == kIOReturnSuccess {
|
||||
return brightness
|
||||
guard let retry = DisplayServicesDynamic.shared.getBrightness(displayID: displayID) else {
|
||||
NSLog("⚠️ DisplayServicesGetBrightness unavailable after display refresh")
|
||||
return nil
|
||||
}
|
||||
NSLog("⚠️ DisplayServicesGetBrightness failed: \(retry)")
|
||||
if retry.status == kIOReturnSuccess {
|
||||
return retry.value
|
||||
}
|
||||
NSLog("⚠️ DisplayServicesGetBrightness failed: \(retry.status)")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -655,9 +664,3 @@ final class SystemBrightnessController {
|
|||
observers.forEach { DistributedNotificationCenter.default().removeObserver($0) }
|
||||
}
|
||||
}
|
||||
|
||||
@_silgen_name("DisplayServicesGetBrightness")
|
||||
private func DisplayServicesGetBrightness(_ display: UInt32, _ brightness: UnsafeMutablePointer<Float>) -> Int32
|
||||
|
||||
@_silgen_name("DisplayServicesSetBrightness")
|
||||
private func DisplayServicesSetBrightness(_ display: UInt32, _ brightness: Float) -> Int32
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue