An open API service indexing awesome lists of open source software.

https://github.com/nightwinddev/preference-bundle-example

Some information about preference bundles and the different cells in there.
https://github.com/nightwinddev/preference-bundle-example

Last synced: 10 months ago
JSON representation

Some information about preference bundles and the different cells in there.

Awesome Lists containing this project

README

          

# Preference Bundle Example

## Universal Keys

**PostNotification** - adds a way for the tweak to communicate with the preference bundle
```xml
PostNotification
com.nightwind.prefbundleexampleprefs-updated
```

**height** - determines the height of the cell
```xml
height
66
```

**id** - gives a unique identifier to the cell
```xml
id
testCellId
```

**key** - unique identifier to the cell, which can later be used when linking the cells to the main tweak file.
```xml
key
testCellKey
```


## PSButtonCell

This is a cell that - when pressed, does a certain action. This action can be specified in your `XXXRootListController.m` file.

Root.plist:

```xml

action
killPhoneApp
cell
PSButtonCell
label
Kill Phone App
defaults
com.nightwind.prefbundleexampleprefs

```

XXXRootListController.m:

```logos
- (void)killPhoneApp {
pid_t pid;
const char* args[] = {"killall", "MobilePhone", NULL};
posix_spawn(&pid, ROOT_PATH("/usr/bin/killall"), NULL, NULL, (char* const*)args, NULL);
}
```

## PSEditTextCell

This is a cell where text can be inputted and then later used in your tweak somewhere.

Root.plist:

```xml

cell
PSEditTextCell
defaults
com.nightwind.prefbundleexampleprefs
label
Text:
default
default text

```

## PSSecureEditTextCell

This is a cell where text can be inputted, secured in a password-style manner, and then later used in your tweak somewhere.

Root.plist:

```xml

cell
PSSecureEditTextCell
defaults
com.nightwind.prefbundleexampleprefs
label
Text:
default
default text

```

(The screenshot does not pick it up, but there are dots where the normal text characters of the text field should be).

## PSEditTextViewCell

This cell is like `PSEditTextCell`, in the way that it is also an area for text input. Unlike `PSEditTextCell`, this cell expands the text input area to fit the whole cell.

`Root.plist`:

```xml

cell
PSEditTextViewCell
defaults
com.nightwind.prefbundleexampleprefs
default
default text

```

## PSGiantCell

This is a cell that is larger than normal cells. This cell can take an action assigned to it, just like `PSButtonCell`.

`Root.plist`:

```xml

cell
PSGiantCell
label
Test
action
respring

```

`XXXRootListController.m`:

```logos
- (void)respring {
pid_t pid;
const char* args[] = {"killall", "SpringBoard", NULL};
posix_spawn(&pid, ROOT_PATH("/usr/bin/killall"), NULL, NULL, (char* const*)args, NULL);
}
```

## PSGiantIconCell

This cell is similar to `PSGiantCell` in the terms of size, however it has an option to put an icon into it.
Your icon should be placed in your `Resources` folder and should be named accordingly to your plist. This cell also allows for an action, just like the `PSGiantCell` mentioned above.

Root.plist:

```xml

cell
PSGiantIconCell
label
Test
icon
testicon.png
action
killSettingsApp

```

XXXRootListController.m:

```logos
- (void)killSettingsApp {
pid_t pid;
const char* args[] = {"killall", "Preferences", NULL};
posix_spawn(&pid, ROOT_PATH("/usr/bin/killall"), NULL, NULL, (char* const*)args, NULL);
}
```

In this case, the icon is named `testicon.png`, so the image in your `Resources` folder should be named `testicon.png` as well. If you want to look at the icon in Filza on device, you can find it in `/var/jb/Library/PreferenceBundles/YourBundleName.bundle/` on rootless and `/Library/PreferenceBundles/YourBundleName.bundle` on non-rootless ("rootful").

## PSGroupCell

`PSGroupCell` is a really useful cell that allows for seperation of large clusters of cells.

Root.plist:

```xml

cell
PSGroupCell
label
PSGroupCell Test

```

(Pictured here: two `PSGiantIconCell`s, which are the ones with the icons, and `PSGroupCell`s above them).

## PSLinkCell

This cell is used to link to a different view controller. For example in this code snippet, the cell leads to `PSUIPrefsListController` which is the main Settings app page.

Root.plist:

```xml

cell
PSLinkCell
detail
PSUIPrefsListController
icon
icon.png
isController

label
test label

```

## PSLinkListCell

This cell is used to link to a predefined view controller, which has the cells inside of it defined here.

Root.plist:

```xml

cell
PSLinkListCell
detail
PSListItemsController
label
Test 1
validTitles

List Test 1
List Test 2

validValues

0
1

```

## PSSegmentCell

This is a segmented cell, which can have multiple values inputted into it.

Root.plist:

```xml

cell
PSSegmentCell
default
0
label
Test
validTitles

test 1
test 2
test 3

validValues

0
1
2

```

## PSSliderCell

This is a cell which contains a slider. The slider can be dragged and have multiple output values based on where the knob is located.

Root.plist:

```xml

cell
PSSliderCell
default
66
min
0
max
50

```

## PSSpinnerCell

This cell is a cell which has a spinner inside of it. This cell is meant to be inserted before an actual cell is loaded and then deleted.

Root.plist:

```xml

cell
PSSpinnerCell
label
Test

```

## PSStaticTextCell

This is a cell which just has text.

Root.plist:

```xml

cell
PSStaticTextCell
label
Test

```

## PSSwitchCell

This is a cell which has a switch in it, and the value of the switch can be used in the tweak.

Root.plist:

```xml

cell
PSSwitchCell
default

label
Test

```


# Linking Cells to Tweak

The code below shoould be put above `%hook`s and, if present, `%group`s as well.

```logos
static BOOL testSwitchKey; // PSSwitchCell
static NSInteger testSegmentkey; // PSSegmentCell
static NSInteger testSliderKey; // PSSliderCell
static NSString *testEditTextKey; // PSEditTextCell or PSSecureEditTextCell
```

The code below should be put in the main `Tweak.x`/`Tweak.xm` file.

```logos
static void preferencesChanged() {
NSUserDefaults *const prefs = [[NSUserDefaults alloc] initWithSuiteName:@"com.nightwind.prefbundleexampleprefs"];

testSwitchKey = [prefs objectForKey:@"testSwitchKey"] ? [prefs boolForKey:@"testSwitchKey"] : YES; // PSSwitchCell
testSegmentKey = [prefs objectForKey:@"testSegmentKey"] ? [prefs integerForKey:@"testSegmentKey"] : 0; // PSSegmentCell
testSliderKey = [prefs objectForKey:@"testSliderKey"] ? [prefs floatForKey:@"testSliderKey"] : 30.0f; // PSSliderCell
testEditTextKey = [prefs objectForKey:@"testEditTextKey"] ? [prefs stringForKey:@"testEditTextKey"] : @""; // PSEditTextCell or PSSecureEditTextCell
}

%ctor {
preferencesChanged();

CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)preferencesChanged, CFSTR("com.nightwind.prefbundleexampleprefs-updated"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
}
```

The key in the `Tweak.x`/`Tweak.xm` file should of course correspond to the key in the `.plist` file.

So for example say there's a enable tweak switch in the preference bundle, which looks like this:

```xml

cell
PSSwitchCell
default

label
Enable tweak
key
tweakEnabled
PostNotification
com.nightwind.prefbundleexampleprefs-updated

```

In the `Tweak.x`/`Tweak.xm` file, there should be this at the top:

```logos
static BOOL tweakEnabled;
```

...and this at the bottom:

```logos
tweakEnabled = [prefs objectForKey:@"tweakEnabled"] ? [prefs boolForKey:@"tweakEnabled"] : YES;
```

**Note:** If the default in the switch in the preference bundle is true, then the default should be `YES` in the `Tweak.x`/`Tweak.xm` file as well. If the default is set to false, then the default in the `Tweak.x`/`Tweak.xm` file should be `NO`.

`Root.plist`:

```xml
default

```

`Tweak.x`:

```logos
tweakEnabled = [prefs objectForKey:@"tweakEnabled"] ? [prefs boolForKey:@"tweakEnabled"] : YES;
```
*It says `YES` at the very end so that corresponds to the `.plist` file.*

# Further Information
https://theapplewiki.com/wiki/Dev:Preferences_specifier_plist