Dev:Flipswitch

libflipswitch is a library used to implement a centralized toggle system. Flipswitch switches (or toggles) can be used as extensions of existing tweaks to provide an interface to enable/disable them.

= How to use this library =

Headers are available from Flipswitch's GitHub project and the library can be found at  on a device where Flipswitch is installed. If using Theos, place the headers in, the library in   and add   to the   Makefile variable.

= How to make a new switch =

To make a switch there are two methods, with or without code. It is recommended to add a glyph so your switch has a visual representation.

Preferred method
Save this NIC template to the  directory and call   to get a premade switch. Once built, it will be installed to.

There will be 2 methods already written in. Here's a sample of a basic switch implementation template:

If  is not implemented, Flipswitch will try to open a URL specified in the "alternate-action-url" key inside the   file

You will find the protocol with the list of methods to implement in  located in your switch folder.

''Note: all of the default implementations of the FSSwitchDataSource methods read data out of the bundle specified by bundleForSwitchIdentifier: (which defaults to the bundle that implements [self class]). You can either override the methods to return your own custom images or image paths or return a bundle and let all of the standard methods do their thing (this includes reading the title from CFBundleDisplayName, detecting if the switch is supported on the device using required-capabilities, and automatically installing an alternate/hold action by reading from alternate-action-url).''

Plist method
This only requires an  added in your switch folder. This plist file should contain the basic keys for describing a bundle plus the following keys:

''Uses FSLazySwitch as NSPrincipalClass when lazy-load set to true. The bundle will not be loaded when querying the title or the list of switches.''

Set  to   for your switch to get the preference switch implementation.

See AirplaneMode and other switches for reference.

Glyphs
Glyphs are the visual part of the switch that should represent your switch's state. You should create black vector images with transparent background and save them as PDFs in your  folder, where an   file resides. Name them as follows:

For common switches, you should make at least two icons, one for  state and one for   state. For button-like switches, glyph.pdf should suffice.

= How to provide preferences =

Simple Approach
Add the following dictionary to your PreferenceLoader plist to make use of the Flipswitch preference bundle:

Extra keys for optimal usage:

= How to make a template bundle =

These bundles contain information about how a switch glyph (the image that the user sees for a given switch) is rendered when it is used in a button returned by the appropriate method of the FlipSwitch panel. Bundles contain an  file and optionally image files. Here is an example of an, taken from SwitchIcons:

Keys not specified in the following table can use the same values as the example given.

array can contain dictionaries with the following keys:

are applied to the button one over the other.

If  is "image", the current layer will draw the image found in. Best use of this layer could be as a background.

If  is "glyph", the current layer will use the switch glyph as a mask. When  is present, the   will select the glyph for said state. If  is true, the layer will be composed of only the glyph's borders.

It is possible to use a  for each state by creating new   arrays named ,   or.

The hex string in  is formatted #RRGGBB.

For more information on existing blend modes and their effects, see Apple's documentation.

= How to show switches =

The following code can be used to retrieve the full list of switches that FlipSwitch knows about:

To show the list of switches that the user set in the settings of your tweak, from your defaults plist in  via creating an NSDictionary, using NSUserDefaults or CFPreferences... family functions, get the object for the key name set for   and use the code above replacing   with the array you just got.

= How to flip switches =

To flip switches programmatically, you can use the shared instance of FSSwitchPanel.

= Usage examples =


 * On-SpringBoard example usage, SwitchIcons
 * Sample code of Toggle for tweak, SleipnizerFlipswitch
 * NC widget using templates, showing switches and PreferenceLoader plist, FlipNC

= External links =


 * Flipswitch source code