Mirmire guides

Make plugins

On this page

Make plugins

A plugin is a small web page that Mirmire runs. There are two kinds:

Plugins are ZIP files you import like a theme or an icon pack, so you can share them with anyone.

Widget plugins also run in Mirmire Dashboard, Mirmire’s Home page as an app of its own, without the games: see Plugins in Mirmire Dashboard.

The easiest way to make one is the Plugin mode of Theme Studio. Pick a template, edit the code, and see it live on a copy of the Home page (or, for a Big Picture, full screen with your keyboard as the controller), with sample games and achievements. Then press Download ZIP.

What’s in a plugin

my-plugin.zip
├── plugin.json     what it is, its sizes and its permissions
├── index.html      the widget (or the Big Picture) itself
└── ...             any images, fonts, scripts or styles it uses

Put plugin.json at the top of the ZIP. A ZIP holding one folder with plugin.json inside works too.

plugin.json

{
  "id": "pixel-pet",
  "name": "Pixel Pal",
  "author": "Your name",
  "version": 1,
  "description": "A little pixel creature that lives on your home page.",
  "entry": "index.html",
  "sizes": ["small", "wide", "medium"],
  "defaultSize": "wide",
  "permissions": []
}
Field Meaning
id A unique name of lowercase letters, numbers and dashes. Importing a plugin with the same id replaces the old one.
name Shown in the widget list.
author, description Shown when someone installs it.
version A whole number. Raise it when you share an update, so Mirmire offers it to players who installed the plugin from the catalog.
entry The page to open. Usually index.html.
sizes The sizes your widget can be: small (1×1), wide (2×1), medium (2×2), large (4×2), and tall (2 wide) and full (4 wide), which take every row of their page. See Tall and Full.
defaultSize The size it starts at. One of sizes.
permissions What else it may do: internet, library, achievements, ai and system. Leave it empty if it needs none.
sounds, music Optional, for a Big Picture: menu sounds and background music of its own. See Sounds and music.
kind Optional. "widget" (the default) or "bigpicture" for a Big Picture. A Big Picture has no sizes or defaultSize, and needs "api": 4.
category Optional, for a widget: what it’s about in a word or two, such as "Emulators", "Play stats", "Clock and weather" or "Device". Settings › Plugins lists plugins under these headings; use one that’s already there if it fits. Without it, a widget is under Other widgets. A Big Picture is always under Big Picture.
edgeToEdge Optional, for a Big Picture. true draws your page under a phone’s camera cutout and the system bars too, so its background reaches every edge. See Phones: the camera cutout and touch.
icon Optional. A square picture of the plugin, shown beside its name in Settings › Plugins: a PNG, JPEG or WebP in the ZIP, 192×192 pixels is plenty.
sites Optional. Websites the plugin may open full screen inside Mirmire with mirmire.openSite(), as host names: ["example.com"]. Needs the internet permission, and players see each one before they install.
api Optional. The window.mirmire version the plugin needs. Leave it out unless you use something new: mirmire.openSite() needs 2; a Big Picture, mirmire.games.art(), get(), play() and mirmire.systems need 4; mirmire.system needs 5; mirmire.http() and mirmire.servers need 6; mirmire.socket() and selfSigned need 7; mirmire.games.video() and the "spine" and "back" artwork need 8. An older Mirmire then says the plugin needs a newer one.
settings Optional. A page for the widget’s own options, such as choosing a pet. Players open it from Widget options in the widget’s edit menu.

Tall and Full

The Home page is cut into pages of widgets, each as many rows tall as fit the screen: two on a short screen, three or more on a taller one. small to large are one or two rows. tall and full take every row their page has, so they fill it from top to bottom whatever the screen. On a two-row page they are exactly as tall as medium and large.

mirmire.rows says how many rows your widget got. Lay it out for any number from two up: let a list or a graph take the room (flex: 1), and show more of it when there’s more.

The quickest way to add both to a widget that already has medium and large is to draw them as those two, with the extra rows to fill. Every widget in the catalog starts with the same few lines, first thing in its <body>:

<script>
(function () {
  var real = mirmire.size, rows = mirmire.rows || 2;
  if (real !== "tall" && real !== "full") return;
  mirmire.realSize = real;
  mirmire.size = real === "tall" ? "medium" : "large";
  document.documentElement.classList.add(real);
  // Lengths written against the height (vh) stay what they are at the usual two rows.
  if (rows > 2) document.querySelectorAll("style").forEach(function (s) {
    s.textContent = s.textContent.replace(/(\d*\.?\d+)vh\b/g, function (m, n) { return +(n * 2 / rows).toFixed(3) + "vh"; });
  });
})();
</script>

After it, the rest of your page sees medium or large, html.tall and html.full are there for your CSS, and mirmire.realSize keeps the size the player chose. An older Mirmire doesn’t know the two names and leaves them out of the sizes it offers, so listing them needs no api.

Permissions

Players see a plugin’s permissions before they install it, so ask only for what you use.

Permission Allows
(none) Drawing itself, reacting to being selected, and keeping up to 64 KB of its own data.
internet Loading images and data from the web. Without it, every request outside the plugin’s own files is blocked. With it, web requests go through Mirmire: they’re cached, so what the plugin loaded once also works offline, and any site can be read with fetch(), whatever its CORS settings. From API 6, mirmire.http() also sends POSTs, headers and logins to servers such as a RomM or Jellyfin on the player’s own network. See Servers and web services.
library mirmire.games.recent(), all(), get(id), open(id) and play(id), each game’s artwork with mirmire.games.art(), and the consoles with mirmire.systems. A Big Picture can also mark favorites.
achievements mirmire.achievements(): RetroAchievements points, rank, this week’s unlocks and the streak.
ai mirmire.ai: short lines from an AI model the player sets up, about a game or their collection. See AI.
romm mirmire.servers: the RomM libraries the player added in Settings › Library, read-only. Mirmire signs each request in; the plugin never sees the password or token. See Servers Mirmire is connected to.
homeassistant mirmire.servers: the Home Assistant the player connected in Settings › Home Assistant, to read states and run actions. The plugin never sees the token.
system mirmire.system.stats(): how busy the device is (processor, graphics, memory, storage, temperature and battery), and mirmire.system.tools() to open Settings › Tools. See The device.

The window.mirmire API

Mirmire adds window.mirmire before your own scripts run.

mirmire.version        // 8
mirmire.size           // "small", "wide", "medium", "large", "tall" or "full"; "settings" on the options page; "bigpicture" for a Big Picture
mirmire.rows           // the rows of the board the widget takes: 1, 2, or every row of its page for "tall" and "full"
mirmire.host           // "mirmire", or "dashboard" in Mirmire Dashboard (see Plugins in Mirmire Dashboard)
mirmire.theme          // { dark: true, colors: { primary: "#F5B54A", surface: "#1C1B22", ... } }

mirmire.storage.get("key")          // a string, or null
mirmire.storage.set("key", "value") // pass null to remove it

// With the "library" permission:
mirmire.games.recent(5)  // the last games played, newest first
mirmire.games.playing()  // the game being played right now (launched from Mirmire), or null; on a handheld's second
                         // screen your widget stays visible while it runs
mirmire.games.all()      // every visible game (up to 5,000)
mirmire.games.open(id)   // opens that game's page
mirmire.games.get(id)    // one game with its details (see below), or null
mirmire.games.play(id)   // starts the game, as pressing A on it does; one that isn't on the device opens its page instead
mirmire.games.art(id, "box", 300)
                         // an address for the game's artwork, to use as an <img> src or a CSS background. Kinds: "box",
                         // "box3d", "screenshot", "title", "mix", "cart", "fanart" and "marquee" (its logo). The last
                         // argument is the largest side in pixels (48 to 1920; 480 when left out). Mirmire answers it
                         // from wherever the artwork is kept, so it needs no "internet" permission. Each kind but
                         // "marquee" falls back to another picture of the game; a game with none answers 404
                         // From API 8 also "spine" and "back": scans of the box's spine and back. Like "marquee" they have no
                         // stand-in, so most games answer 404; draw your own when the picture fails to load
mirmire.games.video(id)  // an address for the game's video, to use as a <video> src (API 8). See below
mirmire.systems.all()    // consoles that have games: [{ id: "snes", name: "Super Nintendo", games: 42, onDevice: 7 }]
mirmire.systems.icon("snes", 300)   // an address for the console's icon, from the player's theme or icon pack

mirmire.bubble("Hi!", { ms: 3000, ai: false, x: 0.5 })
                       // a speech bubble Mirmire draws just above the widget, so it isn't cut off at the edges;
                       // x is where it points (0 = left, 1 = right), ai: true adds an "AI" tag
mirmire.openSettings() // opens the plugin's options page (needs "settings" in plugin.json)
mirmire.openPage("chat.html") // opens another of the plugin's own pages full screen, like its options page
mirmire.openSite("https://example.com/") // opens a website full screen inside Mirmire. Only https addresses on the hosts
                       // in "sites" (and their subdomains). The site is an ordinary web page: it gets no window.mirmire and
                       // none of your plugin's data. Links to other sites, and downloads, open in the device's browser.
mirmire.http(url, o)   // with "internet": any web request, made by Mirmire. See Servers and web services
mirmire.socket(url, o) // with "internet": a web socket, opened by Mirmire (API 7). See Web sockets
mirmire.servers.list("romm")                    // with "romm" or "homeassistant": servers Mirmire is connected to
mirmire.servers.request(id, "/api/stats", o)    // a request to one of them, signed in by Mirmire
mirmire.close()        // on the options page: closes it

// With the "achievements" permission:
mirmire.achievements()   // { user, points, rank, weekUnlocks, weekPoints, streakDays, mastered, beaten } or null

A game looks like this:

{ "id": 42, "title": "Concentration Room", "system": "nes", "systemName": "Nintendo Entertainment System",
  "cover": "https://...", "favorite": false, "lastPlayed": 1731580000000, "playTimeMinutes": 95, "onDevice": true }

cover is a web address; showing it needs the internet permission too. mirmire.games.art(id) doesn’t, and also works for artwork kept on the player’s own storage, so prefer it.

From API 4, games in a list also have added (when the game joined the library), genre, rating (out of 5, to one decimal; 0 when unknown), year (the year it came out, 0 when unknown; from Mirmire 1.3.5, so check for it and fall back to released from games.get()) and status ("want_to_play", "playing", "completed", or empty). mirmire.games.get(id) adds what’s too long for a list: description, developer, publisher, released, players, playCount, and achievements and achievementsEarned (RetroAchievements).

From API 8, a game also says whether it has a video ("video": true), and mirmire.games.video(id) is its address. Like artwork, Mirmire answers it from wherever the video is kept (the web, the device’s storage or a NAS), so it needs no internet permission. A plugin that also runs on an older Mirmire checks that mirmire.games.video is there before using it.

<video muted loop autoplay playsinline></video>
<script>if (game.video && mirmire.games.video) document.querySelector("video").src = mirmire.games.video(game.id);</script>

The device

With the system permission (and "api": 5), a plugin can read how busy the device is, for a performance monitor.

mirmire.system.stats()
// { cpu:     { usage: 37, speed: 54, cores: [{ mhz: 1400, maxMhz: 2800 }, ...] },
//   gpu:     { usage: 21 },
//   ram:     { used: 5300, total: 7600 },      megabytes
//   disk:    { used: 201000, total: 238000 },  megabytes, the device's own storage
//   temp:    { cpu: 48.3, gpu: 46.1, battery: 31.2, status: "normal" },   degrees Celsius
//   battery: { level: 82, charging: true } }
mirmire.system.tools()   // opens Settings › Tools: the same readings, closing background apps and clearing caches

Vitals in the catalog is a complete example.

Servers and web services

With the internet permission (and "api": 6), mirmire.http() makes any web request: a POST to sign in, an Authorization or X-Api-Key header, a PUT or DELETE. Mirmire makes it itself, so it works whatever the server’s CORS settings and reaches a server on the player’s own network (http://192.168.1.20:8080). That’s what a dashboard widget for a home server needs: RomM, Jellyfin, Pi-hole, a download client.

const r = await mirmire.http("http://192.168.1.20:8080/api/stats", {
  method: "GET",                                  // or POST, PUT, PATCH, DELETE, HEAD
  headers: { Authorization: "Bearer " + token },
  body: { name: "Mirmire" },                      // a string, or an object sent as JSON
  timeout: 15,                                    // seconds, 1 to 60
  as: "text",                                     // or "dataUrl" for a picture: a data: address for an <img>
  selfSigned: true,                               // API 7: also accept the certificate a server made for itself (see below)
});
// { ok: true, status: 200, headers: { "content-type": "application/json" }, body: "…", json() }
if (r.ok) console.log(r.json().ROMS);
else console.log(r.status ? "The server said " + r.status : "Can't reach it: " + r.error);

Web sockets

A page in a web view can’t open ws:// to a server on the player’s network, or wss:// to one with its own certificate. From API 7, mirmire.socket() can: Mirmire opens it.

const s = mirmire.socket("ws://192.168.1.30/api/current", { selfSigned: true });
s.onopen = () => s.send(JSON.stringify({ jsonrpc: "2.0", id: 1, method: "core.ping", params: [] }));
s.onmessage = (e) => console.log(JSON.parse(e.data));
s.onclose = (e) => console.log(e.error ? "Lost it: " + e.error : "Closed");
// s.readyState is 0 (opening), 1 (open), 2 (closing) or 3 (closed), as a browser's WebSocket; s.close() closes it

NAS in the catalog uses both: it talks to a TrueNAS over its web socket, at the certificate the TrueNAS made for itself.

RomM in the catalog is a complete example: it finds the server, signs in with a code, and shows the server’s numbers and latest games.

Servers Mirmire is connected to

A player who already added a RomM library in Settings › Library, or connected Home Assistant in Settings › Home Assistant, shouldn’t have to sign in again for a widget. With the romm or homeassistant permission (and "api": 6), a plugin can use those connections: it names the server and a path, and Mirmire sends the request with its own sign-in. The plugin never sees a password or token, and the request can’t go to any other address.

const servers = mirmire.servers.list("romm");   // or "homeassistant", or no argument for all the plugin may use
// [{ id: "romm:3", kind: "romm", name: "RomM", url: "http://192.168.1.20:8080" }]
if (servers.length) {
  const r = await mirmire.servers.request(servers[0].id, "/api/stats");
  if (r.ok) console.log(r.json().ROMS);
}

AI

With the ai permission, a plugin can ask Mirmire’s AI for a short line about a game (a tip, a fun fact or a comment on the collection) and, from a full-screen page, hold a chat the player types. The player sets the AI up once in Settings › AI, and turns it on or off for each plugin on that plugin’s options page. It’s off until they turn it on.

// Any page:
mirmire.ai.status()  // { enabled, ready, provider, providerLabel }: enabled = on for this plugin, ready = set up in Settings
mirmire.ai.ask("game", gameId, { name: "Mochi" }).then((r) => { if (r.ok) say(r.text); })   // r = { ok, text } or { ok: false, error }
// kinds: "game" (just played), "playing" (being played now), "collection" (a few of the player's games)
// name: what the AI calls itself (letters, digits and spaces, up to 20); "Mirmire" when empty
mirmire.ai.settings()   // opens Settings › AI

// Only on a full-screen page (the options page, or one opened with openPage):
mirmire.ai.configure({ enabled: true })   // this plugin's switch; returns the new status
mirmire.ai.test({ name: "Mochi" })        // a Promise like ask(); shows whether the setup works
mirmire.ai.chat([{ role: "user", text: "Any tips for Contra?" }], { name: "Mochi" })
                                     // a conversation the player types: the last 12 messages ("user" or "assistant"),
                                     // each up to 500 characters; the most recently played game is mentioned to the AI.
                                     // Resolves to { ok, text } or { ok: false, error }

Hint replies are a single line of plain text, at most about 160 characters; chat replies are up to a few sentences. When the AI isn’t set up, the quota is used up or the device is offline, ask() returns { ok: false }. Fall back to your own lines quietly, and mark AI lines so players can tell them apart (Pixel Pal adds an AI tag to its speech bubble).

Events

// The player pressed A (or tapped) on your widget.
window.addEventListener("mirmire:select", () => feed());

// The player switched themes. mirmire.theme has the new colors.
window.addEventListener("mirmire:theme", () => redraw());

// The library changed: new games, a favorite, a finished download, a game just played. Ask for the lists again.
// Sent to a Big Picture.
window.addEventListener("mirmire:library", () => reload());

Theme colors

The theme’s colors are set as CSS variables on the page, so your widget matches every theme without extra work:

.title { color: var(--primary); }
.card  { background: var(--surface-variant); color: var(--on-surface); border-color: var(--outline); }

The variables are --primary, --on-primary, --secondary, --tertiary, --background, --on-background, --surface, --on-surface, --surface-variant, --on-surface-variant, --outline and --error.

Three more are the same in every theme, because they mean something: --favorite (the pink-red of a favorite’s heart), --gold (ratings and trophies) and --success (it worked, or it’s on the device). They’re there from Mirmire 1.3.5, so give a fallback: fill: var(--favorite, #FF6B8A), var(--gold, #FFC23D), var(--success, #4FD18B). Prefer a small picture to words for this kind of fact (a heart, a star, a cloud with a tick or an arrow): the catalog’s Big Pictures show how.

The page background is transparent: Mirmire draws the card behind your widget, with the theme’s shape, and the focus outline around it.

An options page

Add "settings": "settings.html" to plugin.json and a settings.html next to index.html. It opens full screen, with the same window.mirmire and the same storage as the widget, so save choices with mirmire.storage.set(). When it closes, the widget reloads to pick them up. On a controller, the arrow keys reach the page as keydown events and A clicks the focused element, so use real buttons and inputs and move focus with the arrows. B closes the page.

Theme Studio previews the widget page only; add an options page (or other pages you open with mirmire.openPage) to the ZIP by hand. In the preview, mirmire.ai gives sample answers, mirmire.bubble shows along the top, and mirmire.games.playing() returns the first sample game.

Make a Big Picture

A Big Picture plugin replaces the whole of Big Picture with your page: your layout, your motion, your idea of what a library should look like. (Need a 3D engine or native speed instead of a web page? A separate app can be a Big Picture too: see Make a Big Picture app.) Players install it like any plugin and pick it in Settings › Layout › Big Picture style. Game Wall, Crossbar, Ledger and Timeline in the catalog are complete ones, each a single readable file, and each a different idea of what a library can look like. Shelves is a larger one: boxes in CSS 3D, console models drawn with three.js, and a game’s video. Theme Studio’s New Big Picture starts from Game Wall, and the others are among its templates.

{
  "id": "game-wall",
  "name": "Game Wall",
  "author": "Your name",
  "version": 1,
  "description": "A Big Picture that is one wall of covers.",
  "kind": "bigpicture",
  "entry": "index.html",
  "permissions": ["library"],
  "api": 4
}

Your page fills the screen, inside the camera cutout and system bars. The page background is transparent, so the player’s theme wallpaper shows wherever you paint nothing; paint html or body to cover it. Theme colors arrive as the same CSS variables a widget gets.

The controller

Presses arrive as mirmire:button events. There is no mouse and no browser focus to rely on: keep track of what’s selected yourself, and draw it.

window.addEventListener("mirmire:button", (e) => {
  const { button, repeat } = e.detail;   // repeat is true while a direction is held
  if (button === "right") move(+1);
  else if (button === "a") mirmire.games.play(selected.id);
  else if (button === "b") { if (!goBack()) return; }   // nowhere to go back to: leave B alone
  else return;
  e.preventDefault();                    // you used the press
});
button Comes from
up, down, left, right The D-pad, the left stick, or a keyboard’s arrows. Held, they repeat with repeat: true.
a A, Enter, or OK on a remote.
b B, Esc, or Android’s Back.
x, y, l1, r1, l2, r2, select Those buttons.

Players who swapped A and B, or remapped a button, get what they chose: you always see the button’s meaning. Touch works as on any web page, so make covers and tabs tappable too.

Mirmire keeps a way out that your page can’t take away:

What a Big Picture can do

mirmire.bigPicture.menu()      // opens Mirmire's menu (the one on Start), for a button of your own
mirmire.bigPicture.settings()  // opens Mirmire's Settings (asks for the parent's PIN when they're locked)
mirmire.bigPicture.search()    // opens the quick menu's search
mirmire.bigPicture.exit()      // leaves Big Picture, back to the home screen
mirmire.bigPicture.select(id)  // tells Mirmire which game the player is on (null for none), so a handheld's
                               // second screen shows it

// With the "library" permission, as well as everything a widget gets:
mirmire.games.favorite(id, true)   // marks a game as a favorite, or not (false)

mirmire.openSettings(), openPage() and openSite() work as in a widget, and open over your Big Picture. mirmire.bubble() does nothing here: draw your own.

What you list is what Mirmire’s own Big Picture would: games hidden by library cleanup or by a child’s profile aren’t in mirmire.games.all().

Sounds and music

A Big Picture gets the player’s theme sounds and music without doing anything: Mirmire plays a sound for each press and the theme’s music behind your page. To give yours its own, add the files to the ZIP and name them in plugin.json:

"sounds": { "move": "sounds/move.wav", "select": "sounds/select.wav", "back": "sounds/back.wav" },
"music": ["music/drift.ogg"]
Sound Plays when
move The D-pad or left stick is pressed
select A, X, Y or Select
back B
tab L1, R1, L2 or R2
menu Start, when Mirmire’s menu opens
favorite A game is marked a favorite
launch A game starts
edge A press that nothing used, which is rare in a Big Picture

Phones: the camera cutout and touch

On a phone, Big Picture is played by touch, and in landscape the camera cutout sits at one side of the screen.

Good to know

Tips

Plugins in Mirmire Dashboard

Mirmire Dashboard is Mirmire’s Home page on its own: a light dashboard and home screen for a homelab, a wall tablet or a TV box, with no game library. It installs widget plugins from the same catalog and runs them the same way: the same sizes (including Tall and Full), mirmire.rows, theme colors, options pages, mirmire.openSite(), mirmire.http(), mirmire.socket() and selfSigned.

What it can’t do is anything about games, so only some permissions work there:

Permission In Mirmire Dashboard
internet Works as in Mirmire.
system Works. Graphics load and some temperatures are null (Mirmire reads them through its own shell access), and mirmire.system.tools() opens Android’s storage settings.
homeassistant Works, with the Home Assistant connected in the Dashboard’s Settings › Home Assistant.
library, achievements, ai, emulators, romm Not available. A plugin that asks for any of them is listed under Only in Mirmire in the Dashboard’s catalog and can’t be installed there.

Big Picture plugins are Mirmire only.

To check where it’s running, read mirmire.host: "dashboard" in Mirmire Dashboard, "mirmire" in Mirmire (versions before 1.3.9 leave it out). In the Dashboard, mirmire.games, mirmire.systems, mirmire.achievements() and mirmire.emulators still exist and answer empty, and mirmire.ai answers with an error, so a plugin shared by both apps doesn’t fail on them.

To make a widget that works in both, ask only for internet, system or homeassistant. Every Home server plugin in the catalog except RomM does.

Share your plugin in Mirmire’s catalog

Mirmire lists the plugins from mirmire-plugins under Settings › Plugins › Available plugins, where players install them with one press. To add yours, fork that repository, put your plugin’s folder in plugins/, and open a pull request. Its README has the steps and what a pull request needs.

Install a plugin

Mirmire shows the plugin’s name, author and permissions, and installs it when you press Install. Then add a widget from Add widget › Plugins, or choose a Big Picture in Settings › Layout › Big Picture style and turn on Big Picture. To turn a plugin off or remove it, open Settings › Plugins; a Big Picture that’s off or removed gives way to Mirmire’s own.

Troubleshooting

Problem Fix
“No plugin.json in that ZIP” Zip the plugin folder’s contents, so plugin.json is at the top.
The widget is blank Check that entry names your page, and that sizes use vh/% rather than a fixed height. On a computer, Theme Studio’s preview shows script errors as a message.
An image or font doesn’t load Paths are relative to the ZIP’s top, for example img/cat.png. Web addresses need the internet permission.
mirmire.games returns nothing Add library to permissions, then import the plugin again.
The old version still shows Use the same id to replace a plugin.
A Big Picture shows up as a widget, or “needs a newer Mirmire” Add "kind": "bigpicture" and "api": 4. Big Picture plugins need a Mirmire that offers plugin API 4.
The D-pad does nothing in a Big Picture Listen for mirmire:button on window, not for keydown.
Stuck in a Big Picture Press Start, or touch the screen and tap Menu in the top right corner (or press B or Back three times quickly), then Use Mirmire’s Big Picture or Exit Big Picture.
View this page on GitHub