Add phone features to your app
Use the phone features around your page: icon, orientation, badge, notifications, key and images. To render a page outside the phone, see Surfaces.
You need: a registered app (AppHandle). See Build your first app.
Set the icon
Section titled “Set the icon”- Put
icon.pngin your bundle: square, 256x256, transparent outside the rounded square. Without it the app gets a flat colored square. - The caption is
iconLabelfromApps.Register. It defaults to the title.
Open the app from code, with no icon
Section titled “Open the app from code, with no icon”Use .NoIcon() when the way in is somewhere else, such as a world object. The app still has its panel, page and exit key.
Apps.Register("reflash-messages", "Reflash.Assets.reflash-messages", "Messages").NoIcon();Open and close it from code:
app.Open(); // same as pressing the iconapp.Close(); // back to the home screenbool open = app.IsOpen;Open()closes any other open app and turns the phone to this app’s orientation. The page is built on the first open.- It does not take the phone out of the pocket. A phone raised later shows your app.
IsOpenis true in that state;IsOnScreenalso requires the phone to be up. - Before the app is on a phone,
Open()does nothing. The log saysopen: '<id>' is not on a phone. The home screen is built when the gameplay scene starts. - Set
NoIcon()during init. Set later, it applies from the next spawn (a scene change).
Needs Sideload 1.1.0+. On an older host, both calls do nothing and the icon appears anyway. Check first:
if (!AppHandle.CanOpenProgrammatically){ LoggerInstance.Error("Sideload 1.1.0 or newer is required - not registering."); return;}Show the icon only sometimes
Section titled “Show the icon only sometimes”Call Icon(bool) while the game runs.
app.Icon(consoleIsOn); // show or hide the square- Call it every time you evaluate the condition. The phone is rebuilt on every scene load, so do not cache “already showing”.
- It is safe in an update loop.
- The first
Icon(true)creates the square. Hiding only deactivates it, so it returns to its place.
Support both orientations
Section titled “Support both orientations”-
Name the orientations in preference order. The first one is the opening orientation.
.Orientation("landscape") // landscape only.Orientation("landscape", "portrait") // both, opens landscape.Orientation("portrait", "landscape") // both, opens portrait// no call -> landscape only -
Style both in one sheet.
@media (orientation: portrait) {.app { flex-direction: column; }.sidebar { width: 100%; flex: 1; }.detail { display: none; }.app.on-detail .sidebar { display: none; }.app.on-detail .detail { display: flex; }}
- Do not build a turn button. The player turns the phone with the game’s rotate keys (Q and E by default, gamepad triggers too). Sideload adds a “Rotate Phone” hint while a turnable app is open.
- Sideload remembers the choice per app. Do not store it.
- A turn lays the page out again. The document, script, scroll positions and field contents stay.
s1.setOrientation(v)turns the phone from the page. It is refused with a log line if the app never declared that orientation.s1.orientationreads the current one.- A two-pane split rarely fits 400 px. In portrait, use push navigation: the script marks the visible pane, the stylesheet hides the other. Use
orientationchangeandback(see JavaScript, DOM and events).
Set an unread badge
Section titled “Set an unread badge”app.Badge(unreadCount); // zero clears itCounts above 99 show as “99+”. Set it when your count changes, not on a timer. The value survives a phone rebuild.
Send a notification
Section titled “Send a notification”app.Notify("Jessi Waters", "on my way");This raises the game’s own slide-in notification with your app icon. It does nothing if the app is not on a phone yet. It interrupts the player, so use Badge for anything that can wait.
Skip it when the player already sees your app:
if (!app.IsOnScreen) app.Notify(sender, text);IsOnScreen is true when your app is the open app and the phone is up.
Open the app with a key
Section titled “Open the app with a key”-
Register the key in your mod.
OnKeyfires with the phone still in the pocket.app.OnKey("Enter", _ => Online && app.Show()); -
Order the calls inside the handler:
Show()first, thenEmit().internal static bool QuickChat(){if (!_source.Online) return false; // let another app have Enterif (!_app.Show()) return false; // the game refused the phone_app.Emit("chat.compose", "everyone");return true;} -
In the page, call
focus()on your field when the event arrives.
- Call
Show()beforeEmit(). The page is built on first open. Before that, nothing listens, so an earlyEmitis lost.Show()builds the page synchronously. - Use
Show(), notOpen().Open()picks the app but leaves the phone down, so the app is open and invisible.Show()raises the phone first, so the first layout uses the real viewport. - Return
falseto decline. The press then goes to the next app that wants the same key. Decline when you cannot help the player. - A
focus()before the field is painted is granted when the field is rendered.
Key ownership, where keys are read, and caret rules are on Keys and typing.
Show images
Section titled “Show images”For a file in your bundle:
<img class="mark" src="glyph.png" alt="">.mark { width: 20px; height: 20px; color: #FFFFFF; }- Set both width and height. Layout cannot read the PNG size, so an image without both is empty.
- The aspect ratio stays inside the box.
colortints the image.
For a picture your mod makes at runtime, pass PNG bytes and use the s1:// name:
app.Image("avatar/" + steamId, pngBytes); // null or empty bytes remove it<img class="avatar" src="s1://avatar/76561198000000001">Sprites are cached per app. The same name replaces the picture.
Look up what a page cannot do
Section titled “Look up what a page cannot do”| You want | Result |
|---|---|
| Read or set a scroll offset | No. scrollToEnd() is the only scroll member. The host restores offsets after a rebuild when the content looks the same. |
| Know where a box is | Yes, with Sideload 1.12+. el.rect() gives { x, y, width, height } in CSS pixels from the screen’s top left. It shows the last render, so a new box reads as zeroes. |
| Know the app opened or closed | Not from the page. orientationchange is the only state signal. Your mod can use app.IsOpen and app.IsOnScreen. |
| Get a key other than Enter | Name it in data-keys on a text field. It arrives as keydown. Enter and Escape are refused: they already arrive as keydown and back. |
| Get a key while the app is closed | From your mod: app.OnKey(...). |
| Type without a click first | Yes. Set data-typing on the field. |
| Focus a control from script | Only input and textarea, with el.focus(). |
| Clipboard, files, time zone | No. There is no navigator. |
If the page cannot do it, ask whether your mod can, behind an s1.call.
Check it works
Section titled “Check it works”The icon, badge and notification appear on the phone. The log shows a line for each refused call, such as the open: message above.