Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tauri): webview bundle plugin for tauri v2 #16

Merged
merged 5 commits into from
Nov 1, 2024
Merged

feat(tauri): webview bundle plugin for tauri v2 #16

merged 5 commits into from
Nov 1, 2024

Conversation

seokju-na
Copy link
Owner

Summary

Add webview-bundle-tauri crate is plugin for tauri v2.

See example code below:

use tauri::{Manager, WebviewUrl};
use webview_bundle_tauri::cache::NoopCache;
use webview_bundle_tauri::config::Config;
use webview_bundle_tauri::loader::FSLoader;

fn main() {
  tauri::Builder::default()
    .plugin(webview_bundle_tauri::init("app", |app, _api| {
      let mut dir = app.path().resource_dir()?;
      dir.push("webview-bundles");
      let config = Config::builder()
        .cache(NoopCache::default())
        .loader(FSLoader::from_dir(dir))
        .build();
      Ok(config)
    }))
    .setup(|app| {
      let window = tauri::window::WindowBuilder::new(app, "primary").build()?;
      let webview_builder = tauri::webview::WebviewBuilder::new(
        "primary",
        WebviewUrl::CustomProtocol(url::Url::parse("app://bundle_name").unwrap()),
      );
      let _webview = window.add_child(
        webview_builder,
        tauri::LogicalPosition::new(0, 0),
        window.inner_size().unwrap(),
      );
      Ok(())
    })
    .run(tauri::generate_context!())
    .expect("error while running tauri application");
}

Test Plan

Should pass CI.

## Summary

Add `webview-bundle-tauri` which is tauri plugin for supports webview
bundle system in tauri framework using
[`register_asynchronous_uri_scheme_protocol`](https://docs.rs/tauri/latest/tauri/plugin/struct.Builder.html#method.register_asynchronous_uri_scheme_protocol)
API.

Example code (You can see more in `examples/tauri-simple`):
```rust
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use tauri::{Manager, WebviewUrl};
use webview_bundle_tauri::{Config, FSLoader};

fn main() {
  tauri::Builder::default()
    .plugin(webview_bundle_tauri::init("app", |app, _api| {
      let mut dir = app.path().resource_dir()?;
      dir.pop();
      dir.pop();
      dir.push("examples/tauri-simple");
      let config = Config::builder().loader(FSLoader::from_dir(dir)).build();
      Ok(config)
    }))
    .setup(|app| {
      let window = tauri::window::WindowBuilder::new(app, "primary").build()?;
      let webview_builder = tauri::webview::WebviewBuilder::new(
        "primary",
        WebviewUrl::CustomProtocol(url::Url::parse("app://bundle").unwrap()),
      );
      let _webview = window.add_child(
        webview_builder,
        tauri::LogicalPosition::new(0, 0),
        window.inner_size().unwrap(),
      );
      Ok(())
    })
    .run(tauri::generate_context!())
    .expect("error while running tauri application");
}
```

Tauri v1 supports? => No plan.

## Test Plan

Should pass CI
## Summary

Add cache option for tauri plugin.

## Test Plan

Should pass CI.
## Summary

<!-- Explain the **motivation** for making this change. What existing
problem does the pull request solve?-->

<!-- Link any relevant issues if necessary. -->

## Test Plan

No
@seokju-na seokju-na merged commit 843bd84 into main Nov 1, 2024
10 checks passed
@seokju-na seokju-na deleted the tauri branch November 1, 2024 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant