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 you should: implement the code, set a secondary action (optional) and create a glyph.

Implementing the Code
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. The first one will return the current state of the switch. Here's an example:

Where  returns a BOOL.

The second method will set a new state for the switch. Here's another example:

Aditionally, you can add this method so your switch has a proper title instead of its bundle ID:

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

Secondary action
In the file  you can find the key "alternate-action-url", which will enable you to open a URI when the secondary action of the switch is invoked, in case   is not implemented. The default value is "prefs:".

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 PDF and name them  for the   state and   for the   state. You should then move these PDFs to your  folder, where an   file resides.

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.

For more information, see this resource

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

Explain how to retrieve the switches from the settings bundle (start from here maybe?)