# Distribution and updates

## Code signing and notarization

### Mac (Developer ID and notarization)

If you write the name or SHA-1 of a signing certificate in your keychain in `build.mac.signIdentity` (the environment variable `LIMINALIA_MAC_SIGN_IDENTITY` takes precedence),
the app is signed from the inside out (helper apps, frameworks and native libraries first) with the hardened runtime, entitlements and a timestamp
(@electron/osx-sign). If you don't write it, or write `-`, the app is ad hoc signed as before (enough only for running it on your own Mac).

```json
"build": { "mac": { "signIdentity": "Developer ID Application: Example Inc. (ABCDE12345)", "notaryProfile": "liminalia-notary" } }
```

- If you leave out the entitlements, the export creates the ones Electron needs (JIT and the executable memory it uses). In the Steam-connected version, library validation is also turned off,
  because the app loads the Steam library signed by Valve. To provide your own, write the path of the plist in `build.mac.entitlements`
- Notarization happens if credentials are available (`build.mac.notarize: false` or `LIMINALIA_NOTARIZE=0` signs only). The credentials are one of the following
  - A keychain profile: `build.mac.notaryProfile` or `LIMINALIA_NOTARY_PROFILE` (create it with `xcrun notarytool store-credentials <name>`; recommended)
  - An App Store Connect API key: `LIMINALIA_NOTARY_KEY` (the path of the .p8), `LIMINALIA_NOTARY_KEY_ID`, `LIMINALIA_NOTARY_ISSUER`
  - An Apple ID: `LIMINALIA_NOTARY_APPLE_ID`, `LIMINALIA_NOTARY_PASSWORD` (an app-specific password), `LIMINALIA_NOTARY_TEAM_ID`
- For notarization, the app is zipped and sent with `xcrun notarytool submit --wait`. If it passes, it's stapled with `xcrun stapler staple`, and `spctl` checks that Gatekeeper accepts it.
  If it doesn't pass, the export stops and shows the reason from `notarytool log` (this takes a few minutes)
- Signing and notarization only work on a Mac. If the certificate isn't in the keychain, the export stops before building

### Windows (Authenticode)

In `build.windows.sign`, write either a certificate (PFX) and the environment variable that holds its password, or an external signing command. The executable and the installer
(`build.windows.installer`) are signed.

```json
"build": { "windows": { "sign": { "pfx": "certs/code-signing.pfx", "passwordEnv": "LIMINALIA_WIN_PFX_PASSWORD" } } }
```

- With a PFX, signing uses signtool (Windows SDK) on Windows, and osslsigncode (`brew install osslsigncode`, `apt install osslsigncode`) on Mac and Linux.
  The timestamp (RFC 3161) server is `timestampUrl` (default `http://timestamp.digicert.com`). The password isn't put in command arguments; it's passed in a file that only you can read
- The environment variables `LIMINALIA_WIN_PFX` (the path of the PFX) and `LIMINALIA_WIN_SIGN_COMMAND` take precedence over the settings. The tools' locations can be set with `LIMINALIA_OSSLSIGNCODE` and `LIMINALIA_SIGNTOOL`
- Since 2023, OV and EV certificates keep their keys in hardware (a token or a cloud HSM), so they often can't be passed as a PFX. In that case, use an external signing command.
  `{file}` is replaced with the path of the file to sign. For example, Azure Trusted Signing from a Mac or Linux with [jsign](https://ebourg.github.io/jsign/):
  ```json
  "build": { "windows": { "sign": { "command": ["jsign", "--storetype", "TRUSTEDSIGNING", "--keystore", "weu.codesigning.azure.net", "--alias", "account/profile", "--tsaurl", "http://timestamp.acs.microsoft.com", "{file}"] } } }
  ```
  Pass secrets such as access tokens as jsign's documentation describes. The command runs without a shell, so things like `$VAR` aren't expanded
  (don't write secrets in `liminalia.json`; have the command read them from environment variables or files)
- If a tool (osslsigncode, signtool), the certificate or the password is missing, the export stops before building and shows the reason and how to install what's missing.
  With `ifMissing: "skip"`, it only warns and exports without signing (for trial exports on your own computer, for example)

## Windows installer

If `build.windows.installer` is `true` (or an object with settings), `lim build windows` makes `<name>_<version>_Setup.exe` in addition to the folder and zip
(with NSIS's makensis. If signing is set up, the installer is signed too).

```json
"build": { "windows": { "installer": { "perMachine": false, "desktopShortcut": true, "languages": ["ja", "en"] } } }
```

- The installer's screens are in Japanese and English (chosen by Windows' display language; `languages` narrows the choice). The player can choose where to install, and on the last screen, whether to launch the game and create a desktop shortcut
- It creates a Start menu shortcut and registers the uninstaller in Apps & features. Uninstalling deletes only the installed files
  (anything the player put in the install folder, and save data, are kept). If a previous version is installed, it's removed with that version's uninstaller before installing
- By default it installs for the current user only (`%LOCALAPPDATA%\Programs\<name>`; no administrator rights needed). With `perMachine: true`, it installs for all users (Program Files; administrator rights needed)
- makensis is required: `brew install makensis` on Mac, `apt install nsis` or similar on Linux, and https://nsis.sourceforge.io/Download on Windows.
  You can set its location with `LIMINALIA_MAKENSIS`. If it isn't found, the export stops before building and shows how to install it (with `LIMINALIA_INSTALLER=0`, it exports without making the installer)
- The uninstaller (Uninstall.exe) is created at install time, so it isn't signed

## Icons

If you set `build.icon` to a 1024px PNG, it's used to make the icons of the Mac version (.icns), the Windows version (.ico; or the .ico in `build.winIcon`), the Linux version (the picture of the `.desktop` file),
the browser version (the picture used when it's added to a home screen) and the mobile versions. The template (`lim new`) includes a placeholder icon, `icon.png`.

- If `build.icon` is missing, isn't found, or is still the template's placeholder, exporting a desktop version shows a warning
  (without an icon, the Mac version gets Electron's icon and the Windows and Linux versions get none)
- For builds connected to Steam (`build.steam`), the export stops instead of warning

## Packaging (zip and dmg)

The Windows version gets a folder and a zip by default (`LIMINALIA_ZIP=0` skips the zip). For the Mac and browser versions, a zip and a dmg are made only when you ask for them.

```json
"build": { "mac": { "zip": true, "dmg": true }, "browser": { "zip": true } }
```

```bash
lim build mac,browser --zip --dmg   # make them for this export only (--zip is the zip of the Mac and browser versions, --dmg is the Mac dmg)
```

| Setting | What's made |
|---|---|
| `build.mac.zip` | `<name>.zip` (next to the app). Made with `ditto -c -k --sequesterRsrc --keepParent`, which keeps the symbolic links inside frameworks, execute permissions and signatures (the same form as Compress in the Finder; meant to be opened on a Mac) |
| `build.mac.dmg` | `<name>.dmg` (next to the app). Made with `hdiutil`, containing the app and `Applications`, a link to `/Applications` (open it and drag the app onto the link to install). The volume name is the name of the exported file |
| `build.browser.zip` | `<out>/browser/<id>.zip`. Contains the contents of the exported folder, with `index.html` at the top of the zip (you can upload it as is as an HTML game on itch.io) |

- The order of precedence is `--zip` and `--dmg` on `lim build`, then the environment variables `LIMINALIA_ZIP` and `LIMINALIA_DMG` (`1` or `0`), then `liminalia.json`
- When notarizing, the app is packaged after it's stapled (the dmg itself isn't signed; the app inside is already stapled). The app is packaged as exported, before the launch check
- A dmg can only be made on a Mac (on other OSes, if `build.mac.dmg` is set, the export stops before building)
- The license notices for third-party components are included too. Every export puts `THIRD_PARTY_LICENSES.txt` (for the loading code Vite adds to the build) in the game's content,
  and the browser version has it at the top of the folder and the zip. Desktop versions also put it next to Electron's `LICENSE` and `LICENSES.chromium.html`: inside the app folder for Windows and Linux,
  and next to the app for Mac, where the zip and dmg include them alongside the app. If you repackage the game yourself, include these three
- Before building, `lim build` shows an estimate of the free space the whole export needs (besides copying the assets: Electron, `assets.asar`, the encrypted copy of the assets, and the zip, dmg and installer) along with the free space,
  and stops if there isn't enough (before it runs out partway). Assets on the same disk are cloned and use almost no space, so they aren't counted; the asar, encryption and packaging write the content, so they are.
  If the temporary folder is on another disk, the working space is compared with the free space there
- On Studio's export screen too, these appear under "Package as" when you choose Mac or Browser. Changes are saved to `liminalia.json` right away, and `lim build` uses the same settings

### Size (the engine bundle, language files and the Mac CPU)

- The engine bundle that's exported (`engine/*.js`) doesn't include the command descriptions (summaries, parameter descriptions, examples, search words and their English).
  Studio, VS Code and `lim reference` read them, but the game doesn't. The size of the bundle appears in the export's progress ("Engine and plugins") and in `lim size`.
  In the engine repository, a test (`packages/cli/test/engine-bundle.test.ts`) fails if the template project's bundle goes over 230 KB gzipped
- Electron's language files (`locales/*.pak` on Windows and Linux, `*.lproj` on Mac) are included only for the game's languages (`languages`) and English
  (both Simplified and Traditional for Chinese). Without a file for the OS language, Electron's menus and dialogs are in English.
  To keep other languages, list them in `build.desktop.locales` (`["fr", "ko"]`); `"all"` keeps every language (as before)
- The Mac version is universal by default (one app that runs on both Apple Silicon and Intel). Players can get one download without knowing their Mac's CPU,
  and Intel Macs remain in use through macOS 26, so the default stays. Splitting it by CPU leaves Electron for one CPU only and makes it about half the size
  (for the template game, universal is a 493 MB app and a 222 MB zip; arm64 alone is a 257 MB app and a 118 MB zip).
  Narrow it to one with `build.mac.arch` (`"universal"`, `"arm64"` or `"x64"`) or the environment variable `LIMINALIA_MAC_ARCH` (which takes precedence). To ship both, export each one and make a separate zip for each
- The Windows and Linux versions are x64 by default. Change them with `build.windows.arch` (`"x64"`, `"arm64"` or `"ia32"`) and `build.linux.arch` (`"x64"` or `"arm64"`),
  or with the environment variables `LIMINALIA_WINDOWS_ARCH` and `LIMINALIA_LINUX_ARCH` (which take precedence)
- The environment variable `LIMINALIA_ARCH` applies to every target exported at once, when there's no variable for that target (on Windows and Linux, the Mac's `universal` is the same as not setting it).
  If its value doesn't fit a target, the export stops before building anything (`LIMINALIA_ARCH=ia32 lim build mac,windows` stops at the Mac version; use the per-target variables to set each one)

```json
"build": { "mac": { "arch": "arm64" }, "windows": { "arch": "ia32" }, "linux": { "arch": "arm64" } }
```

```bash
LIMINALIA_MAC_ARCH=arm64 lim build mac --zip   # for Apple Silicon
LIMINALIA_MAC_ARCH=x64 lim build mac --zip     # for Intel
LIMINALIA_MAC_ARCH=arm64 LIMINALIA_WINDOWS_ARCH=ia32 lim build mac,windows   # per target in one export
```

### Linux version

The Linux version gets a folder and `<name>.tar.gz` by default (`LIMINALIA_ZIP=0` skips the tar.gz). The export writes the tar.gz itself, with root (0) as the owner,
and permissions set to 755 for folders and executables and 644 for everything else (it doesn't include your user number and name, and executables keep their permission even when exported on Windows).

| File | What it is |
|---|---|
| `<executable>.sh` | Starts the game. Where Chromium's sandbox can't be used (Ubuntu 24.04 and later restrict user namespaces with AppArmor, and extracting the archive doesn't make `chrome-sandbox` setuid root), it starts the game with `--no-sandbox`. `LIMINALIA_SANDBOX=1` never adds it, and `0` always adds it |
| `<id>.desktop` | The menu entry. So that it opens from the extracted folder, it looks for the launcher next to itself. The launcher rewrites it with absolute paths to the current location (`Exec` and `Icon`) every time it starts, so after starting the game once you can copy it to `~/.local/share/applications/` to add it to the menu |
| `icon.png` | A copy of `build.icon` (PNG). The picture of the `.desktop` file |

- You can also start the executable directly (`build.executableName`, or the project's id if that's not set). Where the sandbox can be used, it works the same
- When distributing on Steam, choose the launcher in the launch options

## Electron fuses in the desktop versions

After building the desktop versions (Mac, Windows and Linux) and before signing, the export changes Electron's fuses (switches burned into the executable).
Plain Electron lets anyone run the game's executable as Node (`ELECTRON_RUN_AS_NODE`), inject code with `NODE_OPTIONS`,
and inspect it with `--inspect` (which can also reveal the encryption key).

| Fuse | Default | What it does |
|---|---|---|
| `RunAsNode` | Off | `ELECTRON_RUN_AS_NODE=1` can't run the game's executable as Node |
| `EnableNodeOptionsEnvironmentVariable` | Off | `NODE_OPTIONS` is ignored |
| `EnableNodeCliInspectArguments` | Off | `--inspect` and similar options are ignored |
| `OnlyLoadAppFromAsar` | On when the app is in an asar | Loads only from `resources/app.asar` (a `resources/app` folder can't replace it) |
| `EnableEmbeddedAsarIntegrityValidation` | On for Mac and Windows when the app is in an asar | The game doesn't start if the file lists of `app.asar` or `assets.asar` were changed |

- For asar integrity, the packager registers `app.asar` (on Mac, `ElectronAsarIntegrity` in Info.plist and a digest inside Electron Framework; on Windows, a resource in the executable),
  and the export adds the assets' `assets.asar`, which it adds later, to the same list, because an app with an asar that isn't in the list doesn't start.
  If it can't be added (an unknown version of Electron, for example), the export shows a warning and exports without the integrity check
- Linux's Electron doesn't check asar integrity, so the Linux version doesn't turn it on
- If `build.asar` is `false` (`LIMINALIA_ASAR=0`), the two asar fuses stay off
- To change them one by one, set names to `true` or `false` in `build.desktop.fuses`. `false` leaves the fuses alone (as before)

```json
"build": { "desktop": { "fuses": { "EnableEmbeddedAsarIntegrityValidation": false } } }
```

You can check what was burned in with `npx @electron/fuses read --app <app>` (the .app on Mac, the .exe on Windows, the executable on Linux).
The authoring app (Liminalia Studio) also ignores `NODE_OPTIONS` (it keeps `RunAsNode`, because AI assistants run its MCP server with the app's executable,
and keeps `--inspect`, which Playwright uses to connect when checking the packaged app).

## The exported page (CSP, title and home screen icons)

The `index.html` of the browser and desktop versions includes a Content Security Policy (`<meta http-equiv="Content-Security-Policy">`).
The game loads only from the same place as the game, and outside scripts and scripts inside HTML parts don't run.

| Directive | Default |
|---|---|
| `script-src` | The engine's files and the script the export writes into `index.html` to install the Service Worker (by the hash of its content) |
| `style-src` | `'self' 'unsafe-inline'` (the engine writes styles directly on elements) |
| `img-src`, `media-src`, `font-src`, `connect-src` | `'self' data: blob:` (save thumbnails, layered sprites and so on). `connect-src` also gets the origins of `build.crashReport.url` and `build.analytics.url`, and of `build.feedback.url` for a test build |
| `object-src`, `frame-src`, `worker-src`, `manifest-src`, `base-uri` | `'self'` (`worker-src` also `blob:`) |
| `form-action` | `'none'` |

When you use plugins that load outside things (outside APIs, embedded videos, WebAssembly and so on), add them per directive with `build.csp`. `false` removes that directive,
and setting `build.csp` to `false` leaves the CSP out (as before).

```json
"build": { "csp": { "connect-src": ["https://api.example.com"], "frame-src": ["https://www.youtube.com"], "script-src": ["'wasm-unsafe-eval'"] } }
```

The page title (`<title>`) is the game's `title`, and the description (`<meta name="description">` and the home screen description) is `description` in `liminalia.json`.
The same title and description go into the Open Graph tags (`og:title` and `og:description`) used when the URL is shared on social media (there's no image, since it needs the absolute URL of where the game is published).
The page language (`<html lang>` and the home screen `lang`) is the original language (the first of `languages`, or `ja` if it isn't set).
The pictures used when the game is added to a home screen are made from `build.icon` (PNG): 192px, 512px, a maskable 512px that isn't cut off when cropped to a circle, and a 180px apple-touch-icon for iPhone.
The page doesn't stop zooming (`user-scalable=no`). The game screen stops double-tap and pinch zooming with CSS (`touch-action`), so controls don't change.
