Skip to content

Chapter 1 of 17

Create a Window ​

Replace the starter counter with the Notes window: an Adwaita window with a header bar and an empty state.

The project ​

Project structure describes the project's files.

The scaffold's starter test, tests/app.test.tsx, looks for the counter's Increment button and imports a default export that the new src/app.tsx doesn't have, so npm run typecheck would fail. Delete it; Test the App writes the app's tests.

bash
rm tests/app.test.tsx

Mark strings for translation ​

Install @gtkx/i18n:

bash
npm install @gtkx/i18n

Until Translate the App adds catalogs, every t("…") shows its source text. Pass t a string literal, as every chapter does, so that GTKX can extract the message; Keep messages extractable lists the forms it reads.

The application window ​

Replace src/app.tsx:

src/app.tsx
tsx
import { useTranslation } from "@gtkx/i18n";
import {
    AdwApplication,
    AdwApplicationWindow,
    AdwHeaderBar,
    AdwStatusPage,
    AdwToolbarView,
} from "@gtkx/jsx/adw";
import { quit } from "@gtkx/react";

export const App = () => {
    const { t } = useTranslation();

    return (
        <AdwApplication>
            <AdwApplicationWindow
                title={t("Notes")}
                widthRequest={360}
                heightRequest={294}
                onCloseRequest={quit}
            >
                <AdwToolbarView top={<AdwHeaderBar />}>
                    <AdwStatusPage
                        iconName="document-new-symbolic"
                        title={t("No Notes")}
                        description={t(
                            "Notes are Markdown files in your notes folder",
                        )}
                    />
                </AdwToolbarView>
            </AdwApplicationWindow>
        </AdwApplication>
    );
};

Elements come from @gtkx/jsx/<namespace>, one module per library, and take the native class's properties and signals as camelCase props; JSX Elements has the rules.

  • AdwApplication creates the application with the ID from gtkx.config.ts and renders its children once it activates.
  • AdwApplicationWindow is the main window. widthRequest and heightRequest set the smallest size it shrinks to, 360 by 294, the size the GNOME HIG asks phone-friendly apps to support. quit() from @gtkx/react unmounts the app and quits when the window closes.
  • AdwToolbarView places bars around its content. Its top slot holds an AdwHeaderBar, which shows the window title and the close button.
  • AdwStatusPage is the empty state, a placeholder page with a symbolic icon, a title and a description.

Run it ​

Save src/app.tsx. Its imports changed, so gtkx dev restarts the app instead of refreshing it, and the window shows the empty state.

The Notes window: a header bar titled Notes above a status page with a new-document icon, the title No Notes, and the description Notes are Markdown files in your notes folder.The Notes window: a header bar titled Notes above a status page with a new-document icon, the title No Notes, and the description Notes are Markdown files in your notes folder.
Captured from src/app.tsx above.

Run npm run typecheck. It passes once the starter test is gone.