A desktop release is an app players download and open like any other program, with your game inside. The starter game can be packaged two ways: with Electron or with Electrobun. Both show the game’s name as the window’s title, offer window sizes on the settings screen and can keep saves as files. Electron also asks “Do you want to quit?” when the player closes the window; Electrobun can’t (see What’s different in Electrobun). Electron apps are larger, because each one carries its own browser engine; Electrobun apps use the one the system already has.

IMPORTANT

Desktop apps need a computer running Windows, macOS or Linux, with Bun installed, and a terminal. A desktop app carries a browser engine along with your game, and the tools that put the two together run on your computer. If you only have a phone or tablet, release your game on the web instead: players on computers can play it there too.

What you need

  • A computer with Windows, macOS or Linux.
  • Bun, a program that runs JavaScript tools on your computer. Install it from bun.sh. If you already have Node.js, npm run runs the Electron commands on this page too; Electrobun always needs Bun.
  • A terminal: the window where you type commands. It’s called Terminal on macOS and on most Linux desktops, and PowerShell or Terminal on Windows. Each command on this page runs in your game folder: in the terminal, go there first with cd followed by the folder’s path.
  • An internet connection and about 600 MB of disk space the first time, for the tools below.
  • The right system for each package. Linux apps build on Linux. Windows installers build on Windows, or on Linux with Wine installed. macOS apps build on a Mac (see macOS).

Set up once

In a terminal, in your game folder:

bun install

This downloads Electron, electron-builder and Electrobun into a node_modules/ folder in your game folder. Electron downloads its own browser the first time you start it or build with it (“Downloading Electron binary…”), and Electrobun downloads its parts the first time you build with it.

NOTE

A game started before Monogatari 2.9.0 has an older package.json. Its commands call Yarn (yarn electron-builder -l), which bun run replaces with Bun but npm run doesn’t; its Linux build stops with “Could not extract a PNG frame from ICNS file”; and it lists Electrobun under dependencies, which puts all of Electrobun inside the Electron app. Compare it with the package.json of the current starter game and copy its scripts, its build.linux.icon line and its devDependencies.

Before you build a release

The desktop apps pack your index.html as it is, including the debug module (engine/debug/debug.js), which shows error dialogs meant for you. Before you build a release for players:

  1. Delete the debug module’s lines from index.html:

    <!-- Debug Library. Remove this file for release builds -->
    <script src="./engine/debug/debug.js"></script>
  2. Set the debug level to 0 in js/main.js:

    monogatari.debug.level(0);

    Without the debug module, Monogatari already writes no step-by-step messages to the console; at 0 it doesn’t write its errors and warnings either.

  3. Build with one of the commands below.

  4. Put both back when you return to writing your game.

Electron

Try your game in the Electron window

bun run start

This opens your game folder in an Electron window, the same way the packaged app shows it: 960×540 at first, never smaller than 640×360, with no menu bar, and with the 'Name' setting from js/options.js as its title.

Build the app

bun run build:windows   # Windows installer
bun run build:mac       # macOS app, as a ZIP (on a Mac)
bun run build:linux     # Linux AppImage

The packages land in build/electron/, named after productName and version in package.json. For the starter:

Command Package
build:windows My Game Setup 0.1.0.exe, an installer.
build:mac The app in a ZIP.
build:linux My Game-0.1.0.AppImage, an app that runs without installing.

bun run build asks for all three in one go. Its macOS part needs a Mac, so on Windows or Linux use the separate commands. For this page, build:linux and build:windows (with Wine) were run on Linux, and the Linux app was started.

Name, version and icons

In package.json:

  • productName is the app’s name, and version its version.
  • build.appId is a unique id for the app, written as a reversed domain (com.studio.game).
  • desktopName is the name of the app’s .desktop file on Linux, which the desktop uses to show the running game with its launcher and icon: my-game.desktop in the starter. Give it your game’s name in lowercase, with dashes instead of spaces, followed by .desktop. build.linux.syncDesktopName, on in the starter, makes the package use that name.
  • build.linux.synopsis and build.linux.description describe the app on Linux.
  • The icons are assets/icons/icon.ico (Windows), assets/icons/icon.icns (macOS) and assets/icons/512x512.png (Linux). Replace those files with your own at the same sizes.

What goes into the package

Every file of your game folder, except build/ and the tools listed under devDependencies in package.json (all of the starter’s tools are there). That includes a few files players don’t need (types/, serve.ts, the source maps). For the starter, the game’s files in the Linux app take about 10 MB.

What players see

  • Closing the window shows the game’s own question, “Do you want to quit?”, with Quit and Cancel. On the title screen, Quit closes the app. During a game, Quit ends the game and goes back to the title screen; closing the window again from there closes the app.
  • Links to websites (<a href="https://…">, with or without target="_blank") and window.open('https://…') open the address in the player’s browser, and the game stays as it was.

The Electron window with the question "Do you want to quit?" and the Quit and Cancel buttons over the dimmed main menu
What players see when they close the Electron window.

Window size

What the player can do with the window depends on the 'ForceAspectRatio' setting in js/options.js:

  • 'None' or 'Visuals' (the starter uses 'None'): the player resizes the window freely. The settings screen shows no window size.
  • 'Global': the player can’t drag the window’s edges, and the settings screen has a Resolution list with window sizes in the shape of the 'AspectRatio' setting (16:9 in the starter), from 640×360 up to the size of the screen, plus Full Screen. The player’s choice is kept as the Resolution preference, which also sets the size the window takes when the game starts: '1280x720' in the starter. A Resolution that isn’t in the list, such as '800x600' for a 16:9 game, opens the window at the largest size in the list that fits inside it (768×432).

macOS

macOS only opens apps from outside its App Store without a warning when Apple has notarized them. That takes a Mac, an Apple Developer membership (a yearly fee) and the signing certificate that comes with it.

When electron-builder builds the macOS app, the starter’s engine/electron/notarize.js sends it to Apple. It reads three values from environment variables, or from a .env file next to package.json:

Variable What it is
APPLEID The Apple ID of your Apple Developer account.
APPLEIDPASS An app-specific password for that Apple ID.
APPLETEAM Your team ID, on the Membership page of your Apple Developer account.

A .env file holds one per line:

APPLEID=you@example.com
APPLEIDPASS=abcd-efgh-ijkl-mnop
APPLETEAM=ABCDE12345

Keep that file to yourself: don’t upload it with your game or share it. Without any of the three, the app is built without being notarized, and the build says so. With only some of them, the build stops and names the missing ones. Builds for Windows and Linux skip notarizing.

WARNING

Not tried on a Mac for this page. On Linux, the values were checked against the checks @electron/notarize makes before it contacts Apple, and they pass; build:mac itself stops with spawn codesign ENOENT, because signing needs a Mac.

Electrobun

Try your game in the Electrobun window

bun run start:electrobun

This builds a development version of the app (build/electrobun/dev-linux-x64/MyGame-dev/ on Linux) and opens it, with your game in a 960×540 window. Don’t give that one to players.

Build the app

bun run build:electrobun

This builds the version you give players (Electrobun’s stable build) for the system you run it on, and puts what you give players in build/electrobun/artifacts/. On Linux:

File What it is
stable-linux-x64-MyGame-Setup.tar.gz The installer (about 34 MB for the starter).
stable-linux-x64-MyGame.tar.zst The app itself, compressed.
stable-linux-x64-update.json The version and a fingerprint of the app, for Electrobun’s updater.

The names come from app.name in electrobun.config.ts, without spaces. The stable package was built on Linux for this page but not installed.

Name, identifier and version

In electrobun.config.ts:

  • app.name is the name players see.
  • app.identifier is a unique id for the game, written as a reversed domain (com.studio.game).
  • app.version is the app’s version.

What goes into the package

Only what the copy block of electrobun.config.ts lists: index.html, engine/core, engine/debug, assets, js and style. If your game loads files from a folder of its own, add a line for it:

'data': 'views/mainview/data',

What’s different in Electrobun

The Electrobun app talks to its window the way the Electron app does: the window takes its title from the 'Name' setting, the settings screen lists window sizes with 'ForceAspectRatio': 'Global', links to websites open in the player’s browser, and the FileSystem storage works. The script that connects the game to the window is engine/electrobun/view.ts, which the window runs before your game’s scripts. Two things differ:

  • Closing the window closes the app at once, without the “Do you want to quit?” question. Electrobun tells the app about a closed window only once it’s gone, so nothing can stop it.
  • With 'ForceAspectRatio': 'Global', the player can still drag the window’s edges. Electrobun has no way to lock a window’s size; the settings screen still offers the sizes in your game’s shape.

If these matter to your game, use Electron.

Linux system libraries

The Electrobun app shows the game with the system’s own WebKitGTK, so on Linux it needs these libraries, on your computer and on your players’: libwebkit2gtk-4.1, libjavascriptcoregtk-4.1 and libayatana-appindicator3. On Arch Linux they come in the webkit2gtk-4.1 and libayatana-appindicator packages; other distributions name their packages differently.

Where desktop apps keep saves

With the IndexedDB adapter the starter uses, both apps keep saves the way a browser does, in the app’s own storage on the player’s computer.

With the Storage setting’s 'Adapter' at 'FileSystem' (see Storage Engines), they keep each save and the player’s preferences as a file instead, in a Storage folder inside the app’s data folder. The files are plain text (JSON), one per save, so a player can back them up or move them to another computer.

App Data folder
Electron Named after productName: ~/.config/My Game/ on Linux, %APPDATA%\My Game\ on Windows, ~/Library/Application Support/My Game/ on macOS.
Electrobun Named after app.identifier in electrobun.config.ts, then stable (or dev for start:electrobun): ~/.local/share/com.example.mygame/stable/ on Linux, %LOCALAPPDATA%\com.example.mygame\stable\ on Windows, ~/Library/Application Support/com.example.mygame/stable/ on macOS.

Inside it, the files are in Storage/, then a folder named after your Name setting (my-visual-novel), then one for the Store (GameData): a save is Save_1795905110677.json, and the preferences are Settings.json. Renaming productName or app.identifier after release points the app at a new, empty folder, without the player’s saves.

Only the Linux paths were checked for this page, with both apps; the Windows and macOS paths are where Electron and Electrobun put an app’s data on those systems.