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 3 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 `with_extension_path` to `WebviewBuilder` for Linux and Windows.
amrbashir marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 7 additions & 0 deletions crates/tauri-cli/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,13 @@
"default": false,
"type": "boolean"
},
"extensionPath": {
"description": "Set the path from which to load extensions from. Extensions stored in this path should be unpacked.\n\n ## Platform-specific:\n\n - **Windows**: Browser extensions must first be enabled. See [`browser_extensions_enabled`](Self::browser_extensions_enabled)\n - **Linux**: Browser extensions do not need to be enabled.\n - **MacOS / iOS / Android** - Unsupported.",
"type": [
"string",
"null"
]
},
"useHttpsScheme": {
"description": "Sets whether the custom protocols should use `https://<scheme>.localhost` instead of the default `http://<scheme>.localhost` on Windows and Android. Defaults to `false`.\n\n ## Note\n\n Using a `https` scheme will NOT allow mixed content when trying to fetch `http` endpoints and therefore will not match the behavior of the `<scheme>://localhost` protocols used on macOS and Linux.\n\n ## Warning\n\n Changing this value between releases will change the IndexedDB, cookies and localstorage location and your app will not be able to access the old data.",
"default": false,
Expand Down
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.extension_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
20 changes: 19 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 extension_path: Option<PathBuf>,
pub use_https_scheme: bool,
pub devtools: Option<bool>,
pub background_color: Option<Color>,
Expand Down Expand Up @@ -247,6 +248,9 @@ impl From<&WindowConfig> for WebviewAttributes {
if let Some(color) = config.background_color {
builder = builder.background_color(color);
}
if let Some(path) = &config.extension_path {
builder = builder.set_extension_path(path);
}
builder
}
}
Expand All @@ -272,6 +276,7 @@ impl WebviewAttributes {
proxy_url: None,
zoom_hotkeys_enabled: false,
browser_extensions_enabled: false,
extension_path: None,
use_https_scheme: false,
devtools: None,
background_color: None,
Expand Down Expand Up @@ -400,6 +405,19 @@ impl WebviewAttributes {
self
}

/// Set the path from which to load extensions from. Extensions stored in this path should be unpacked.
///
/// ## Platform-specific:
///
/// - **Windows**: Browser extensions must first be enabled. See [`browser_extensions_enabled`](Self::browser_extensions_enabled)
/// - **Linux**: Browser extensions do not need to be enabled.
amrbashir marked this conversation as resolved.
Show resolved Hide resolved
/// - **MacOS / iOS / Android** - Unsupported.
#[must_use]
pub fn set_extension_path(mut self, path: impl AsRef<Path>) -> Self {
amrbashir marked this conversation as resolved.
Show resolved Hide resolved
self.extension_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
7 changes: 7 additions & 0 deletions crates/tauri-schema-generator/schemas/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,13 @@
"default": false,
"type": "boolean"
},
"extensionPath": {
"description": "Set the path from which to load extensions from. Extensions stored in this path should be unpacked.\n\n ## Platform-specific:\n\n - **Windows**: Browser extensions must first be enabled. See [`browser_extensions_enabled`](Self::browser_extensions_enabled)\n - **Linux**: Browser extensions do not need to be enabled.\n - **MacOS / iOS / Android** - Unsupported.",
"type": [
"string",
"null"
]
},
"useHttpsScheme": {
"description": "Sets whether the custom protocols should use `https://<scheme>.localhost` instead of the default `http://<scheme>.localhost` on Windows and Android. Defaults to `false`.\n\n ## Note\n\n Using a `https` scheme will NOT allow mixed content when trying to fetch `http` endpoints and therefore will not match the behavior of the `<scheme>://localhost` protocols used on macOS and Linux.\n\n ## Warning\n\n Changing this value between releases will change the IndexedDB, cookies and localstorage location and your app will not be able to access the old data.",
"default": false,
Expand Down
13 changes: 13 additions & 0 deletions crates/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1656,6 +1656,16 @@ pub struct WindowConfig {
#[serde(default, alias = "browser-extensions-enabled")]
pub browser_extensions_enabled: bool,

/// Set the path from which to load extensions from. Extensions stored in this path should be unpacked.
///
/// ## Platform-specific:
///
/// - **Windows**: Browser extensions must first be enabled. See [`browser_extensions_enabled`](Self::browser_extensions_enabled)
/// - **Linux**: Browser extensions do not need to be enabled.
/// - **MacOS / iOS / Android** - Unsupported.
#[serde(default, alias = "extensions-path")]
pub extension_path: Option<PathBuf>,
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 Expand Up @@ -1736,6 +1746,7 @@ impl Default for WindowConfig {
proxy_url: None,
zoom_hotkeys_enabled: false,
browser_extensions_enabled: false,
extension_path: None,
use_https_scheme: false,
devtools: None,
background_color: None,
Expand Down Expand Up @@ -2989,6 +3000,7 @@ mod build {
let parent = opt_str_lit(self.parent.as_ref());
let zoom_hotkeys_enabled = self.zoom_hotkeys_enabled;
let browser_extensions_enabled = self.browser_extensions_enabled;
let extension_path = opt_lit(self.extension_path.as_ref().map(path_buf_lit).as_ref());
let use_https_scheme = self.use_https_scheme;
let devtools = opt_lit(self.devtools.as_ref());
let background_color = opt_lit(self.background_color.as_ref());
Expand Down Expand Up @@ -3040,6 +3052,7 @@ mod build {
parent,
zoom_hotkeys_enabled,
browser_extensions_enabled,
extension_path,
use_https_scheme,
devtools,
background_color
Expand Down
15 changes: 14 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,19 @@ fn main() {
self
}

/// Set the path from which to load extensions from. Extensions stored in this path should be unpacked.
///
/// ## Platform-specific:
///
/// - **Windows**: Browser extensions must first be enabled. See [`browser_extensions_enabled`](Self::browser_extensions_enabled)
/// - **Linux**: Browser extensions do not need to be enabled.
amrbashir marked this conversation as resolved.
Show resolved Hide resolved
/// - **MacOS / iOS / Android** - Unsupported.
#[must_use]
pub fn extension_path(mut self, path: impl AsRef<Path>) -> Self {
amrbashir marked this conversation as resolved.
Show resolved Hide resolved
self.webview_attributes.extension_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
15 changes: 14 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,19 @@ 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.
///
/// ## Platform-specific:
///
/// - **Windows**: Browser extensions must first be enabled. See [`browser_extensions_enabled`](Self::browser_extensions_enabled)
/// - **Linux**: Browser extensions do not need to be enabled.
amrbashir marked this conversation as resolved.
Show resolved Hide resolved
/// - **MacOS / iOS / Android** - Unsupported.
#[must_use]
pub fn extension_path(mut self, path: impl AsRef<Path>) -> Self {
amrbashir marked this conversation as resolved.
Show resolved Hide resolved
self.webview_builder = self.webview_builder.extension_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