Skip to content

TomokiMiyauci/rfd

Repository files navigation

rfd

JSR GitHub semantic-release: angular standard-readme compliant

Native dialog, port of Rust rfd.

Based on rfd@0.14.1.

Install

deno:

deno add @miyauci/rfd

node:

npx jsr add @miyauci/rfd

Usage

The load function must be called first. By default, it downloads and caches remote binaries.

import { FileDialog, load } from "@miyauci/rfd/$RUNTIME";

await load();

const dialog = new FileDialog();
const path = dialog.pickFile();

In addition, see supported runtime.

MessageDialog

MessageDialog corresponds to rfd::MessageDialog

import {
  load,
  MessageButtons,
  MessageDialog,
  MessageLevel,
} from "@miyauci/rfd/$RUNTIME";

await load();

const dialog = new MessageDialog();
const result = dialog.setLevel(MessageLevel.Error).setButtons(
  MessageButtons.OkCancel,
)
  .show();

Loading Local Binary

If you want to use a local binary, specify its path.

import { load } from "@miyauci/rfd/$RUNTIME";

await load("/path/to/bin");

Deno Runtime

Resource Management

Deno FFI requires explicit resource release. To prevent resource leaks, use using or call [Symbol.dispose]. See ECMAScript Explicit Resource Management.

import { FileDialog, load } from "@miyauci/rfd/deno";

await load();

using dialog = new FileDialog();

Unstable Feature Flags

The following flags are required for execution:

  • --unstable-ffi

Permission Flags

The following permissions must be allowed:

Permission Value
--allow-env
  • DENO_DIR
  • HOME
--allow-read ${DENO_DIR}/plug
--allow-ffi path to binary cache

This is usually used for debugging, etc.

Support

Currently supported targets are as follows.

Platform

The following platforms are supported:

Platform Rust Target
64-bit macOS (10.12+, Sierra+) x86_64-apple-darwin
ARM64 macOS (11.0+, Big Sur+) aarch64-apple-darwin
64-bit MSVC (Windows 10+, Windows Server 2016+) x86_64-pc-windows-msvc
ARM64 Windows MSVC aarch64-pc-windows-msvc
64-bit Linux (kernel 3.2+, glibc 2.17+) x86_64-unknown-linux-gnu
ARM64 Linux (kernel 4.1, glibc 2.17+) aarch64-unknown-linux-gnu

Runtime

The following runtime are supported:

Runtime Import Specifier
Deno @miyauci/rfd/deno
Node.js @miyauci/rfd/node

Modules

The following modules are supported:

rfd Supported
FileDialog
MessageDialog
AsyncFileDialog -
AsyncMessageDialog -
FileHandle -

API

See jsr doc for all APIs.

Contributing

See CONTRIBUTING.md

License

MIT © 2024 Tomoki Miyauchi