Skip to content
Open
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
25 changes: 23 additions & 2 deletions Hot/Classes/NSApplication+LaunchServices.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
******************************************************************************/

#import "NSApplication+LaunchServices.h"
#import <ServiceManagement/ServiceManagement.h>

/*
* LaunchServices functions for managing login items are deprecated,
Expand Down Expand Up @@ -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
Expand Down
78 changes: 17 additions & 61 deletions Hot/Classes/ThermalLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import Foundation
import IOHIDKit
import SMCKit
import IOKit.pwr_mgt

public class ThermalLog: NSObject
{
Expand Down Expand Up @@ -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<Unmanaged<CFDictionary>?>.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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that the new code runs only on x86_64, and no code running on arm64. Did you test this on Apple silicon?


self.refreshing = false

Expand Down