ThemeStore Store Docs FAQ
Documentation

Variables of your own

globalVariables as constants, as computed values, and as the state a tap writes, and which of the three a name is.

On this page

globalVariables is one map at the top of a theme, and it does three different jobs. Knowing which one a given entry is doing is the difference between a theme that stays editable and one that has the same number written into eleven fields.

json
"globalVariables": {
  "accent":     "#FF7A5CFF",
  "clock_size": "$is_landscape ? 48 : 72$",
  "feed_filter": ""
}

A constant#

A plain value is a name for a number, a colour or a word. Every field that reads $accent$ changes when the one entry changes.

This is worth doing far earlier than it feels necessary. A colour used in four elements is already four places to miss one.

A computed value#

If the value itself contains a formula, it becomes one. clock_size above is not the text $is_landscape ? 48 : 72$, and it is evaluated wherever it is read.

That is the mechanism that keeps a layout coherent. The default theme's clock size appears in six fields: the font size, the clock's height, the gap to the date, the height of the block, and twice in the height of the app grid underneath it. Written out, changing the clock means finding all six and dragging the rest back into place. As a computed variable the number exists once and everything else points at it:

json
"clock_size":  "$is_landscape ? 48 : 72$",
"clock_block": "$clock_size + 34$"

Computed variables may read other computed variables, up to six levels deep. Deeper than that (or a cycle, where a reads b and b reads a) stops and yields nothing, rather than locking up mid-frame.

State a tap writes#

The third job is state. A set_variable action writes a name, and every formula reading it re-evaluates:

json
"clickActions": "[{\"trigger\":\"tap\",\"action\":\"set_variable\",\"value\":\"feed_filter=news\"}]"

Declare the starting value in globalVariables, "" above, so the theme behaves the same on its first run as on its hundredth.

The rule that connects the three#

A value written at runtime is always text, and is never evaluated as a formula.

Only what stands in the theme's own globalVariables can become a computed value. Whatever a set_variable action or an input_field writes stays literal, whatever it looks like.

This is not a technicality. Someone typing buy $5 or $10 into a search box has not written a template, and a launcher that evaluated it would be running text from outside the theme as code. Origin decides, not spelling.

The two share one namespace, and a runtime value shadows a computed one of the same name. That is occasionally useful (a computed default that a tap can override) and otherwise a good way to confuse yourself. Give state variables names that read like state: feed_filter, panel_open, letter.

How long a value lives#

A runtime value lives as long as the launcher process. It is not saved: after a reboot, after the launcher is killed for memory, or after switching themes, every variable is back to what globalVariables declares.

So a theme cannot use variables to remember anything across sessions: no counters, no "seen this already", no preferences of its own. A theme is a document, not an app with storage. Where something must persist, it belongs to the launcher's own settings, not to a theme.

Two fields exist for the small, deliberate cases of forgetting: clearOnLeave on a text field, and clearVariableOnLaunch on a list, which resets a letter filter after an app is opened.

Naming#

Names share one namespace with the built-in variables. Nothing stops you from declaring time_hour, and nothing good comes of it either. Beyond the confusion, a name starting with time_, tilt_, page_position or scrub_ makes the launcher treat your element as one that needs re-evaluating every frame. See performance.

A short prefix of your own, such as my_accent or feed_filter, avoids both problems.

Documentation for launcher 0.1.0-alpha Android 12 and later last updated