Skip to content

Commit 96d1b69

Browse files
committed
smcFanControl Community Edition: strip Apple Silicon, fix deprecated APIs, remove dead code
Intel-only fork targeting OCLP (OpenCore Legacy Patcher) Macs: - Remove IOHIDSensor (ARM64 temperature path), all TARGET_CPU_ARM64 branches - Replace OSSpinLock with os_unfair_lock, IOMasterPort with kIOMainPortDefault - Modernize NSAlert calls (alertWithMessageText → init pattern) - Replace NSArchiver/NSUnarchiver with NSKeyedArchiver (secure coding) - Fix NSSmallControlSize → NSControlSizeSmall, cString → UTF8String - Remove dead code: SystemVersion, StatusItemWindow, donation prompts - Remove Sparkle auto-updater (dead eidac.de URL), add GitHub Releases link - Apply PR hholtmann#143 (SYMROOT fix), PR hholtmann#146 (exit if no fans), PR hholtmann#108 (FP fan speed) - Update Info.plist copyright for community fork
1 parent e1bd672 commit 96d1b69

13 files changed

Lines changed: 74 additions & 640 deletions

File tree

Classes/FanControl.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#import "NSFileManager+DirectoryLocations.h"
2626
#import "smc.h"
2727
#import "smcWrapper.h"
28-
#import "IOHIDSensor.h"
2928
#import "MachineDefaults.h"
3029

3130
#import "Power.h"
@@ -113,9 +112,6 @@
113112

114113
-(void)terminate:(id)sender;
115114

116-
- (IBAction)paypal:(id)sender;
117-
- (IBAction)visitHomepage:(id)sender;
118-
119115
- (IBAction)closePreferences:(id)sender;
120116
- (IBAction)savePreferences:(id)sender;
121117
- (IBAction)updateCheck:(id)sender;

Classes/FanControl.m

Lines changed: 60 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
#import <Security/Authorization.h>
2828
#import <Security/AuthorizationDB.h>
2929
#import <Security/AuthorizationTags.h>
30-
#import <Sparkle/SUUpdater.h>
31-
#import "SystemVersion.h"
30+
// Sparkle removed — dead update server (eidac.de), will add GitHub-based updates later
3231

3332
@interface FanControl ()
3433
+ (void)copyMachinesIfNecessary;
34+
+ (void)terminateIfNoFans;
3535
@property (NS_NONATOMIC_IOSONLY, getter=isInAutoStart, readonly) BOOL inAutoStart;
3636
- (void)setStartAtLogin:(BOOL)enabled;
3737
+ (void)checkRightStatus:(OSStatus)status;
@@ -51,19 +51,30 @@ +(void) initialize {
5151

5252
//avoid Zombies when starting external app
5353
signal(SIGCHLD, SIG_IGN);
54-
55-
[FanControl copyMachinesIfNecessary];
54+
5655
//check owner and suid rights
5756
[FanControl setRights];
5857

5958
//talk to smc
6059
[smcWrapper init];
61-
60+
61+
[FanControl terminateIfNoFans];
62+
63+
[FanControl copyMachinesIfNecessary];
64+
6265
//app in foreground for update notifications
6366
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
6467

6568
}
6669

70+
+(void) terminateIfNoFans {
71+
int fan_num = [smcWrapper get_fan_num];
72+
if (fan_num <= 0) {
73+
NSLog(@"Exiting as %d fans were detected for Model Identifier: %@", fan_num, [MachineDefaults computerModel]);
74+
[[NSApplication sharedApplication] terminate:self];
75+
}
76+
}
77+
6778
+(void)copyMachinesIfNecessary
6879
{
6980
NSString *path = [[[NSFileManager defaultManager] applicationSupportDirectory] stringByAppendingPathComponent:@"Machines.plist"];
@@ -150,14 +161,10 @@ -(void) awakeFromNib {
150161
@0, PREF_AC_SELECTION,
151162
@0, PREF_CHARGING_SELECTION,
152163
@0, PREF_MENU_DISPLAYMODE,
153-
#if TARGET_CPU_ARM64
154-
@"Tp0D",PREF_TEMPERATURE_SENSOR,
155-
#else
156164
@"TC0D",PREF_TEMPERATURE_SENSOR,
157-
#endif
158165
@0, PREF_NUMBEROF_LAUNCHES,
159166
@NO,PREF_DONATIONMESSAGE_DISPLAY,
160-
[NSArchiver archivedDataWithRootObject:[NSColor blackColor]],PREF_MENU_TEXTCOLOR,
167+
[NSKeyedArchiver archivedDataWithRootObject:[NSColor blackColor] requiringSecureCoding:NO error:nil],PREF_MENU_TEXTCOLOR,
161168
favorites,PREF_FAVORITES_ARRAY,
162169
nil]];
163170

@@ -205,7 +212,7 @@ -(void) awakeFromNib {
205212
[faqText replaceCharactersInRange:NSMakeRange(0,0) withRTF: [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"F.A.Q" ofType:@"rtf"]]];
206213
[self apply_settings:nil controllerindex:[[defaults objectForKey:PREF_SELECTION_DEFAULT] intValue]];
207214
[[[[theMenu itemWithTag:1] submenu] itemAtIndex:[[defaults objectForKey:PREF_SELECTION_DEFAULT] intValue]] setState:NSOnState];
208-
[[sliderCell dataCell] setControlSize:NSSmallControlSize];
215+
[[sliderCell dataCell] setControlSize:NSControlSizeSmall];
209216
[self changeMenu:nil];
210217

211218
//seting toolbar image
@@ -228,30 +235,10 @@ -(void) awakeFromNib {
228235

229236
//autostart
230237
[[NSUserDefaults standardUserDefaults] setValue:@([self isInAutoStart]) forKey:PREF_AUTOSTART_ENABLED];
231-
NSUInteger numLaunches = [[[NSUserDefaults standardUserDefaults] objectForKey:PREF_NUMBEROF_LAUNCHES] integerValue];
232-
[[NSUserDefaults standardUserDefaults] setObject:@(numLaunches+1) forKey:PREF_NUMBEROF_LAUNCHES];
233-
if (numLaunches != 0 && (numLaunches % 3 == 0) && ![[[NSUserDefaults standardUserDefaults] objectForKey:PREF_DONATIONMESSAGE_DISPLAY] boolValue]) {
234-
[self displayDonationMessage];
235-
}
236-
237238
[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(readFanData:) name:@"AppleInterfaceThemeChangedNotification" object:nil];
238239

239240
}
240241

241-
-(void)displayDonationMessage
242-
{
243-
NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Consider a donation",nil)
244-
defaultButton:NSLocalizedString(@"Donate over Paypal",nil) alternateButton:NSLocalizedString(@"Never ask me again",nil) otherButton:NSLocalizedString(@"Remind me later",nil)
245-
informativeTextWithFormat:NSLocalizedString(@"smcFanControl keeps your Mac cool since 2006.\n\nIf smcFanControl is helfpul for you and you want to support further development, a small donation over Paypal is much appreciated.",nil)];
246-
NSModalResponse code=[alert runModal];
247-
if (code == NSAlertDefaultReturn) {
248-
[self paypal:nil];
249-
[[NSUserDefaults standardUserDefaults] setObject:@(YES) forKey:PREF_DONATIONMESSAGE_DISPLAY];
250-
} else if (code == NSAlertAlternateReturn) {
251-
[[NSUserDefaults standardUserDefaults] setObject:@(YES) forKey:PREF_DONATIONMESSAGE_DISPLAY];
252-
}
253-
}
254-
255242

256243
-(void)init_statusitem{
257244
statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength: NSVariableStatusItemLength];
@@ -321,7 +308,7 @@ -(void) check_deletion:(id)combo{
321308

322309
- (void) deleteAlertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
323310
{
324-
if (returnCode==0) {
311+
if (returnCode==NSAlertSecondButtonReturn) {
325312
//delete favorite, but resets presets before
326313
[self check_deletion:PREF_BATTERY_SELECTION];
327314
[self check_deletion:PREF_AC_SELECTION];
@@ -332,20 +319,16 @@ - (void) deleteAlertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode con
332319

333320
- (IBAction)delete_favorite:(id)sender{
334321

335-
NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Delete favorite",nil) defaultButton:NSLocalizedString(@"No",nil) alternateButton:NSLocalizedString(@"Yes",nil) otherButton:nil informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"Do you really want to delete the favorite %@?",nil), [FavoritesController arrangedObjects][[FavoritesController selectionIndex]][@"Title"] ]];
322+
NSAlert *alert = [[NSAlert alloc] init];
323+
[alert setMessageText:NSLocalizedString(@"Delete favorite",nil)];
324+
[alert setInformativeText:[NSString stringWithFormat:NSLocalizedString(@"Do you really want to delete the favorite %@?",nil), [FavoritesController arrangedObjects][[FavoritesController selectionIndex]][@"Title"]]];
325+
[alert addButtonWithTitle:NSLocalizedString(@"No",nil)];
326+
[alert addButtonWithTitle:NSLocalizedString(@"Yes",nil)];
336327

337328
[alert beginSheetModalForWindow:mainwindow modalDelegate:self didEndSelector:@selector(deleteAlertDidEnd:returnCode:contextInfo:) contextInfo:NULL];
338329
}
339330

340331

341-
- (BOOL)usesIOHIDForTemperature {
342-
#if TARGET_CPU_ARM64
343-
return [[MachineDefaults computerModel] rangeOfString:@"MacBookPro17"].length > 0;
344-
#else
345-
return false;
346-
#endif
347-
}
348-
349332
// Called via a timer mechanism. This is where all the temp / RPM reading is done.
350333
//reads fan data and updates the gui
351334
-(void) readFanData:(id)caller{
@@ -410,11 +393,7 @@ -(void) readFanData:(id)caller{
410393

411394
if (bNeedTemp == true) {
412395
// Read current temperature and format text for the menubar.
413-
if ([self usesIOHIDForTemperature]) {
414-
c_temp = [IOHIDSensor getSOCTemperature];
415-
} else {
416-
c_temp = [smcWrapper get_maintemp];
417-
}
396+
c_temp = [smcWrapper get_maintemp];
418397

419398
if ([[defaults objectForKey:PREF_TEMP_UNIT] intValue]==0) {
420399
temp = [NSString stringWithFormat:@"%@%CC",@(c_temp),(unsigned short)0xb0];
@@ -429,7 +408,7 @@ -(void) readFanData:(id)caller{
429408
NSMutableAttributedString *s_status = nil;
430409
NSMutableParagraphStyle *paragraphStyle = nil;
431410

432-
NSColor *menuColor = (NSColor*)[NSUnarchiver unarchiveObjectWithData:[defaults objectForKey:PREF_MENU_TEXTCOLOR]];
411+
NSColor *menuColor = (NSColor*)[NSKeyedUnarchiver unarchivedObjectOfClass:[NSColor class] fromData:[defaults objectForKey:PREF_MENU_TEXTCOLOR] error:nil];
433412
BOOL setColor = NO;
434413
if (!([[menuColor colorUsingColorSpaceName:
435414
NSCalibratedWhiteColorSpace] whiteComponent] == 0.0) || ![statusItem respondsToSelector:@selector(button)]) setColor = YES;
@@ -462,9 +441,7 @@ -(void) readFanData:(id)caller{
462441
[paragraphStyle setAlignment:NSLeftTextAlignment];
463442
[s_status addAttribute:NSFontAttributeName value:[NSFont fontWithName:@"Lucida Grande" size:fsize] range:NSMakeRange(0,[s_status length])];
464443
[s_status addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0,[s_status length])];
465-
if (menuBarSetting == 0)
466-
[s_status addAttribute:NSBaselineOffsetAttributeName value:[NSNumber numberWithFloat: -6] range:NSMakeRange(0, [s_status length])];
467-
444+
468445
if (setColor) [s_status addAttribute:NSForegroundColorAttributeName value:menuColor range:NSMakeRange(0,[s_status length])];
469446

470447

@@ -549,16 +526,6 @@ - (IBAction)closePreferences:(id)sender{
549526
[DefaultsController revert:sender];
550527
}
551528

552-
-(void)setFansToAuto:(bool)is_auto {
553-
for (int fan_index=0;fan_index<[[FavoritesController arrangedObjects][0][PREF_FAN_ARRAY] count];fan_index++) {
554-
[self setFanToAuto:fan_index is_auto:is_auto];
555-
}
556-
}
557-
558-
-(void)setFanToAuto:(int)fan_index is_auto:(bool)is_auto {
559-
[smcWrapper setKey_external:[NSString stringWithFormat:@"F%dMd",fan_index] value:is_auto ? @"00" : @"01"];
560-
}
561-
562529
//set the new fan settings
563530

564531
-(void)apply_settings:(id)sender controllerindex:(int)cIndex{
@@ -573,7 +540,7 @@ -(void)apply_settings:(id)sender controllerindex:(int)cIndex{
573540
[smcWrapper setKey_external:[NSString stringWithFormat:@"F%dMn",i] value:[[FanController arrangedObjects][i][PREF_FAN_SELSPEED] tohex]];
574541
} else {
575542
bool is_auto = [[FanController arrangedObjects][i][PREF_FAN_AUTO] boolValue];
576-
[self setFanToAuto:i is_auto:is_auto];
543+
[smcWrapper setKey_external:[NSString stringWithFormat:@"F%dMd",i] value:is_auto ? @"00" : @"01"];
577544
float f_val = [[FanController arrangedObjects][i][PREF_FAN_SELSPEED] floatValue];
578545
uint8 *vals = (uint8*)&f_val;
579546
//NSString str_val = ;
@@ -682,9 +649,15 @@ - (void)menuNeedsUpdate:(NSMenu*)menu {
682649

683650
//just a helper to bringt update-info-window to the front
684651
- (IBAction)updateCheck:(id)sender{
685-
SUUpdater *updater = [[SUUpdater alloc] init];
686-
[updater checkForUpdates:sender];
687-
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
652+
// TODO: Implement GitHub Releases-based update check
653+
NSAlert *alert = [[NSAlert alloc] init];
654+
[alert setMessageText:@"Check for Updates"];
655+
[alert setInformativeText:@"Visit the GitHub releases page to check for updates."];
656+
[alert addButtonWithTitle:@"Open GitHub"];
657+
[alert addButtonWithTitle:@"Cancel"];
658+
if ([alert runModal] == NSAlertFirstButtonReturn) {
659+
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://github.com/wolffcatskyy/smcFanControl/releases"]];
660+
}
688661
}
689662

690663

@@ -700,45 +673,39 @@ -(void)performReset
700673
}
701674
error = nil;
702675
if ([[MachineDefaults computerModel] rangeOfString:@"MacBookPro15"].location != NSNotFound) {
703-
[self setFansToAuto:true];
676+
for (int i=0;i<[[FavoritesController arrangedObjects][0][PREF_FAN_ARRAY] count];i++) {
677+
[smcWrapper setKey_external:[NSString stringWithFormat:@"F%dMd",i] value:@"00"];
678+
}
704679
}
705680

706681
NSString *domainName = [[NSBundle mainBundle] bundleIdentifier];
707682
[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:domainName];
708683

709684

710-
NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Shutdown required",nil)
711-
defaultButton:NSLocalizedString(@"OK",nil) alternateButton:nil otherButton:nil
712-
informativeTextWithFormat:NSLocalizedString(@"Please shutdown your computer now to return to default fan settings.",nil)];
685+
NSAlert *alert = [[NSAlert alloc] init];
686+
[alert setMessageText:NSLocalizedString(@"Shutdown required",nil)];
687+
[alert setInformativeText:NSLocalizedString(@"Please shutdown your computer now to return to default fan settings.",nil)];
688+
[alert addButtonWithTitle:NSLocalizedString(@"OK",nil)];
713689
NSModalResponse code=[alert runModal];
714-
if (code == NSAlertDefaultReturn) {
690+
if (code == NSAlertFirstButtonReturn) {
715691
[[NSApplication sharedApplication] terminate:self];
716692
}
717693
}
718694

719695
- (IBAction)resetSettings:(id)sender
720696
{
721-
NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Reset Settings",nil)
722-
defaultButton:NSLocalizedString(@"Yes",nil) alternateButton:NSLocalizedString(@"No",nil) otherButton:nil
723-
informativeTextWithFormat:NSLocalizedString(@"Do you want to reset smcFanControl to default settings? Favorites will be deleted and fans will return to default speed.",nil)];
697+
NSAlert *alert = [[NSAlert alloc] init];
698+
[alert setMessageText:NSLocalizedString(@"Reset Settings",nil)];
699+
[alert setInformativeText:NSLocalizedString(@"Do you want to reset smcFanControl to default settings? Favorites will be deleted and fans will return to default speed.",nil)];
700+
[alert addButtonWithTitle:NSLocalizedString(@"Yes",nil)];
701+
[alert addButtonWithTitle:NSLocalizedString(@"No",nil)];
724702
NSModalResponse code=[alert runModal];
725-
if (code == NSAlertDefaultReturn) {
703+
if (code == NSAlertFirstButtonReturn) {
726704
[self performReset];
727-
} else if (code == NSAlertAlternateReturn) {
728-
729705
}
730706

731707
}
732708

733-
- (IBAction)visitHomepage:(id)sender{
734-
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://www.eidac.de/products"]];
735-
}
736-
737-
738-
- (IBAction)paypal:(id)sender{
739-
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=holtmann%40campus%2dvirtuell%2ede&no_shipping=0&no_note=1&tax=0&currency_code=EUR&bn=PP%2dDonationsBF&charset=UTF%2d8&country=US"]];
740-
}
741-
742709
-(void) syncBinder:(Boolean)bind{
743710
//in case plist is corrupt, don't bind
744711
if ([[FanController arrangedObjects] count]>1 ) {
@@ -756,10 +723,6 @@ -(void) syncBinder:(Boolean)bind{
756723
#pragma mark **Power Watchdog-Methods**
757724

758725
- (void)systemWillSleep:(id)sender{
759-
#if TARGET_CPU_ARM64
760-
[FanControl setRights];
761-
[self setFansToAuto:true];
762-
#endif
763726
}
764727

765728
- (void)systemDidWakeFromSleep:(id)sender{
@@ -879,11 +842,14 @@ - (void) setStartAtLogin:(BOOL)enabled {
879842
+(void) checkRightStatus:(OSStatus) status
880843
{
881844
if (status != errAuthorizationSuccess) {
882-
NSAlert *alert = [NSAlert alertWithMessageText:@"Authorization failed" defaultButton:@"Quit" alternateButton:nil otherButton:nil informativeTextWithFormat:[NSString stringWithFormat:@"Authorization failed with code %d",status]];
883-
[alert setAlertStyle:2];
845+
NSAlert *alert = [[NSAlert alloc] init];
846+
[alert setMessageText:@"Authorization failed"];
847+
[alert setInformativeText:[NSString stringWithFormat:@"Authorization failed with code %d",status]];
848+
[alert addButtonWithTitle:@"Quit"];
849+
[alert setAlertStyle:NSAlertStyleCritical];
884850
NSInteger result = [alert runModal];
885-
886-
if (result == NSAlertDefaultReturn) {
851+
852+
if (result == NSAlertFirstButtonReturn) {
887853
[[NSApplication sharedApplication] terminate:self];
888854
}
889855
}
@@ -915,7 +881,7 @@ +(void)setRights{
915881
int i;
916882
char *args[255];
917883
for(i = 0;i < [argsArray count];i++){
918-
args[i] = (char *)[argsArray[i]cString];
884+
args[i] = (char *)[argsArray[i] UTF8String];
919885
}
920886
args[i] = NULL;
921887
status=AuthorizationExecuteWithPrivileges(authorizationRef,[tool UTF8String],0,args,&commPipe);
@@ -926,7 +892,7 @@ +(void)setRights{
926892
tool=@"/bin/chmod";
927893
argsArray = @[@"6555",smcpath];
928894
for(i = 0;i < [argsArray count];i++){
929-
args[i] = (char *)[argsArray[i]cString];
895+
args[i] = (char *)[argsArray[i] UTF8String];
930896
}
931897
args[i] = NULL;
932898
status=AuthorizationExecuteWithPrivileges(authorizationRef,[tool UTF8String],0,args,&commPipe);

0 commit comments

Comments
 (0)