#tauri-plugin #mobile #view #sharing #viewing

sys tauri-plugin-view

A mobile plugin for Tauri for viewing and sharing files

1 unstable release

new 0.0.5 Nov 16, 2024

#872 in GUI

Download history 96/week @ 2024-11-15

96 downloads per month

MIT license

79KB
460 lines

Contains (JAR file, 44KB) gradle-wrapper.jar

Tauri Mobile View Plugin

A mobile plugin for Tauri for viewing and sharing files.

Installation

npm install tauri-plugin-view-api

src-tauri/Cargo.toml

[dependencies]
tauri-plugin-view = "0.0.5"

src-tauri/src/lib.rs

pub fn run() {
  tauri::Builder::default()
    .plugin(tauri_plugin_view::init())
    .run(tauri::generate_context!())
    .expect("...");
}

src-tauri/capabilities/default.json

"permissions": [
  "core:default",
  "view:allow-view"
]

Android

Application file paths should be replaced with ../

src-tauri/gen/android/app/src/main/res/xml/file_paths.xml

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
  <external-path name="my_images" path="../" />
  <cache-path name="my_cache_images" path="../" />
</paths>

Usage

import { view } from "tauri-plugin-view-api";
import { appDataDir, resolve } from "@tauri-apps/api/path";

const path = await resolve(await appDataDir(), "sample.pdf");

await view(path);

Note: On desktop, view function is noop and just returns the given path.

Contributing

iOS code is in ios/Sources/ViewPlugin.swift, Android code is in android/src/main/java/ViewPlugin.kt and the desktop code is in src/desktop.rs

Pull requests are welcomed.

Dependencies

~18–58MB
~885K SLoC