# App mode

Your app’s own page, `<id>.fave1.app`. The board, the list, the link someone sends a friend — the place people come back to.

ctx.surface === 'app'

## Your address

Any address on `https://<id>.fave1.app/` opens your app — one bundle, and the query and hash are yours to read. That’s how a link opens straight to the right thing: a note, a shared board, a page that says where a link goes. Put what a link needs in the **query or hash**, not the path: a link opened in a browser goes through My Fave1, which carries the query (up to 2,000 characters) and the hash but not the path, and paths that name your app’s files (`/index.js`, `/manifest.json`, `/locales/…`) serve those files.

`src/index.ts`

```ts
if (ctx.surface === 'app') {
  const q = new URL(location.href).searchParams;
  const shared = location.hash.startsWith('#s=') ? location.hash.slice(3) : null;
  if (shared) showShared(shared);        // a hash never reaches any server
  else if (q.get('u')) showLink(q.get('u')!);
  else showHome();
}
```

Fave1 uses `?review=`, `?data=`, `?locale=`, `?dev=`, `?app=` and `?f1note=` — pick any other names. `#s=` is the convention Fave1’s own apps use for a [ctx.shared](https://developers.fave1.com/docs/ctx-shared.md) link: the ref after it is the whole key, and because it is a hash it never leaves the browser.

## Trying it

Add your build as a [DEV source](https://developers.fave1.com/docs/quickstart.md#dev-source) in the launcher, then open [My Fave1](https://www.fave1.com/myapps): it’s there first, with a DEV badge, and opens in app mode in the same window and phone card people get. With `npm run dev`, save a file and press the window’s refresh. On your phone or in Safari, add a Test link instead ([App mode, too](https://developers.fave1.com/docs/quickstart.md#home)).

Like the DEV source, a test build starts in a sandbox — storage and pub stay in that browser. Switch **Data** to **My account** in the DEV panel to save to [your account’s DEV slot](https://developers.fave1.com/docs/quickstart.md#dev-account) instead, and see app mode the way people with an account will. A Test link from `npm run submit` or Versions also opens the build on its own, in any browser, for 12 hours ([Test a build anywhere](https://developers.fave1.com/docs/publishing.md#test)).

To see app mode in another language, add `?locale=ko` (or `es`, `pt-BR` …) to a DEV or review build’s address — `ctx.locale` and `ctx.t` follow it. Live apps ignore it and use the person’s own language ([ctx.locale · ctx.t](https://developers.fave1.com/docs/ctx-locale.md)).

## The screen

| Where | What you get | Size |
| --- | --- | --- |
| `phone` | The whole screen under Fave1’s header | full |
| `Test link` | On a computer, a [Test link](https://developers.fave1.com/docs/publishing.md#test) opens on its own: a column in the middle of the browser window — phone-sized, or as wide as your manifest’s `window` asks for when the screen allows. Any other visit to your address opens your app in My Fave1 | 390 · 760 · 1120 |
| `My Fave1` | A window people move and resize, next to other apps. It opens phone-size unless your [manifest](https://developers.fave1.com/docs/manifest.md#fields) says `"window": "medium"` (760 wide) or `"wide"` (1120) — as wide as the screen allows | 390 · 760 · 1120 |

## Drawing it

`ctx.ui.host()` is everything under the header — draw your screen there. The panel calls (`corner`, `minimize`, `resizable`, `resize`, `hide`) do nothing in app mode; there’s no page to get out of the way of. Fill the width you’re given, from a narrow window to a wide one.

## Inside My Fave1

My Fave1 opens app mode in a frame. Almost everything works the way it does on its own page:

| Thing | Inside My Fave1 | Works |
| --- | --- | --- |
| `popups · new tabs` | `window.open()` and `target="_blank"` links open a new tab | yes |
| `downloads` | `<a download>` saves the file | yes |
| `clipboard` | Copy on a tap. Paste with [ctx.clipboard.read()](https://developers.fave1.com/docs/ctx-clipboard.md) — Fave1 asks first | yes |
| `ai` | [ctx.ai](https://developers.fave1.com/docs/ctx-ai.md) works the same — in app mode it asks once for your app, not per site | yes |
| `leaving` | A plain link can’t take the whole window to another site — open it in a new tab | new tab |
| `sound` | Fave1 mutes your app while another one is in front, and turns it back up when yours is. Nothing to do | auto |
| `share sheet` | `navigator.share()` opens the system share sheet | yes |
| `camera · mic` | [ctx.camera](https://developers.fave1.com/docs/ctx-camera.md) and [ctx.mic](https://developers.fave1.com/docs/ctx-mic.md) work when your manifest declares them | yes |
| `motion sensors` | Tilt and shake don’t reach the frame. Only a Test link opened on its own gets them | no |
| `pointer lock · screen capture · fullscreen` | The frame doesn’t allow `requestPointerLock()`, `getDisplayMedia()` or `requestFullscreen()` — they fail. Use them on a site, or in a Test link opened on its own | no |
| `localStorage` | Your own, but kept apart from the same address opened on its own (a Test link) — the browser files a frame’s storage separately. What should be the same everywhere goes in [ctx.storage](https://developers.fave1.com/docs/ctx-storage.md) | apart |

## When nobody is signed in

A link to `<id>.fave1.app` opened in a browser’s address bar goes to My Fave1 (`www.fave1.com/myapps?open=<id>`) — signed out, through sign-in first — and your app opens there, carrying the link’s `?query` and `#hash` — as a visitor window if they haven’t added it yet, as long as it’s in the store. Inside My Fave1 your app runs in a frame at its own address; a review link (`?review=`) opens on its own page.

An app that declares only `page` permissions or `clipboard` opens straight away — and because it never asks the account, `ctx.user.signedIn` is `false` in app mode. One that declares anything else (`storage`, `pub`, `ai`, `camera`, `mic`) may show Safari and Firefox people a one-tap Continue first — Fave1 draws it; if their browser says no, your app opens for them signed out.

To sign someone in for app mode, link to `https://www.fave1.com/myapps?open=<id>`. Signed out, it goes through sign-in first; after that My Fave1 opens your app — added or not, as long as it’s in the store. On a site you don’t need a link: the panel header already has **Join**, and your app opens again once they’re in.

## Sending people to app mode

From the page, open app mode in a new tab on a tap — *See all your notes*. Want them to land back on the exact spot later? Keep the page address with a text fragment (`#:~:text=first%20words,last%20words`), and leave yourself a note in [ctx.storage](https://developers.fave1.com/docs/ctx-storage.md) so the page side knows what to light up when your app opens there again.

`src/index.ts`

```ts
ctx.ui.button('See them all', {
  onClick: () => window.open('https://my-app.fave1.app/', '_blank', 'noopener'),
});
```
