feat(windows, linux): add WebviewWindowBuilder/WebviewBuilder::extensions_path (#11628)

This commit is contained in:
SpikeHD
2024-11-12 15:20:06 -08:00
committed by GitHub
parent 46935212b6
commit dc4d794776
5 changed files with 49 additions and 2 deletions

View File

@@ -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.

View File

@@ -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(),

View File

@@ -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>,
@@ -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,

View File

@@ -42,7 +42,7 @@ use crate::{
use std::{
borrow::Cow,
hash::{Hash, Hasher},
path::PathBuf,
path::{Path, PathBuf},
sync::{Arc, Mutex, MutexGuard},
};
@@ -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

View File

@@ -6,7 +6,7 @@
use std::{
borrow::Cow,
path::PathBuf,
path::{Path, PathBuf},
sync::{Arc, MutexGuard},
};
@@ -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