# 1. Open your first window

Source: https://daybrite.dev/docs/tutorials/first-app

Build a Session counter in six lessons using AppKit on macOS, WinUI on Windows, or GTK on
Linux. Use the same host platform throughout. Prerequisites: basic Rust, a terminal, and a text
editor. A target combines an OS and UI toolkit; a Piece describes UI controls or containers.

## 1. Prepare your computer

Install Git and stable Rust through [rustup](https://rustup.rs/), then install the platform tools:

**macOS:** Use an Apple silicon Mac with full Xcode 27 or newer. Open Xcode once to finish installation. In Terminal, use Bash or Zsh.

**Windows:** Use Windows with Visual Studio C++ Build Tools, the Windows SDK, the MSVC Rust toolchain, and Windows App Runtime 2.5.1 or newer. Use PowerShell 7 in a Developer PowerShell terminal so the C++ tools are on PATH.

**Linux:** These instructions use Ubuntu 24.04 or newer with GTK 4.10+, libadwaita 1.5+, librsvg 2.52+, their development packages, and pkg-config. Use Bash in a desktop session.

See [system requirements](https://daybrite.dev/docs/reference/system-requirements). Select full Xcode on macOS;
use the MSVC Rust toolchain on Windows. The Day installation does not install SDKs.

## 2. Install Day

**macOS: Run in `.`**

```sh
cargo install day-cli --locked
```

**Windows: Run in `.`**

```powershell
cargo install day-cli --locked
```

**Linux: Run in `.`**

```sh
cargo install day-cli --locked
```

This compiles the latest published CLI from crates.io into Cargo's executable directory.
If `day` is not found, open a new terminal or check [PATH](https://daybrite.dev/docs/how-to/troubleshooting#day-is-not-found).
This desktop debug app requires neither mobile SDKs nor a developer signing account.

Check the CLI and toolkit installation:

**macOS: Run in `.`**

```sh
day --version
day doctor --toolkit appkit
```

**Windows: Run in `.`**

```powershell
day --version
day doctor --toolkit winui
```

**Linux: Run in `.`**

```sh
day --version
day doctor --toolkit gtk
```

## 3. Create the project

Run in your projects directory. Use an unused name if `first-app` exists.

**macOS: Run in `.`**

```sh
mkdir -p first-app/src first-app/resource/locales/en
cd first-app
```

**Windows: Run in `.`**

```powershell
New-Item -ItemType Directory -Path first-app/src, first-app/resource/locales/en
Set-Location first-app
```

**Linux: Run in `.`**

```sh
mkdir -p first-app/src first-app/resource/locales/en
cd first-app
```

All following paths are relative to this app directory. Create these files:

**All platforms: Write `Cargo.toml`**

```toml
[package]
name = "first-app"
version = "0.1.0"
edition = "2024"

[workspace]

[lib]
name = "dayapp"
```

The empty `[workspace]` isolates the app from enclosing Cargo workspaces. `[lib] name = "dayapp"`
names the library used by `main.rs` and native hosts. Create source files before adding dependencies.

**macOS: Write `Day.toml`**

```toml
schema = 1

[app]
id = "dev.daybrite.tutorial.session-counter"
title = "Session counter"
build = 1
targets = ["macos-appkit"]

[window]
width = 640
height = 480
min_width = 400
min_height = 320
```

**Windows: Write `Day.toml`**

```toml
schema = 1

[app]
id = "dev.daybrite.tutorial.session-counter"
title = "Session counter"
build = 1
targets = ["windows-winui"]

[window]
width = 640
height = 480
min_width = 400
min_height = 320
```

**Linux: Write `Day.toml`**

```toml
schema = 1

[app]
id = "dev.daybrite.tutorial.session-counter"
title = "Session counter"
build = 1
targets = ["linux-gtk"]

[window]
width = 640
height = 480
min_width = 400
min_height = 320
```

Use a unique app ID for a product. Window dimensions are in points. The manifest title is
packaging metadata; the visible window title comes from the Fluent catalog.

**All platforms: Write `build.rs`**

```rust
fn main() {
    day_build::prebuild_project().expect("day-build: prebuild");
}
```

**All platforms: Write `resource/locales/en/app.ftl`**

```ftl
app_title = Session counter
welcome = Count the sessions you finish today.
```

The build script generates typed accessors for Fluent messages.

**All platforms: Write `src/lib.rs`**

```rust
use day::prelude::*;

day::resources!();
day::day_start!(options: res::window_options(), root);

pub fn root() -> impl Piece {
    label(res::str::welcome())
        .padding(Space::L)
        .id(id!(welcome_label))
}
```

**All platforms: Write `src/main.rs`**

```rust
fn main() {
    day::launch(dayapp::res::window_options(), dayapp::root);
}
```

`day::resources!()` exposes `res`. `res::window_options()` installs the catalog and sets the
localized title and manifest geometry. `root()` defines the content; `Space::L` is a spacing token.
`day_start!` supplies the native-host entry point; `main.rs` supplies the Rust desktop entry point.
`welcome_label` identifies the label for automation independently of its translated text.

Add the dependencies:

**macOS: Run in `first-app`**

```sh
cargo add 'day-app@0.*' --rename day
cargo add --build 'day-build@0.*'
```

**Windows: Run in `first-app`**

```powershell
cargo add 'day-app@0.*' --rename day
cargo add --build 'day-build@0.*'
```

**Linux: Run in `first-app`**

```sh
cargo add 'day-app@0.*' --rename day
cargo add --build 'day-build@0.*'
```

`cargo add` records dependency requirements in `Cargo.toml`; Cargo locks exact versions in
`Cargo.lock`. Keep the lockfile. The `day-app` package exports the `day` library;
`--rename day` sets the dependency key. `day-build` is used by `build.rs`.

**All platforms: Append to `Cargo.toml`**

```toml

[features]
default = ["mock"]
mock = ["day/mock"]
appkit = ["day/appkit"]
gtk = ["day/gtk"]
winui = ["day/winui"]
```

The default `mock` feature supports editor checks. `day build` selects the target's toolkit feature.

## 4. Prepare the native host

On [macOS](https://daybrite.dev/docs/reference/platforms/macos-appkit), generate the Swift runner and host configuration:

**macOS: Run in `first-app`**

```sh
day project add-target macos-appkit
```

Keep the files under `platform/macos/`. Builds generate the Xcode project.
[Windows](https://daybrite.dev/docs/reference/platforms/windows-winui) and [Linux](https://daybrite.dev/docs/reference/platforms) use `main.rs` and skip this command.

## 5. Build and open the window

Run from `first-app`:

**macOS: Run in `first-app`**

```sh
day build -t macos-appkit
```

**Windows: Run in `first-app`**

```powershell
day build -t windows-winui
```

**Linux: Run in `first-app`**

```sh
day build -t linux-gtk
```

**macOS: Run in `first-app`**

```sh
day launch -t macos-appkit
```

**Windows: Run in `first-app`**

```powershell
day launch -t windows-winui
```

**Linux: Run in `first-app`**

```sh
day launch -t linux-gtk
```

Expect a successful build and a window titled **Session counter** displaying
**Count the sessions you finish today.** Debug builds may append build information to the title.

**macOS:** Quit with Command-Q before continuing.

**Windows:** Close the app window before continuing.

**Linux:** Close the app window before continuing.

`day launch` also builds; use it after subsequent edits. A missing-icon notice is expected
because this app has no custom launcher icon.

## Troubleshooting

| Symptom                        | Check and recovery                                                                                                                |
| ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------- |
| `day: command not found`       | Add Cargo's executable directory (`~/.cargo/bin` by default) to `PATH`; open a new terminal.                                      |
| Doctor rejects Xcode           | Select full Xcode 27 or newer with `DEVELOPER_DIR`; run `day doctor --toolkit appkit`. Command Line Tools alone are insufficient. |
| Cargo cannot find `day`        | Check `day-app`, `day-build`, and connectivity to crates.io.                                                                      |
| Missing `res::str` accessor    | Check the catalog path and key; rebuild. Do not edit generated Rust.                                                              |
| Launch cannot find the project | Run from the directory containing `Day.toml`.                                                                                     |

## Editor support

The [VS Code extension](https://daybrite.dev/docs/how-to/vscode) provides project and target commands.
See [agent instructions](https://daybrite.dev/docs/reference/for-agents) for coding conventions.

## Next step

Continue to [2. Handle a button click](https://daybrite.dev/docs/tutorials/events).
