Skip to content

Commit

Permalink
feat(core): always use the custom protocol IPC on Linux (#10840)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Sep 2, 2024
1 parent f0acf50 commit 5048a72
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 16 deletions.
7 changes: 7 additions & 0 deletions .changes/always-enable-linux-ipc-custom-protocol.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"tauri": patch:breaking
"tauri-runtime-wry": patch:breaking
---

The `linux-ipc-protocol` feature is now always enabled, so the Cargo feature flag was removed.
This increases the minimum webkit2gtk version to a release that does not affect the minimum target Linux distros for Tauri apps.
4 changes: 2 additions & 2 deletions crates/tauri-runtime-wry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ wry = { version = "0.42", default-features = false, features = [
"drag-drop",
"protocol",
"os-webview",
"linux-body",
] }
tao = { version = "0.29.1", default-features = false, features = ["rwh_06"] }
tauri-runtime = { version = "2.0.0-rc.7", path = "../tauri-runtime" }
Expand All @@ -41,7 +42,7 @@ features = ["Win32_Foundation", "Win32_Graphics_Dwm"]

[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]
gtk = { version = "0.18", features = ["v3_24"] }
webkit2gtk = { version = "=2.0", features = ["v2_38"] }
webkit2gtk = { version = "=2.0", features = ["v2_40"] }
percent-encoding = "2.1"

[target."cfg(any(target_os = \"ios\", target_os = \"macos\"))".dependencies]
Expand All @@ -58,7 +59,6 @@ macos-private-api = [
"tauri-runtime/macos-private-api",
]
objc-exception = ["wry/objc-exception"]
linux-protocol-body = ["wry/linux-body", "webkit2gtk/v2_40"]
tracing = ["dep:tracing", "wry/tracing"]
macos-proxy = ["wry/mac-proxy"]
unstable = []
6 changes: 1 addition & 5 deletions crates/tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ tray-icon = { version = "0.16", default-features = false, features = [

[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]
gtk = { version = "0.18", features = ["v3_24"] }
webkit2gtk = { version = "=2.0.1", features = ["v2_38"] }
webkit2gtk = { version = "=2.0.1", features = ["v2_40"] }

[target."cfg(target_os = \"macos\")".dependencies]
embed_plist = "1.2"
Expand Down Expand Up @@ -155,10 +155,6 @@ test = []
compression = ["tauri-macros/compression", "tauri-utils/compression"]
wry = ["tauri-runtime-wry"]
objc-exception = ["tauri-runtime-wry/objc-exception"]
linux-ipc-protocol = [
"tauri-runtime-wry/linux-protocol-body",
"webkit2gtk/v2_40",
]
linux-libxdo = ["tray-icon/libxdo", "muda/libxdo"]
isolation = ["tauri-utils/isolation", "tauri-macros/isolation", "uuid"]
custom-protocol = ["tauri-macros/custom-protocol"]
Expand Down
5 changes: 1 addition & 4 deletions crates/tauri/scripts/ipc-protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@
const processIpcMessage = __RAW_process_ipc_message_fn__
const osName = __TEMPLATE_os_name__
const fetchChannelDataCommand = __TEMPLATE_fetch_channel_data_command__
const linuxIpcProtocolEnabled = __TEMPLATE_linux_ipc_protocol_enabled__
let customProtocolIpcFailed = false

// on Linux we only use the custom-protocol-based IPC if the linux-ipc-protocol Cargo feature is enabled
// on Android we never use it because Android does not have support to reading the request body
const canUseCustomProtocol =
osName === 'linux' ? linuxIpcProtocolEnabled : osName !== 'android'
const canUseCustomProtocol = osName !== 'android'

function sendIpcMessage(message) {
const { cmd, callback, error, payload, options } = message
Expand Down
2 changes: 0 additions & 2 deletions crates/tauri/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,6 @@ pub(crate) struct InvokeInitializationScript<'a> {
pub(crate) process_ipc_message_fn: &'a str,
pub(crate) os_name: &'a str,
pub(crate) fetch_channel_data_command: &'a str,
pub(crate) linux_ipc_protocol_enabled: bool,
pub(crate) invoke_key: &'a str,
}

Expand Down Expand Up @@ -1254,7 +1253,6 @@ impl<R: Runtime> Builder<R> {
process_ipc_message_fn: crate::manager::webview::PROCESS_IPC_MESSAGE_FN,
os_name: std::env::consts::OS,
fetch_channel_data_command: crate::ipc::channel::FETCH_CHANNEL_DATA_COMMAND,
linux_ipc_protocol_enabled: cfg!(feature = "linux-ipc-protocol"),
invoke_key: &invoke_key.clone(),
}
.render_default(&Default::default())
Expand Down
2 changes: 1 addition & 1 deletion crates/tauri/src/ipc/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ fn parse_invoke_request<R: Runtime>(
.decode_utf8_lossy()
.to_string();

// on Android and on Linux (without the linux-ipc-protocol Cargo feature) we cannot read the request body
// on Android we cannot read the request body
// so we must ignore it because some commands use the IPC for faster response
let has_payload = !body.is_empty();

Expand Down
1 change: 0 additions & 1 deletion crates/tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
//! - **tracing**: Enables [`tracing`](https://docs.rs/tracing/latest/tracing) for window startup, plugins, `Window::eval`, events, IPC, updater and custom protocol request handlers.
//! - **test**: Enables the [`mod@test`] module exposing unit test helpers.
//! - **objc-exception**: Wrap each msg_send! in a @try/@catch and panics if an exception is caught, preventing Objective-C from unwinding into Rust.
//! - **linux-ipc-protocol**: Use custom protocol for faster IPC on Linux. Requires webkit2gtk v2.40 or above.
//! - **linux-libxdo**: Enables linking to libxdo which enables Cut, Copy, Paste and SelectAll menu items to work on Linux.
//! - **isolation**: Enables the isolation pattern. Enabled by default if the `app > security > pattern > use` config option is set to `isolation` on the `tauri.conf.json` file.
//! - **custom-protocol**: Feature managed by the Tauri CLI. When enabled, Tauri assumes a production environment instead of a development one.
Expand Down
1 change: 0 additions & 1 deletion crates/tauri/src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ pub fn mock_builder() -> Builder<MockRuntime> {
process_ipc_message_fn: crate::manager::webview::PROCESS_IPC_MESSAGE_FN,
os_name: std::env::consts::OS,
fetch_channel_data_command: crate::ipc::channel::FETCH_CHANNEL_DATA_COMMAND,
linux_ipc_protocol_enabled: cfg!(feature = "linux-ipc-protocol"),
invoke_key: INVOKE_KEY,
}
.render_default(&Default::default())
Expand Down

0 comments on commit 5048a72

Please sign in to comment.