Skip to content

silvermine/tauri-plugin-download

Repository files navigation

Tauri Plugin Download

CI

State-driven, resumable download API for Tauri 2.x apps.

This plugin provides a cross-platform download interface with resumable downloads, progress tracking, and proper resource management.

Features

  • Parallel, resumable download support
  • Persistable, thread-safe store
  • State and progress notifications
  • Cross-platform support (Linux, Windows, macOS, Android, iOS)
Platform Supported
Linux
Windows
macOS
Android
iOS¹

¹ Supports fully interruptible and resumable background downloads, even when the app is suspended or terminated using URLSession with a background configuration.

Getting Started

Installation

  1. Install NPM dependencies:

    npm install
  2. Build the TypeScript bindings:

    npm run build
  3. Build the Rust plugin:

    cargo build

Tests

Run Rust tests:

cargo test

Install

This plugin requires a Rust version of at least 1.77.2

Rust

Add the plugin to your Cargo.toml:

src-tauri/Cargo.toml

[dependencies]
tauri-plugin-download = { git = "https://github.com/silvermine/tauri-plugin-download" }

JavaScript/TypeScript

Install the JavaScript bindings:

npm install @silvermine/tauri-plugin-download

Usage

Prerequisites

Initialize the plugin in your tauri::Builder:

fn main() {
   tauri::Builder::default()
      .plugin(tauri_plugin_download::init())
      .run(tauri::generate_context!())
      .expect("error while running tauri application");
}

API

Create a download

import { create } from 'tauri-plugin-download';

async function createDownload() {
   const key = 'file.zip',
         url = 'https://example.com/file.zip',
         path = await join(await appDataDir(), 'downloads', key);

   const download = await create(key, url, path);

   console.debug(`Created '${download.key}':${download.url}`);
}

List downloads

import { list } from 'tauri-plugin-download';

async function listDownloads() {
   const downloads = await list();

   for (let download of downloads) {
      console.debug(`Found '${download.key}':${download.url} [${download.state}, ${download.progress}%]`)
   }
}

Get a download

import { get } from 'tauri-plugin-download';

async function getDownload() {
   const download = await get('file.zip');

   console.debug(`Found '${download.key}':${download.url} [${download.state}, ${download.progress}%]`)
}

Start, pause, resume or cancel a download

import { get } from 'tauri-plugin-download';

async function getDownloadAndUpdate() {
   const download = await get('file.zip');

   download.start();
   download.pause();
   download.resume();
   download.cancel();
}

Listen for progress notifications

import { get } from 'tauri-plugin-download';

async function getDownloadAndListen() {
   const download = await get('file.zip');

   const unlisten = await download.listen((updatedDownload) => {
      console.debug(`'${updatedDownload.key}':${updatedDownload.progress}%`);
   });

   // To stop listening
   unlisten();
}

Examples

Check out the examples/tauri-app directory for a working example of how to use this plugin.

Development Standards

This project follows the Silvermine standardization guidelines. Key standards include:

  • EditorConfig: Consistent editor settings across the team
  • Markdownlint: Markdown linting for documentation
  • Commitlint: Conventional commit message format
  • Code Style: 3-space indentation, LF line endings

Running Standards Checks

npm run standards

License

MIT

Contributing

Contributions are welcome! Please follow the established coding standards and commit message conventions.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published