diff --git a/Hot/Classes/NSApplication+LaunchServices.m b/Hot/Classes/NSApplication+LaunchServices.m index 1f9010c..c089725 100644 --- a/Hot/Classes/NSApplication+LaunchServices.m +++ b/Hot/Classes/NSApplication+LaunchServices.m @@ -23,6 +23,7 @@ ******************************************************************************/ #import "NSApplication+LaunchServices.h" +#import /* * LaunchServices functions for managing login items are deprecated, @@ -205,12 +206,32 @@ + ( void )disableLoginItemForBundleURL: ( NSURL * )url - ( BOOL )isLoginItemEnabled { - return [ NSApplication isLoginItemEnabledForBundleURL: [ NSURL fileURLWithPath: [ [ NSBundle mainBundle ] bundlePath ] ] ]; + if (@available(macOS 13.0, *)) { + + SMAppServiceStatus status = SMAppService.mainAppService.status; + NSLog(@"SMAppServiceStatus=%li", status); + return status == SMAppServiceStatusEnabled; + } else { + return [ NSApplication isLoginItemEnabledForBundleURL: [ NSURL fileURLWithPath: [ [ NSBundle mainBundle ] bundlePath ] ] ]; + } } - ( void )setLoginItemEnabled: ( BOOL )enabled { - [ NSApplication setLoginItemEnabled: enabled forBundleURL: [ NSURL fileURLWithPath: [ [ NSBundle mainBundle ] bundlePath ] ] ]; + if (@available(macOS 13.0, *)) { + + NSError *error; + + if (enabled) { + [SMAppService.mainAppService registerAndReturnError:&error]; + NSLog(@"SMAppService Registered with error: %@",error); + } else { + NSLog(@"SMAppService Unregistered with error: %@",error); + [SMAppService.mainAppService unregisterAndReturnError:&error]; + } + } else { + [ NSApplication setLoginItemEnabled: enabled forBundleURL: [ NSURL fileURLWithPath: [ [ NSBundle mainBundle ] bundlePath ] ] ]; + } } - ( void )enableLoginItem diff --git a/Hot/Classes/ThermalLog.swift b/Hot/Classes/ThermalLog.swift index 06cb820..bbaf7de 100644 --- a/Hot/Classes/ThermalLog.swift +++ b/Hot/Classes/ThermalLog.swift @@ -25,6 +25,7 @@ import Foundation import IOHIDKit import SMCKit +import IOKit.pwr_mgt public class ThermalLog: NSObject { @@ -185,67 +186,22 @@ public class ThermalLog: NSObject { self.temperature = NSNumber( value: temp ) } - - let pipe = Pipe() - let task = Process() - task.launchPath = "/usr/bin/pmset" - task.arguments = [ "-g", "therm" ] - task.standardOutput = pipe - - task.launch() - task.waitUntilExit() - - if task.terminationStatus != 0 - { - self.refreshing = false - - completion() - - return - } - - let data = pipe.fileHandleForReading.readDataToEndOfFile() - - guard let str = String( data: data, encoding: .utf8 ), str.count > 0 - else - { - self.refreshing = false - - completion() - - return - } - - let lines = str.replacingOccurrences( of: " ", with: "" ).replacingOccurrences( of: "\t", with: "" ).split( separator: "\n" ) - - for line in lines - { - let p = line.split( separator: "=" ) - - if p.count < 2 - { - continue - } - - guard let n = UInt( p[ 1 ] ) - else - { - continue - } - - if p[ 0 ] == "CPU_Scheduler_Limit" - { - self.schedulerLimit = NSNumber( value: n ) - } - else if p[ 0 ] == "CPU_Available_CPUs" - { - self.availableCPUs = NSNumber( value: n ) - } - else if p[ 0 ] == "CPU_Speed_Limit" - { - self.speedLimit = NSNumber( value: n ) - } - } + +#if arch(x86_64) + let status = UnsafeMutablePointer?>.allocate(capacity: 3) + let result = IOPMCopyCPUPowerStatus(status) + + if result == kIOReturnSuccess, + let data = status.move()?.takeUnretainedValue() { + let dataMap = data as NSDictionary + + self.speedLimit = dataMap[kIOPMCPUPowerLimitProcessorSpeedKey] as? NSNumber + self.availableCPUs = dataMap[kIOPMCPUPowerLimitProcessorCountKey] as? NSNumber + self.schedulerLimit = dataMap[kIOPMCPUPowerLimitSchedulerTimeKey] as? NSNumber + } + + status.deallocate() +#endif self.refreshing = false