<p>Podman Desktop uses when clauses to enable or disable extensions command and UI customizations, such as views.</p>
<p>For example, the Kind extension adds a custom icon to a container that has a label equals to <code>io.x-k8s.kind.cluster</code> by using the following instruction.</p>
<p>A when clause can consist of a context key (such as <code>isLinux</code>) or complex expressions to define a specific state.</p>
<h3class="anchor anchorWithStickyNavbar_JmGV"id="available-context-keys">Available context keys<ahref="#available-context-keys"class="hash-link"aria-label="Direct link to Available context keys"title="Direct link to Available context keys"></a></h3>
<p>Podman Desktop has a set of context keys that are evaluated to Boolean true/false.</p>
<table><thead><tr><th>Context key</th><th>True when</th></tr></thead><tbody><tr><td><strong>Operating system contexts</strong></td><td></td></tr><tr><td>isLinux</td><td>True when the OS is Linux.</td></tr><tr><td>isWindows</td><td>True when the OS is Windows.</td></tr><tr><td>isMac</td><td>True when the OS is macOS.</td></tr></tbody></table>
<p>Podman Desktop also provides context keys that return values that can be used to create meaningful expressions</p>
<table><thead><tr><th>Context key</th><th>Value in it</th></tr></thead><tbody><tr><td>containerLabelKeys</td><td>A list of all labels belonging to the current container. Example: <code>"value in containerLabelKeys"</code></td></tr><tr><td>selectedImageId</td><td>The image id which the dashboard/image menu opened belong to. Example <code>"selectedImageId in imagesPushInProgressToKind"</code></td></tr></tbody></table>
<h3class="anchor anchorWithStickyNavbar_JmGV"id="add-a-custom-when-clause-context">Add a custom when clause context<ahref="#add-a-custom-when-clause-context"class="hash-link"aria-label="Direct link to Add a custom when clause context"title="Direct link to Add a custom when clause context"></a></h3>
<p>If you are creating your own extension and none of the existing keys suit your needs, you can set your own context key by calling the function <code>setValue(key: string, value: any, scope?: 'onboarding')</code> provided by the <code>context</code> namespace in the Podman Desktop API.</p>
<p>The scope, if specified, triggers a custom behavior to avoid any type of collisions between different extensions for that specific scope. Podman Desktop is responsible for handling its state and cleans it accordingly when necessary.</p>
<p>If omitted, the key/value is set globally. For this reason it is recommended to use the extension id as part of the key to avoid unexpected collisions with other extensions.</p>
<p>The first example below sets the key <code>"podmanIsInstalled"</code> to true globally while the second example sets the key <code>"toolInstalled"</code> to <code>oc.exe</code> using the onboarding scope.</p>
<p>After setting the <code>toolInstalled</code> to <code>oc.exe</code>, you could use this information in the <code>when</code> clause to enable something</p>
<h3class="anchor anchorWithStickyNavbar_JmGV"id="conditional-operators">Conditional operators<ahref="#conditional-operators"class="hash-link"aria-label="Direct link to Conditional operators"title="Direct link to Conditional operators"></a></h3>
<p>To create <code>when</code> clauses a bit more complex Podman Desktop offers a set of operators that can be combined with each other.</p>
<h4class="anchor anchorWithStickyNavbar_JmGV"id="logical-operators">Logical operators<ahref="#logical-operators"class="hash-link"aria-label="Direct link to Logical operators"title="Direct link to Logical operators"></a></h4>
<p>Logical operators allow combining simple context keys or when-clause expressions that include other operators</p>
<table><thead><tr><th>Operator</th><th>Symbol</th><th>Example</th></tr></thead><tbody><tr><td>Not</td><td><code>!</code></td><td><code>!podmanIsInstalled</code> or <code>!(podmanIsInstalled && isWindows)</code></td></tr><tr><td>And</td><td><code>&&</code></td><td><code>podmanIsInstalled && isWindows</code></td></tr><tr><td>Or</td><td><code>||</code></td><td><code>isLinux || isWindows</code></td></tr></tbody></table>
<h4class="anchor anchorWithStickyNavbar_JmGV"id="equality-operators">Equality operators<ahref="#equality-operators"class="hash-link"aria-label="Direct link to Equality operators"title="Direct link to Equality operators"></a></h4>
<p>Equality operators allow checking for equality of a context key's value against a specified value.</p>
<p><strong>Note:</strong> the right side is a value and not considered as a context key, so no value is searched in the context. If it contains whitespaces, it must be wrapped in single-quotes (for example <code>'my tool.exe'</code>)</p>
<h4class="anchor anchorWithStickyNavbar_JmGV"id="comparison-operators">Comparison operators<ahref="#comparison-operators"class="hash-link"aria-label="Direct link to Comparison operators"title="Direct link to Comparison operators"></a></h4>
<p>Comparison operator allow comparing a context key's value against a number.</p>
<p><strong>Note:</strong> the left and right side of the operator must be separated by whitespace - <code>bar < 2</code>, but not <code>bar<2</code></p>
<h4class="anchor anchorWithStickyNavbar_JmGV"id="in-and-not-in">In and not in<ahref="#in-and-not-in"class="hash-link"aria-label="Direct link to In and not in"title="Direct link to In and not in"></a></h4>
<p>The <code>in</code>/<code>not in</code> operators allow checking if a value exists/not exists within the other. The right should be a context key, which value is retrieved in the context. The left can be a value or a context key.</p>
<table><thead><tr><th>Operator</th><th>Symbol</th><th>Example</th></tr></thead><tbody><tr><td>In</td><td><code>in</code></td><td><code>label in containerLabelKeys</code></td></tr><tr><td>Not</td><td><code>not in</code></td><td><code>label not in containerLabelKeys</code></td></tr></tbody></table>
<h4class="anchor anchorWithStickyNavbar_JmGV"id="match-operator">Match operator<ahref="#match-operator"class="hash-link"aria-label="Direct link to Match operator"title="Direct link to Match operator"></a></h4>
<p>The match operator allow treating the right side item as a regular expression literal to match against the left side.</p>