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

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.

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. Bundles go in /Library/Switches. 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
''Explain using FSSwitchPanel and -button... method''

How to use the Preference Bundle
Add the following dictionary to your PreferenceLoader plist to make use of the Flipswitch preference bundle:

Extra keys for optimal usage: