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 5 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
9 changes: 9 additions & 0 deletions .changes/extension-path.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"tauri": "patch:feat"
"tauri-cli": "patch:feat"
"tauri-runtime": "patch:feat"
"tauri-runtime-wry": "patch:feat"
"tauri-utils": "patch:feat"
amrbashir marked this conversation as resolved.
Show resolved Hide resolved
---

Add `WebviewWindowBuilder/WebviewBuilder::extensions_path` on Linux and Windows.
7 changes: 7 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,13 @@ fn create_webview<T: UserEvent>(
.with_browser_extensions_enabled(webview_attributes.browser_extensions_enabled);
}

#[cfg(any(windows, target_os = "linux"))]
amrbashir marked this conversation as resolved.
Show resolved Hide resolved
{
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
16 changes: 15 additions & 1 deletion crates/tauri-runtime/src/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::{
borrow::Cow,
collections::HashMap,
hash::{Hash, Hasher},
path::PathBuf,
path::{Path, PathBuf},
amrbashir marked this conversation as resolved.
Show resolved Hide resolved
sync::Arc,
};

Expand Down 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 Expand Up @@ -400,6 +402,18 @@ impl WebviewAttributes {
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 set_extensions_path(mut self, path: impl AsRef<Path>) -> Self {
self.extensions_path = Some(path.as_ref().to_path_buf());
self
}
amrbashir marked this conversation as resolved.
Show resolved Hide resolved

/// 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/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
Loading