diff --git a/Classes/Constants.h b/Classes/Constants.h new file mode 100644 index 0000000..0070982 --- /dev/null +++ b/Classes/Constants.h @@ -0,0 +1,28 @@ +// +// Constants.h +// smcFanControl +// +// Created by Hendrik Holtmann on 16/10/16. +// +// + +#define PREF_TEMP_UNIT @"Unit" +#define PREF_SELECTION_DEFAULT @"SelDefault" +#define PREF_AUTOSTART_ENABLED @"AutoStart" +#define PREF_AUTOMATIC_CHANGE @"AutomaticChange" +#define PREF_BATTERY_SELECTION @"selbatt" +#define PREF_AC_SELECTION @"selac" +#define PREF_CHARGING_SELECTION @"selload" +#define PREF_MENU_DISPLAYMODE @"MenuBar" +#define PREF_TEMPERATURE_SENSOR @"TSensor" +#define PREF_NUMBEROF_LAUNCHES @"NumLaunches" +#define PREF_DONATIONMESSAGE_DISPLAY @"DonationMessageDisplay" +#define PREF_MENU_TEXTCOLOR @"MenuColor" +#define PREF_FAVORITES_ARRAY @"Favorites" + +#define PREF_FAN_ARRAY @"FanData" +#define PREF_FAN_TITLE @"Title" +#define PREF_FAN_MINSPEED @"Minspeed" +#define PREF_FAN_SELSPEED @"selspeed" +#define PREF_FAN_SYNC @"sync" +#define PREF_FAN_SHOWMENU @"menu" diff --git a/Classes/FanControl.h b/Classes/FanControl.h index 19f5a8f..a1b4d55 100755 --- a/Classes/FanControl.h +++ b/Classes/FanControl.h @@ -34,6 +34,7 @@ #include #include +#import "Constants.h" #define kMenuBarHeight 22 diff --git a/Classes/FanControl.m b/Classes/FanControl.m index 29ff0fb..8e896c2 100755 --- a/Classes/FanControl.m +++ b/Classes/FanControl.m @@ -80,14 +80,14 @@ -(void)upgradeFavorites for (i=0;i<[rfavorites count];i++) { BOOL selected = NO; - NSArray *fans = rfavorites[i][@"FanData"]; + NSArray *fans = rfavorites[i][PREF_FAN_ARRAY]; for (j=0;j<[fans count];j++) { - if ([fans[j][@"menu"] boolValue] == YES ) { + if ([fans[j][PREF_FAN_SHOWMENU] boolValue] == YES ) { selected = YES; } } if (selected==NO) { - rfavorites[i][@"FanData"][0][@"menu"] = @YES; + rfavorites[i][PREF_FAN_ARRAY][0][PREF_FAN_SHOWMENU] = @YES; } } @@ -111,8 +111,8 @@ -(void) awakeFromNib { NSMutableArray *favorites = [[NSMutableArray alloc] init]; - NSMutableDictionary *defaultFav = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Default", @"Title", - [NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:[[mdefaults get_machine_defaults] objectForKey:@"Fans"]]], @"FanData",nil]; + NSMutableDictionary *defaultFav = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Default", PREF_FAN_TITLE, + [NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:[[mdefaults get_machine_defaults] objectForKey:@"Fans"]]], PREF_FAN_ARRAY,nil]; [favorites addObject:defaultFav]; @@ -120,12 +120,12 @@ -(void) awakeFromNib { NSRange range=[[MachineDefaults computerModel] rangeOfString:@"MacBook"]; if (range.length>0) { //for macbooks add a second default - NSMutableDictionary *higherFav=[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Higher RPM", @"Title", - [NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:[[mdefaults get_machine_defaults] objectForKey:@"Fans"]]], @"FanData",nil]; + NSMutableDictionary *higherFav=[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Higher RPM", PREF_FAN_TITLE, + [NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:[[mdefaults get_machine_defaults] objectForKey:@"Fans"]]], PREF_FAN_ARRAY,nil]; for (NSUInteger i=0;i<[_machineDefaultsDict[@"Fans"] count];i++) { - int min_value=([[[[_machineDefaultsDict objectForKey:@"Fans"] objectAtIndex:i] objectForKey:@"Minspeed"] intValue])*2; - [[[higherFav objectForKey:@"FanData"] objectAtIndex:i] setObject:[NSNumber numberWithInt:min_value] forKey:@"selspeed"]; + int min_value=([[[[_machineDefaultsDict objectForKey:@"Fans"] objectAtIndex:i] objectForKey:PREF_FAN_MINSPEED] intValue])*2; + [[[higherFav objectForKey:PREF_FAN_ARRAY] objectAtIndex:i] setObject:[NSNumber numberWithInt:min_value] forKey:PREF_FAN_SELSPEED]; } [favorites addObject:higherFav]; @@ -141,19 +141,19 @@ -(void) awakeFromNib { defaults = [NSUserDefaults standardUserDefaults]; [defaults registerDefaults: [NSMutableDictionary dictionaryWithObjectsAndKeys: - @0, @"Unit", - @0, @"SelDefault", - @NO, @"AutoStart", - @NO,@"AutomaticChange", - @0,@"selbatt", - @0,@"selac", - @0,@"selload", - @0,@"MenuBar", - @"TC0D",@"TSensor", - @0,@"NumLaunches", - @NO,@"DonationMessageShown", - [NSArchiver archivedDataWithRootObject:[NSColor blackColor]],@"MenuColor", - favorites,@"Favorites", + @0, PREF_TEMP_UNIT, + @0, PREF_SELECTION_DEFAULT, + @NO,PREF_AUTOSTART_ENABLED, + @NO,PREF_AUTOMATIC_CHANGE, + @0, PREF_BATTERY_SELECTION, + @0, PREF_AC_SELECTION, + @0, PREF_CHARGING_SELECTION, + @0, PREF_MENU_DISPLAYMODE, + @"TC0D",PREF_TEMPERATURE_SENSOR, + @0, PREF_NUMBEROF_LAUNCHES, + @NO,PREF_DONATIONMESSAGE_DISPLAY, + [NSArchiver archivedDataWithRootObject:[NSColor blackColor]],PREF_MENU_TEXTCOLOR, + favorites,PREF_FAVORITES_ARRAY, nil]]; @@ -169,15 +169,15 @@ -(void) awakeFromNib { [FavoritesController bind:@"content" toObject:[NSUserDefaultsController sharedUserDefaultsController] - withKeyPath:@"values.Favorites" + withKeyPath:[@"values." stringByAppendingString:PREF_FAVORITES_ARRAY] options:nil]; [FavoritesController setEditable:YES]; // set slider sync - only for MBP for (i=0;i<[[FavoritesController arrangedObjects] count];i++) { - if([[FavoritesController arrangedObjects][i][@"sync"] boolValue]==YES) { + if([[FavoritesController arrangedObjects][i][PREF_FAN_SYNC] boolValue]==YES) { [FavoritesController setSelectionIndex:i]; - [self syncBinder:[[FavoritesController arrangedObjects][i][@"sync"] boolValue]]; + [self syncBinder:[[FavoritesController arrangedObjects][i][PREF_FAN_SYNC] boolValue]]; } } @@ -198,8 +198,8 @@ -(void) awakeFromNib { [autochange setEnabled:false]; } [faqText replaceCharactersInRange:NSMakeRange(0,0) withRTF: [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"F.A.Q" ofType:@"rtf"]]]; - [self apply_settings:nil controllerindex:[[defaults objectForKey:@"SelDefault"] intValue]]; - [[[[theMenu itemWithTag:1] submenu] itemAtIndex:[[defaults objectForKey:@"SelDefault"] intValue]] setState:NSOnState]; + [self apply_settings:nil controllerindex:[[defaults objectForKey:PREF_SELECTION_DEFAULT] intValue]]; + [[[[theMenu itemWithTag:1] submenu] itemAtIndex:[[defaults objectForKey:PREF_SELECTION_DEFAULT] intValue]] setState:NSOnState]; [[sliderCell dataCell] setControlSize:NSSmallControlSize]; [self changeMenu:nil]; @@ -222,10 +222,10 @@ -(void) awakeFromNib { [self upgradeFavorites]; //autostart - [[NSUserDefaults standardUserDefaults] setValue:@([self isInAutoStart]) forKey:@"AutoStart"]; - NSUInteger numLaunches = [[[NSUserDefaults standardUserDefaults] objectForKey:@"NumLaunches"] integerValue]; - [[NSUserDefaults standardUserDefaults] setObject:@(numLaunches+1) forKey:@"NumLaunches"]; - if (numLaunches != 0 && (numLaunches % 5 == 0) && ![[[NSUserDefaults standardUserDefaults] objectForKey:@"DonationMessageShown"] boolValue]) { + [[NSUserDefaults standardUserDefaults] setValue:@([self isInAutoStart]) forKey:PREF_AUTOSTART_ENABLED]; + NSUInteger numLaunches = [[[NSUserDefaults standardUserDefaults] objectForKey:PREF_NUMBEROF_LAUNCHES] integerValue]; + [[NSUserDefaults standardUserDefaults] setObject:@(numLaunches+1) forKey:PREF_NUMBEROF_LAUNCHES]; + if (numLaunches != 0 && (numLaunches % 3 == 0) && ![[[NSUserDefaults standardUserDefaults] objectForKey:PREF_DONATIONMESSAGE_DISPLAY] boolValue]) { [self displayDonationMessage]; } @@ -241,9 +241,9 @@ -(void)displayDonationMessage NSModalResponse code=[alert runModal]; if (code == NSAlertDefaultReturn) { [self paypal:nil]; - [[NSUserDefaults standardUserDefaults] setObject:@(YES) forKey:@"DonationMessageShown"]; + [[NSUserDefaults standardUserDefaults] setObject:@(YES) forKey:PREF_DONATIONMESSAGE_DISPLAY]; } else if (code == NSAlertAlternateReturn) { - [[NSUserDefaults standardUserDefaults] setObject:@(YES) forKey:@"DonationMessageShown"]; + [[NSUserDefaults standardUserDefaults] setObject:@(YES) forKey:PREF_DONATIONMESSAGE_DISPLAY]; } } @@ -296,7 +296,7 @@ - (IBAction)close_favorite:(id)sender{ - (IBAction)save_favorite:(id)sender{ MachineDefaults *msdefaults=[[MachineDefaults alloc] init:nil]; if ([[newfavorite_title stringValue] length]>0) { - NSMutableDictionary *toinsert=[[NSMutableDictionary alloc] initWithObjectsAndKeys:[newfavorite_title stringValue],@"Title",[msdefaults get_machine_defaults][@"Fans"],@"FanData",nil]; //default as template + NSMutableDictionary *toinsert=[[NSMutableDictionary alloc] initWithObjectsAndKeys:[newfavorite_title stringValue],@"Title",[msdefaults get_machine_defaults][@"Fans"],PREF_FAN_ARRAY,nil]; //default as template [toinsert setValue:@0 forKey:@"Standard"]; [FavoritesController addObject:toinsert]; [newfavoritewindow close]; @@ -318,9 +318,9 @@ - (void) deleteAlertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode con { if (returnCode==0) { //delete favorite, but resets presets before - [self check_deletion:@"selbatt"]; - [self check_deletion:@"selac"]; - [self check_deletion:@"selload"]; + [self check_deletion:PREF_BATTERY_SELECTION]; + [self check_deletion:PREF_AC_SELECTION]; + [self check_deletion:PREF_CHARGING_SELECTION]; [FavoritesController removeObjects:[FavoritesController selectedObjects]]; } } @@ -349,7 +349,7 @@ -(void) readFanData:(id)caller{ // as low as possible. bool bNeedTemp = false; bool bNeedRpm = false; - const int menuBarSetting = [[defaults objectForKey:@"MenuBar"] intValue]; + const int menuBarSetting = [[defaults objectForKey:PREF_MENU_DISPLAYMODE] intValue]; switch (menuBarSetting) { default: case 1: @@ -380,10 +380,10 @@ -(void) readFanData:(id)caller{ if (bNeedRpm == true) { // Read the current fan speed for the desired fan and format text for display in the menubar. - NSArray *fans = [FavoritesController arrangedObjects][[FavoritesController selectionIndex]][@"FanData"]; + NSArray *fans = [FavoritesController arrangedObjects][[FavoritesController selectionIndex]][PREF_FAN_ARRAY]; for (i=0; i1 ) { if (bind==YES) { - [[FanController arrangedObjects][1] bind:@"selspeed" toObject:[FanController arrangedObjects][0] withKeyPath:@"selspeed" options:nil]; - [[FanController arrangedObjects][0] bind:@"selspeed" toObject:[FanController arrangedObjects][1] withKeyPath:@"selspeed" options:nil]; + [[FanController arrangedObjects][1] bind:PREF_FAN_SELSPEED toObject:[FanController arrangedObjects][0] withKeyPath:PREF_FAN_SELSPEED options:nil]; + [[FanController arrangedObjects][0] bind:PREF_FAN_SELSPEED toObject:[FanController arrangedObjects][1] withKeyPath:PREF_FAN_SELSPEED options:nil]; } else { - [[FanController arrangedObjects][1] unbind:@"selspeed"]; - [[FanController arrangedObjects][0] unbind:@"selspeed"]; + [[FanController arrangedObjects][1] unbind:PREF_FAN_SELSPEED]; + [[FanController arrangedObjects][0] unbind:PREF_FAN_SELSPEED]; } } } @@ -713,27 +713,27 @@ -(void) syncBinder:(Boolean)bind{ #pragma mark **Power Watchdog-Methods** - (void)systemDidWakeFromSleep:(id)sender{ - [self apply_settings:nil controllerindex:[[defaults objectForKey:@"SelDefault"] intValue]]; + [self apply_settings:nil controllerindex:[[defaults objectForKey:PREF_SELECTION_DEFAULT] intValue]]; } - (void)powerChangeToBattery:(id)sender{ if ([[defaults objectForKey:@"AutomaticChange"] boolValue]==YES) { - [self apply_settings:nil controllerindex:[[defaults objectForKey:@"selbatt"] intValue]]; + [self apply_settings:nil controllerindex:[[defaults objectForKey:PREF_BATTERY_SELECTION] intValue]]; } } - (void)powerChangeToAC:(id)sender{ if ([[defaults objectForKey:@"AutomaticChange"] boolValue]==YES) { - [self apply_settings:nil controllerindex:[[defaults objectForKey:@"selac"] intValue]]; + [self apply_settings:nil controllerindex:[[defaults objectForKey:PREF_AC_SELECTION] intValue]]; } } - (void)powerChangeToACLoading:(id)sender{ if ([[defaults objectForKey:@"AutomaticChange"] boolValue]==YES) { - [self apply_settings:nil controllerindex:[[defaults objectForKey:@"selload"] intValue]]; + [self apply_settings:nil controllerindex:[[defaults objectForKey:PREF_CHARGING_SELECTION] intValue]]; } } diff --git a/Classes/smcWrapper.h b/Classes/smcWrapper.h index a927638..8a2abaa 100755 --- a/Classes/smcWrapper.h +++ b/Classes/smcWrapper.h @@ -24,6 +24,7 @@ #import #import #import +#import "Constants.h" @interface smcWrapper : NSObject { } diff --git a/Classes/smcWrapper.m b/Classes/smcWrapper.m index 4c73b35..46f202f 100755 --- a/Classes/smcWrapper.m +++ b/Classes/smcWrapper.m @@ -41,7 +41,7 @@ +(float)readTempSensors { float retValue; SMCVal_t val; - NSString *sensor = [[NSUserDefaults standardUserDefaults] objectForKey:@"TSensor"]; + NSString *sensor = [[NSUserDefaults standardUserDefaults] objectForKey:PREF_TEMPERATURE_SENSOR]; SMCReadKey2((char*)[sensor UTF8String], &val,conn); retValue= ((val.bytes[0] * 256 + val.bytes[1]) >> 2)/64; allSensors = [NSArray arrayWithObjects:@"TC0D",@"TC0P",@"TCAD",@"TC0H",@"TC0F",@"TCAH",@"TCBH",nil]; @@ -50,7 +50,7 @@ +(float)readTempSensors SMCReadKey2((char*)[sensor UTF8String], &val,conn); retValue= ((val.bytes[0] * 256 + val.bytes[1]) >> 2)/64; if (retValue>0 && floor(retValue) != 129 ) { - [[NSUserDefaults standardUserDefaults] setObject:sensor forKey:@"TSensor"]; + [[NSUserDefaults standardUserDefaults] setObject:sensor forKey:PREF_TEMPERATURE_SENSOR]; [[NSUserDefaults standardUserDefaults] synchronize]; break; } diff --git a/smcFanControl.xcodeproj/project.pbxproj b/smcFanControl.xcodeproj/project.pbxproj index ecc7848..c0a88d9 100644 --- a/smcFanControl.xcodeproj/project.pbxproj +++ b/smcFanControl.xcodeproj/project.pbxproj @@ -107,6 +107,7 @@ 894DC9E60F8AA399006A046F /* Spanish */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Spanish; path = Spanish.lproj/Localizable.strings; sourceTree = ""; }; 89559A830BAC338400DBA37E /* smcover.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = smcover.png; sourceTree = ""; }; 895BDA390B8F8F42003CD894 /* Sparkle.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Sparkle.framework; sourceTree = ""; }; + 897753AB1DB3D89D00595411 /* Constants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Constants.h; sourceTree = ""; }; 8985F1580ADD0B5500F9EC46 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = /System/Library/Frameworks/Security.framework; sourceTree = ""; }; 8987FBD00B878B3900A5ED8E /* smc.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = smc.png; sourceTree = ""; }; 89949E8B0AEEA37700077E93 /* Power.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Power.h; sourceTree = ""; }; @@ -149,6 +150,7 @@ 080E96DDFE201D6D7F000001 /* Classes */ = { isa = PBXGroup; children = ( + 897753AB1DB3D89D00595411 /* Constants.h */, 89148EA115E2543D00A073EE /* NSFileManager+DirectoryLocations.m */, 89148EA215E2543D00A073EE /* NSFileManager+DirectoryLocations.h */, 894A465F0ADBD6CF008785F3 /* FanControl.h */, @@ -496,7 +498,7 @@ COPY_PHASE_STRIP = NO; DEVELOPMENT_TEAM = H4G85G26BP; FRAMEWORK_SEARCH_PATHS = ( - ".//**", + ., "$(inherited)", "$(PROJECT_DIR)", ); @@ -575,7 +577,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; MACOSX_DEPLOYMENT_TARGET = 10.7; ONLY_ACTIVE_ARCH = YES; - OTHER_CFLAGS = "-fnested-functions"; + OTHER_CFLAGS = ""; OTHER_LDFLAGS = ""; SDKROOT = macosx; VALID_ARCHS = "i386 x86_64"; @@ -592,7 +594,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; MACOSX_DEPLOYMENT_TARGET = 10.7; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = "-fnested-functions"; + OTHER_CFLAGS = ""; OTHER_LDFLAGS = ""; SDKROOT = macosx; SYMROOT = "~/builds"; diff --git a/smcFanControl.xcodeproj/project.xcworkspace/xcuserdata/hendrikh.xcuserdatad/UserInterfaceState.xcuserstate b/smcFanControl.xcodeproj/project.xcworkspace/xcuserdata/hendrikh.xcuserdatad/UserInterfaceState.xcuserstate index e62635f..bec4dca 100644 Binary files a/smcFanControl.xcodeproj/project.xcworkspace/xcuserdata/hendrikh.xcuserdatad/UserInterfaceState.xcuserstate and b/smcFanControl.xcodeproj/project.xcworkspace/xcuserdata/hendrikh.xcuserdatad/UserInterfaceState.xcuserstate differ