Skip to content

Commit

Permalink
Update READMEs to reflect project structure (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
zephraph authored Feb 19, 2025
1 parent d4ddde3 commit a317380
Show file tree
Hide file tree
Showing 3 changed files with 198 additions and 39 deletions.
87 changes: 48 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
# @justbe/webview

A light, cross-platform library for building web-based desktop apps with [Deno](https://deno.com/).
A light, cross-platform library for building web-based desktop apps. The project consists of a Rust backend that provides the core webview functionality, with multiple client libraries available for different languages and runtimes.

> [!NOTE]
> This is alpha level software that's rapidly changing. Things might break. Please let me know if you notice anything missing or not working.
## Available Clients

## Example
- [Deno Client](src/clients/deno/README.md) - Build desktop apps using Deno and TypeScript
- [Python Client](src/clients/python/README.md) - Build desktop apps using Python

## Architecture

This project is structured into two main components:

1. A Rust backend that provides the core webview functionality, compiled into a native binary for each platform
2. Client libraries that interface with the binary, available for multiple languages

Each client library handles binary management, communication with the webview process over stdio (standard input/output), and provides a idiomatic API for its respective language/runtime.

## Binary Management

When using any of the clients, they will check for the required binary for interfacing with the OS's webview. If it doesn't exist, it downloads it to a cache directory and executes it. The specific behavior and permissions required may vary by client - please see the respective client's documentation for details.

### Using a Custom Binary

All clients support using a custom binary via the `WEBVIEW_BIN` environment variable. If present and allowed, this will override the default binary resolution process in favor of the path specified.

## Examples

<details>
<summary>Deno Example</summary>

```typescript
import { createWebView } from "jsr:@justbe/webview";
Expand All @@ -24,50 +46,37 @@ webview.on("started", async () => {
await webview.waitUntilClosed();
```

You can run this yourself with
</details>

```sh
deno run https://raw.githubusercontent.com/zephraph/webview/refs/heads/main/examples/simple.ts
```

Checkout the [examples directory](https://github.com/zephraph/webview/tree/main/examples) for more.

## Permissions

When executing this package, it checks to see if you have the required binary for interfacing with the OS's webview. If it doesn't exist, it downloads it to a cache directory and executes it. This yields a few different permission code paths to be aware of.

### Binary not in cache
<details>
<summary>Python Example</summary>

This will be true of a first run of the package. These are the following permission requests you can expect to see:
```python
import asyncio
from justbe_webview import WebView, WebViewOptions, WebViewContentHtml, WebViewNotification

- Read HOME env -- Used to locate the cache directory
- Read <cache>/webview/webview-<version> -- Tries to read the binary from cache
- net to github.com:443 -- Connects to GitHub releases to try to download the binary (will be redirected)
- net to objects.githubusercontent.com:443 -- GitHub's CDN for the actual download
- Read <cache>/webview/ -- Reads the cache directory
- Write <cache>/webview/webview-<version> -- Writes the binary
- Run <cache>/webview/webview-<version> -- Runs the binary
async def main():
config = WebViewOptions(
title="Example",
load=WebViewContentHtml(html="<h1>Hello, World!</h1>"),
devtools=True
)

### Binary cached
async with WebView(config) as webview:
async def handle_start(event: WebViewNotification):
await webview.open_devtools()
await webview.eval("console.log('This is printed from eval!')")

On subsequent runs you can expect fewer permission requests:
webview.on("started", handle_start)

- Read HOME env -- Use to locate the cache directory
- Read <cache>/deno-webview/deno-webview-<version>
- Run <cache>/deno-webview/deno-webview-<version>

### Allowed `WEBVIEW_BIN`

`WEBVIEW_BIN` is a special environment variable that, if present and allowed, will short circuit
the binary resolution process in favor of the path specified. In this case there will be only one permission:

- Run <WEBVIEW_BIN>
if __name__ == "__main__":
asyncio.run(main())
```

Note that this environment variable will never be _explicitly_ requested. If the script detects it's not allowed to read this env var it just skips this code path altogether.
</details>

## Contributing

This project uses [mise](https://mise.jdx.dev/) to manage runtimes (like deno, rust) and run scripts. If you'd like
to contribute, you'll need to install it.
This project uses [mise](https://mise.jdx.dev/) to manage runtimes (like deno, python, rust) and run scripts. If you'd like to contribute, you'll need to install it.

Use the `mise tasks` command to see what you can do.
79 changes: 79 additions & 0 deletions src/clients/deno/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# @justbe/webview Deno Client

A light, cross-platform library for building web-based desktop apps with
[Deno](https://deno.com/).

## Installation

```typescript
import { createWebView } from "jsr:@justbe/webview";
```

## Example

```typescript
import { createWebView } from "jsr:@justbe/webview";

using webview = await createWebView({
title: "Example",
html: "<h1>Hello, World!</h1>",
devtools: true,
});

webview.on("started", async () => {
await webview.openDevTools();
await webview.eval("console.log('This is printed from eval!')");
});

await webview.waitUntilClosed();
```

You can run this yourself with:

```sh
deno run https://raw.githubusercontent.com/zephraph/webview/refs/heads/main/examples/simple.ts
```

Check out the [examples directory](examples/) for more examples.

## Permissions

When executing this package, it checks to see if you have the required binary
for interfacing with the OS's webview. If it doesn't exist, it downloads it to a
cache directory and executes it. This yields a few different permission code
paths to be aware of.

### Binary not in cache

This will be true of a first run of the package. These are the following
permission requests you can expect to see:

- Read HOME env -- Used to locate the cache directory
- Read <cache>/webview/webview-<version> -- Tries to read the binary from cache
- net to github.com:443 -- Connects to GitHub releases to try to download the
binary (will be redirected)
- net to objects.githubusercontent.com:443 -- GitHub's CDN for the actual
download
- Read <cache>/webview/ -- Reads the cache directory
- Write <cache>/webview/webview-<version> -- Writes the binary
- Run <cache>/webview/webview-<version> -- Runs the binary

### Binary cached

On subsequent runs you can expect fewer permission requests:

- Read HOME env -- Use to locate the cache directory
- Read <cache>/deno-webview/deno-webview-<version>
- Run <cache>/deno-webview/deno-webview-<version>

### Using a Custom Binary

You can specify a custom binary path using the `WEBVIEW_BIN` environment
variable. When set and allowed, this will bypass the default binary resolution
process. In this case, only one permission is needed:

- Run <WEBVIEW_BIN>

Note that this environment variable will never be _explicitly_ requested. If the
script detects it's not allowed to read this env var it just skips this code
path altogether.
71 changes: 71 additions & 0 deletions src/clients/python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# justbe-webview

A light, cross-platform library for building web-based desktop apps with Python.

## Installation

You can install justbe-webview using either `uv` (recommended) or `pip`:

```bash
# Using uv (recommended)
uv pip install justbe-webview

# Using pip
pip install justbe-webview
```

## Example

```python
import asyncio
from justbe_webview import (
WebView,
WebViewOptions,
WebViewContentHtml,
WebViewNotification,
)

async def main():
config = WebViewOptions(
title="Simple",
load=WebViewContentHtml(html="<h1>Hello, World!</h1>"),
)

async with WebView(config) as webview:
async def handle_start(event: WebViewNotification):
await webview.eval("console.log('This is printed from eval!')")

webview.on("started", handle_start)

if __name__ == "__main__":
asyncio.run(main())
```

You can find more examples in the [examples directory](examples/), including:
- Loading URLs
- Loading HTML content
- Window size management
- IPC (Inter-Process Communication)

### Binary Management

On first run, the client will:
1. Check for a cached binary in the user's cache directory
2. If not found, download the appropriate binary for the current platform
3. Cache the binary for future use

The exact cache location depends on your operating system:
- Linux: `~/.cache/justbe-webview/`
- macOS: `~/Library/Caches/justbe-webview/`
- Windows: `%LOCALAPPDATA%\justbe-webview\Cache\`

### Using a Custom Binary

You can specify a custom binary path using the `WEBVIEW_BIN` environment variable:

```bash
export WEBVIEW_BIN=/path/to/webview/binary
python your_app.py
```

When set, this will bypass the default binary resolution process.

0 comments on commit a317380

Please sign in to comment.