# API reference

> Every public item of the `kurogane` crate 0.0.6-beta.1, grouped by topic.

A composable Chromium runtime for Rust.

Build high-performance, GPU-accelerated desktop applications on Chromium or
embed it directly into existing applications.

Guides, concepts and the CLI reference are at <https://kurogane-rs.org/docs>.

## A first app

```rust
use kurogane::{App, AppHandle, IpcError};

fn greet(name: String, _: &AppHandle) -> Result<String, IpcError> {
    Ok(format!("Hello, {name}!"))
}

fn main() {
    App::new("content").command("greet", greet).run_or_exit();
}
```

The page calls the command with `window.kurogane.invoke("greet", "Kurogane")`
and gets `"Hello, Kurogane!"` back.

## Where to start

* [`App`] describes an application and starts it.
* [`AppInstance`] is the running application, owned by the thread that
  started it. [`AppHandle`] reaches it from any thread.
* [`BrowserHandle`] drives one browser.
* [`WindowOptions`] describes an application window.

## Talking to the page

* [`App::command`] registers a command. Its async and binary forms answer
  later or take bytes. A handler fails with an [`IpcError`].
* [`AppHandle::broadcast_json`] sends an event to every subscribed page.
* [`App::stream`] registers a [`StreamHandler`] for chunks in both
  directions.
* [`App::permit`] opens a command or stream to another origin.
* [`capability::Filesystem`] grants pages scoped access to files.

## Deciding what a page may do

Hooks such as [`App::on_new_window`], [`App::on_navigation`],
[`App::on_download`] and [`App::on_permission`] take a typed request. Each
answers with a decision whose `Default` leaves the choice to Kurogane.

## Processes

Chromium runs your binary again for each of its helper processes. Code
before the call that starts the runtime runs in every process. Guard
one-time work with [`is_browser_process`]. See [`App`].

## Your own event loop

[`App::start`] and [`App::start_embedded`] start Chromium without its
message loop. Your loop calls [`AppInstance::pump`] until
[`AppInstance::should_shutdown`] turns true and then
[`AppInstance::shutdown`].

[`AppInstance`]: https://kurogane-rs.org/docs/api/app/appinstance.md
[`AppHandle`]: https://kurogane-rs.org/docs/api/app/apphandle.md
[`App::on_download`]: https://kurogane-rs.org/docs/api/app/app.md#method.on_download
[`BrowserHandle`]: https://kurogane-rs.org/docs/api/app/browserhandle.md
[`App::on_new_window`]: https://kurogane-rs.org/docs/api/app/app.md#method.on_new_window
[`IpcError`]: https://kurogane-rs.org/docs/api/ipc/ipcerror.md
[`App::permit`]: https://kurogane-rs.org/docs/api/app/app.md#method.permit
[`App::start_embedded`]: https://kurogane-rs.org/docs/api/app/app.md#method.start_embedded
[`App`]: https://kurogane-rs.org/docs/api/app/app.md
[`AppHandle::broadcast_json`]: https://kurogane-rs.org/docs/api/app/apphandle.md#method.broadcast_json
[`App::stream`]: https://kurogane-rs.org/docs/api/app/app.md#method.stream
[`capability::Filesystem`]: https://kurogane-rs.org/docs/api/capabilities/filesystem.md
[`App::on_navigation`]: https://kurogane-rs.org/docs/api/app/app.md#method.on_navigation
[`App::start`]: https://kurogane-rs.org/docs/api/app/app.md#method.start
[`AppInstance::pump`]: https://kurogane-rs.org/docs/api/app/appinstance.md#method.pump
[`AppInstance::shutdown`]: https://kurogane-rs.org/docs/api/app/appinstance.md#method.shutdown
[`WindowOptions`]: https://kurogane-rs.org/docs/api/windows/windowoptions.md
[`is_browser_process`]: https://kurogane-rs.org/docs/api/app/is_browser_process.md
[`StreamHandler`]: https://kurogane-rs.org/docs/api/ipc/streamhandler.md
[`App::command`]: https://kurogane-rs.org/docs/api/app/app.md#method.command
[`App::on_permission`]: https://kurogane-rs.org/docs/api/app/app.md#method.on_permission
[`AppInstance::should_shutdown`]: https://kurogane-rs.org/docs/api/app/appinstance.md#method.should_shutdown

## Topics

- [App and runtime](https://kurogane-rs.org/docs/api/app.md): Configures an application, starts the runtime and reaches it once it runs.
- [Windows and browsers](https://kurogane-rs.org/docs/api/windows.md): Opens windows, places them and names the browsers inside them.
- [IPC](https://kurogane-rs.org/docs/api/ipc.md): Commands, streams and errors between your Rust code and the page.
- [Capabilities](https://kurogane-rs.org/docs/api/capabilities.md): Grants a page scoped access to the filesystem.
- [Requests and decisions](https://kurogane-rs.org/docs/api/requests.md): What a page or Chromium asks of your application and the answers it can give.

## Re-exports

- [`raw_window_handle`](https://docs.rs/raw_window_handle)
- [`tanso`](https://docs.rs/tanso)
