mNo edit summary |
(How 2 prefs) |
||
Line 5: | Line 5: | ||
If you are looking for notifications within a process, give [https://github.com/uroboro/NotificationExplorer NotificationExplorer] a look. | If you are looking for notifications within a process, give [https://github.com/uroboro/NotificationExplorer NotificationExplorer] a look. | ||
=== Other Stuff | == How 2 prefs == | ||
As opposed to using NSDictionaries and <code>[NSHomeDirectory() stringByAppendingFormat:@"/Library/Preferences/%s.plist", "com.your.tweak"]</code>, here's another alternative to handling preferences on tweaks. Note that I use "com.your.tweak" for both the domain (defaults) and the notification name (PostNotification). | |||
=== Tweak.xm === | |||
<source lang="objc"> | |||
@interface NSUserDefaults (Tweak_Category) | |||
- (id)objectForKey:(NSString *)key inDomain:(NSString *)domain; | |||
- (void)setObject:(id)value forKey:(NSString *)key inDomain:(NSString *)domain; | |||
@end | |||
static NSString const *nsDomainString = @"com.your.tweak"; | |||
static NSString const *nsKey = @"enabled"; | |||
static BOOL enabled; | |||
static void notificationCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) { | |||
NSNumber *n = (NSNumber *)[[NSUserDefaults standardUserDefaults] objectForKey:nsKey inDomain:nsDomainString]; | |||
enabled = (n)? [n boolValue]:YES; | |||
} | |||
%ctor { | |||
NSNumber *n = (NSNumber *)[[NSUserDefaults standardUserDefaults] objectForKey:nsKey inDomain:nsDomainName]; | |||
enabled = (n)? [n boolValue]:YES; | |||
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, notificationCallback, nsDomainName, NULL, CFNotificationSuspensionBehaviorCoalesce); | |||
// Add any personal initializations | |||
} | |||
/* | |||
* From here onward, write your tweak. | |||
* To make your tweak actually do stuff when enabled: | |||
if (!enabled) { | |||
// Do the original algorithm, either by calling: | |||
// %orig(); //if using logos for methods | |||
// _functionName(args); //if using MSHook() for functions | |||
} else { | |||
... | |||
// Optionally, do the original algorithm | |||
} | |||
*/ | |||
</source> | |||
=== Preference plist === | |||
Saved in your tweak's folder as <code>layout/Library/PreferenceLoader/Preferences/com.your.tweak.plist</code>, use any of the following | |||
==== Reduced style ==== | |||
Provides a switch on the root section of the preferences (like Airplane Mode). Recommended for configuration-less tweaks. | |||
<pre>{ | |||
entry = { | |||
cell = PSSwitchCell; | |||
label = "Your Tweak"; | |||
defaults = "com.your.tweak"; | |||
default = 1; | |||
icon = "/Applications/Preferences.app/[email protected]"; | |||
PostNotification = "com.your.tweak"; | |||
}; | |||
} | |||
</pre> | |||
==== Extended Style ==== | |||
Provides a pane where other cells can appear (like Wi-Fi). Recommended for configuration-friendly tweaks. | |||
<pre>{ | |||
title = "Your Tweak"; | |||
entry = { | |||
cell = PSLinkCell; | |||
label = "Your Tweak"; | |||
icon = "/Applications/Preferences.app/[email protected]"; | |||
}; | |||
items = ( | |||
{ | |||
cell = PSSwitchCell; | |||
defaults = "com.your.tweak"; | |||
label = Enabled; | |||
key = enabled; | |||
default = 1; | |||
PostNotification = "com.your.tweak"; | |||
} | |||
// add more cells (dictionaries) here | |||
); | |||
}</pre> | |||
== Other Stuff == | |||
Similar Wanted Pages: | Similar Wanted Pages: |
Revision as of 03:05, 20 June 2014
Find me on saurik's IRC server, on Twitter, on Reddit, on Github.
Made UnlockEvents and FlipNC.
If you are looking for notifications within a process, give NotificationExplorer a look.
How 2 prefs
As opposed to using NSDictionaries and [NSHomeDirectory() stringByAppendingFormat:@"/Library/Preferences/%s.plist", "com.your.tweak"]
, here's another alternative to handling preferences on tweaks. Note that I use "com.your.tweak" for both the domain (defaults) and the notification name (PostNotification).
Tweak.xm
@interface NSUserDefaults (Tweak_Category)
- (id)objectForKey:(NSString *)key inDomain:(NSString *)domain;
- (void)setObject:(id)value forKey:(NSString *)key inDomain:(NSString *)domain;
@end
static NSString const *nsDomainString = @"com.your.tweak";
static NSString const *nsKey = @"enabled";
static BOOL enabled;
static void notificationCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
NSNumber *n = (NSNumber *)[[NSUserDefaults standardUserDefaults] objectForKey:nsKey inDomain:nsDomainString];
enabled = (n)? [n boolValue]:YES;
}
%ctor {
NSNumber *n = (NSNumber *)[[NSUserDefaults standardUserDefaults] objectForKey:nsKey inDomain:nsDomainName];
enabled = (n)? [n boolValue]:YES;
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, notificationCallback, nsDomainName, NULL, CFNotificationSuspensionBehaviorCoalesce);
// Add any personal initializations
}
/*
* From here onward, write your tweak.
* To make your tweak actually do stuff when enabled:
if (!enabled) {
// Do the original algorithm, either by calling:
// %orig(); //if using logos for methods
// _functionName(args); //if using MSHook() for functions
} else {
...
// Optionally, do the original algorithm
}
*/
Preference plist
Saved in your tweak's folder as layout/Library/PreferenceLoader/Preferences/com.your.tweak.plist
, use any of the following
Reduced style
Provides a switch on the root section of the preferences (like Airplane Mode). Recommended for configuration-less tweaks.
{ entry = { cell = PSSwitchCell; label = "Your Tweak"; defaults = "com.your.tweak"; default = 1; icon = "/Applications/Preferences.app/[email protected]"; PostNotification = "com.your.tweak"; }; }
Extended Style
Provides a pane where other cells can appear (like Wi-Fi). Recommended for configuration-friendly tweaks.
{ title = "Your Tweak"; entry = { cell = PSLinkCell; label = "Your Tweak"; icon = "/Applications/Preferences.app/[email protected]"; }; items = ( { cell = PSSwitchCell; defaults = "com.your.tweak"; label = Enabled; key = enabled; default = 1; PostNotification = "com.your.tweak"; } // add more cells (dictionaries) here ); }
Other Stuff
Similar Wanted Pages: