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(windows, linux): Add with_extension_path to WebviewBuilder #11628

Merged
merged 8 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changes/extension-path.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"tauri": "minor:feat"
"tauri-runtime": "minor:feat"
"tauri-runtime-wry": "minor:feat"
---

Add `WebviewWindowBuilder/WebviewBuilder::extensions_path` on Linux and Windows.
14 changes: 14 additions & 0 deletions crates/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4283,6 +4283,20 @@ fn create_webview<T: UserEvent>(
.with_browser_extensions_enabled(webview_attributes.browser_extensions_enabled);
}

#[cfg(any(
windows,
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
))]
{
if let Some(path) = &webview_attributes.extensions_path {
webview_builder = webview_builder.with_extension_path(path);
}
}

webview_builder = webview_builder.with_ipc_handler(create_ipc_handler(
kind,
window_id.clone(),
Expand Down
2 changes: 2 additions & 0 deletions crates/tauri-runtime/src/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ pub struct WebviewAttributes {
pub proxy_url: Option<Url>,
pub zoom_hotkeys_enabled: bool,
pub browser_extensions_enabled: bool,
pub extensions_path: Option<PathBuf>,
pub use_https_scheme: bool,
pub devtools: Option<bool>,
pub background_color: Option<Color>,
Expand Down Expand Up @@ -272,6 +273,7 @@ impl WebviewAttributes {
proxy_url: None,
zoom_hotkeys_enabled: false,
browser_extensions_enabled: false,
extensions_path: None,
use_https_scheme: false,
devtools: None,
background_color: None,
Expand Down
14 changes: 13 additions & 1 deletion crates/tauri/src/webview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use crate::{
use std::{
borrow::Cow,
hash::{Hash, Hasher},
path::PathBuf,
path::{Path, PathBuf},
sync::{Arc, Mutex, MutexGuard},
};

Expand Down Expand Up @@ -802,6 +802,18 @@ fn main() {
self
}

/// Set the path from which to load extensions from. Extensions stored in this path should be unpacked Chrome extensions on Windows, and compiled `.so` extensions on Linux.
///
/// ## Platform-specific:
///
/// - **Windows**: Browser extensions must first be enabled. See [`browser_extensions_enabled`](Self::browser_extensions_enabled)
/// - **MacOS / iOS / Android** - Unsupported.
#[must_use]
pub fn extensions_path(mut self, path: impl AsRef<Path>) -> Self {
self.webview_attributes.extensions_path = Some(path.as_ref().to_path_buf());
self
}

/// Sets whether the custom protocols should use `https://<scheme>.localhost` instead of the default `http://<scheme>.localhost` on Windows and Android. Defaults to `false`.
///
/// ## Note
Expand Down
14 changes: 13 additions & 1 deletion crates/tauri/src/webview/webview_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use std::{
borrow::Cow,
path::PathBuf,
path::{Path, PathBuf},
sync::{Arc, MutexGuard},
};

Expand Down Expand Up @@ -906,6 +906,18 @@ impl<'a, R: Runtime, M: Manager<R>> WebviewWindowBuilder<'a, R, M> {
self
}

/// Set the path from which to load extensions from. Extensions stored in this path should be unpacked Chrome extensions on Windows, and compiled `.so` extensions on Linux.
///
/// ## Platform-specific:
///
/// - **Windows**: Browser extensions must first be enabled. See [`browser_extensions_enabled`](Self::browser_extensions_enabled)
/// - **MacOS / iOS / Android** - Unsupported.
#[must_use]
pub fn extensions_path(mut self, path: impl AsRef<Path>) -> Self {
self.webview_builder = self.webview_builder.extensions_path(path);
self
}

/// Sets whether the custom protocols should use `https://<scheme>.localhost` instead of the default `http://<scheme>.localhost` on Windows and Android. Defaults to `false`.
///
/// ## Note
Expand Down