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.

Simple 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:

Set  to   for your switch.

See AirplaneMode and other switches for reference.

Advanced 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.

Glyphs
Glyphs are the visual part of the switch that should represent your switch's state. To create one, you have to create at least two icons (one for  state and one for   state) as black vector images with transparent background. Then, save those vector images as PDFs in your  folder, where an   file resides. Name them as follows:

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