GithubHelp home page GithubHelp logo

jcbhmr / rfd.js Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 1.0 188 KB

๐Ÿ“‚ Lets you open native file picker and message boxes in JavaScript!

Home Page: https://bindrs.github.io/rfd

License: MIT License

Rust 98.12% JavaScript 1.88%
bindings napi-rs nodejs nodejs-addon rust

rfd.js's Introduction

Rusty File Dialogs for JavaScript

๐Ÿ“‚ Lets you open native file picker and message boxes in JavaScript!

๐Ÿ‘จโ€๐Ÿ’ป Uses your OS' native API
๐Ÿ– Piggy-backs on the Rusty File Dialogs project
๐Ÿ“‚ Lets you open file picker dialogs
๐Ÿ”” Utility alert boxes too!

Installation

npm Yarn pnpm

You can install this package using npm, pnpm, Yarn, or your favorite npm-compatible package manager!

npm install @bindrs/rfd

If you're using Deno, you can use the new npm: specifiers to import this package straight from the npm registry. It's not possible to use an npm CDN because this package uses a .node compiled binary.

import {} from "npm:@bindrs/rfd";

๐Ÿ›‘ This package doesn't work in the browser. It's meant to be used with Node.js, Deno, or Bun which all support .node native addons.

Support matrix
Node.js v16 Node.js v18 Node.js v20
Windows x64 โœ… โœ… โœ…
Windows x32 โŒ โŒ โŒ
Windows arm64 โŒ โŒ โŒ
macOS x64 โœ… โœ… โœ…
macOS arm64 โŒ โŒ โŒ
Linux x64 gnu โœ… โœ… โœ…
Linux x64 musl โŒ โŒ โŒ
Linux arm gnu โŒ โŒ โŒ
Linux arm64 gnu โŒ โŒ โŒ
Linux arm64 musl โŒ โŒ โŒ
Android arm64 โŒ โŒ โŒ
Android armv7 โŒ โŒ โŒ
FreeBSD x64 โŒ โŒ โŒ

Want to add support for your favorite platform? Open a PR! โค๏ธ

Usage

Node.js Deno Bun

import { homedir } from "node:os";
import { AsyncFileDialog } from "@bindrs/rfd";

const fileHandle = await new AsyncFileDialog()
  .addFilter("Images", ["png", "jpg", "jpeg"])
  .addFilter("All Files", ["*"])
  .setTitle("Pick an image")
  .setDirectory(homedir())
  .pickFile();
const path = fileHandle.path();
console.log(`You chose to open ${path}!`);
//=> You chose to open /home/jcbhmr/cool.png!

You can also open message boxes:

import { AsyncMessageDialog } from "@bindrs/rfd";

const answer = await new AsyncMessageDialog()
  .setTitle("Hello!")
  .setDescription("Click OK if you're feeling good ๐Ÿ˜Š")
  .show();
if (answer) {
  console.log("You clicked OK!");
  //=> You clicked OK!
}

๐Ÿ“š Check out the TypeDoc website for more extensive API documentation. You can also refer to the original rfd crate documentation if you want to learn more about the features and limitations inherited from the Rust API.

Development

Rust Node.js

This project uses NAPI-RS to bridge the gap between Rust and JavaScript. Other options like Neon also work, but this seemed the simplest. To get started, you'll need the Rust toolchain installed in addition to the usual Node.js stuff. You'll also need the GTK-3 or other platform-specific libraries installed for your desktop GUI.

To quickly get setup on Ubuntu, you can run the below commands. If you're on Windows, you don't need any extra GUI libraries; those are already all included with the Windows native toolkits!

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
sudo apt install libgtk-3-dev

We use a testing REPL instead of more concrete tests. This is because any concrete test we write won't work in CI because there's no GUI in GitHub Actions! ๐Ÿ˜ญ It's better to just tinker around with it in a REPL.

npm run test:repl

rfd.js's People

Contributors

jcbhmr avatar

Stargazers

 avatar

Watchers

 avatar

rfd.js's Issues

[Milestone] v1

  • Implement the interfaces and stuff described in https://docs.rs/rfd/latest/rfd/
  • Add a basic JavaScript test for CI
  • Create a demo for manual testing
  • Get it to build for Windows
  • Get it to build for macOS
  • #1
  • Release to npm
  • Publish docs website
  • #3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.