Skip to content

armgit / Pake

Public Imported from GitHub
0

Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.

fix: handle niri Wayland AppImage input

Tw9398bcb50ffa92
diff --git a/docs/faq.md b/docs/faq.md
index c42214af..2bd83eae 100644
--- a/docs/faq.md
+++ b/docs/faq.md
@@ -197,6 +197,29 @@ The `NO_STRIP=1` environment variable is the official workaround recommended by
---
+### Linux: AppImage Opens but Buttons or Keyboard Do Not Work on Wayland
+
+**Problem:**
+On some pure Wayland compositors, especially niri, the AppImage can open but page buttons cannot be clicked or keyboard input does not reach the webview.
+
+**Solution:**
+Pake automatically avoids the conservative WebKit rendering flags in niri sessions. To force the same native WebKit path manually, launch the app with:
+
+```bash
+PAKE_LINUX_WEBKIT_SAFE_MODE=0 ./MyApp.AppImage
+```
+
+If your system shows a blank window instead, re-enable the conservative WebKit workaround:
+
+```bash
+PAKE_LINUX_WEBKIT_SAFE_MODE=1 ./MyApp.AppImage
+```
+
+**Why This Happens:**
+Pake normally enables WebKitGTK workarounds that help blank-window cases on Linux, but those same flags can make input and window controls unreliable on some Wayland compositors. The `PAKE_LINUX_WEBKIT_SAFE_MODE` variable lets you choose the safer rendering mode for your compositor.
+
+---
+
### Linux: "cargo: command not found" After Installing Rust
**Problem:**
diff --git a/docs/faq_CN.md b/docs/faq_CN.md
index 401a3fbb..c72847e1 100644
--- a/docs/faq_CN.md
+++ b/docs/faq_CN.md
@@ -197,6 +197,29 @@ docker run --rm --privileged \
---
+### Linux:AppImage 打开后按钮或键盘在 Wayland 下不可用
+
+**问题描述:**
+在某些纯 Wayland 合成器上,尤其是 niri,AppImage 可以打开,但页面按钮无法点击,键盘输入也无法进入 webview。
+
+**解决方案:**
+Pake 会在 niri 会话中自动避开保守的 WebKit 渲染参数。也可以手动强制使用原生 WebKit 渲染路径:
+
+```bash
+PAKE_LINUX_WEBKIT_SAFE_MODE=0 ./MyApp.AppImage
+```
+
+如果你的系统反而出现白屏,可以重新启用保守 WebKit workaround:
+
+```bash
+PAKE_LINUX_WEBKIT_SAFE_MODE=1 ./MyApp.AppImage
+```
+
+**原因:**
+Pake 默认启用的 WebKitGTK workaround 可以缓解 Linux 白屏,但在部分 Wayland 合成器上,这些参数可能导致输入和窗口控件不可用。`PAKE_LINUX_WEBKIT_SAFE_MODE` 可以按当前合成器选择更合适的渲染模式。
+
+---
+
### Linux:"cargo: command not found" 即使已安装 Rust
**问题描述:**
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index 93c6c0f9..9fe7d2a5 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -10,6 +10,12 @@ use tauri_plugin_window_state::StateFlags;
use std::time::Duration;
const WINDOW_SHOW_DELAY: u64 = 50;
+#[cfg(target_os = "linux")]
+const PAKE_LINUX_WEBKIT_SAFE_MODE: &str = "PAKE_LINUX_WEBKIT_SAFE_MODE";
+#[cfg(target_os = "linux")]
+const WEBKIT_DISABLE_DMABUF_RENDERER: &str = "WEBKIT_DISABLE_DMABUF_RENDERER";
+#[cfg(target_os = "linux")]
+const WEBKIT_DISABLE_COMPOSITING_MODE: &str = "WEBKIT_DISABLE_COMPOSITING_MODE";
use app::{
invoke::{
@@ -21,16 +27,83 @@ use app::{
};
use util::get_pake_config;
+#[cfg(any(target_os = "linux", test))]
+fn is_disabled_env_value(value: &str) -> bool {
+ matches!(
+ value.trim().to_ascii_lowercase().as_str(),
+ "0" | "false" | "off" | "no" | "native" | "disabled"
+ )
+}
+
+#[cfg(any(target_os = "linux", test))]
+fn is_non_empty_env_value(value: Option<&str>) -> bool {
+ value.map(|value| !value.trim().is_empty()).unwrap_or(false)
+}
+
+#[cfg(any(target_os = "linux", test))]
+fn contains_niri(value: &str) -> bool {
+ value
+ .split([':', ';', ',', ' '])
+ .any(|part| part.eq_ignore_ascii_case("niri"))
+}
+
+#[cfg(any(target_os = "linux", test))]
+fn should_enable_linux_webkit_safe_mode_from_values(
+ safe_mode: Option<&str>,
+ niri_socket: Option<&str>,
+ desktop_values: &[Option<&str>],
+) -> bool {
+ if let Some(value) = safe_mode.filter(|value| !value.trim().is_empty()) {
+ return !is_disabled_env_value(value);
+ }
+
+ let is_niri_session = is_non_empty_env_value(niri_socket)
+ || desktop_values
+ .iter()
+ .flatten()
+ .any(|value| contains_niri(value));
+
+ !is_niri_session
+}
+
+#[cfg(target_os = "linux")]
+fn apply_linux_webkit_runtime_flags() {
+ let safe_mode = std::env::var(PAKE_LINUX_WEBKIT_SAFE_MODE).ok();
+ if safe_mode.as_deref().is_some_and(is_disabled_env_value) {
+ std::env::remove_var(WEBKIT_DISABLE_DMABUF_RENDERER);
+ std::env::remove_var(WEBKIT_DISABLE_COMPOSITING_MODE);
+ return;
+ }
+
+ let desktop_values = [
+ std::env::var("XDG_CURRENT_DESKTOP").ok(),
+ std::env::var("XDG_SESSION_DESKTOP").ok(),
+ std::env::var("DESKTOP_SESSION").ok(),
+ ];
+ let desktop_refs = desktop_values
+ .iter()
+ .map(|value| value.as_deref())
+ .collect::<Vec<_>>();
+
+ if !should_enable_linux_webkit_safe_mode_from_values(
+ safe_mode.as_deref(),
+ std::env::var("NIRI_SOCKET").ok().as_deref(),
+ &desktop_refs,
+ ) {
+ return;
+ }
+
+ if std::env::var(WEBKIT_DISABLE_DMABUF_RENDERER).is_err() {
+ std::env::set_var(WEBKIT_DISABLE_DMABUF_RENDERER, "1");
+ }
+ if std::env::var(WEBKIT_DISABLE_COMPOSITING_MODE).is_err() {
+ std::env::set_var(WEBKIT_DISABLE_COMPOSITING_MODE, "1");
+ }
+}
+
pub fn run_app() {
#[cfg(target_os = "linux")]
- {
- if std::env::var("WEBKIT_DISABLE_DMABUF_RENDERER").is_err() {
- std::env::set_var("WEBKIT_DISABLE_DMABUF_RENDERER", "1");
- }
- if std::env::var("WEBKIT_DISABLE_COMPOSITING_MODE").is_err() {
- std::env::set_var("WEBKIT_DISABLE_COMPOSITING_MODE", "1");
- }
- }
+ apply_linux_webkit_runtime_flags();
let (pake_config, tauri_config) = get_pake_config();
let tauri_app = tauri::Builder::default();
@@ -202,3 +275,58 @@ pub fn run_app() {
pub fn run() {
run_app()
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn linux_webkit_safe_mode_stays_on_by_default() {
+ assert!(should_enable_linux_webkit_safe_mode_from_values(
+ None,
+ None,
+ &[None, None, None]
+ ));
+ }
+
+ #[test]
+ fn linux_webkit_safe_mode_is_disabled_for_niri_socket() {
+ assert!(!should_enable_linux_webkit_safe_mode_from_values(
+ None,
+ Some("/run/user/501/niri.sock"),
+ &[None, None, None]
+ ));
+ }
+
+ #[test]
+ fn linux_webkit_safe_mode_is_disabled_for_niri_desktop() {
+ assert!(!should_enable_linux_webkit_safe_mode_from_values(
+ None,
+ None,
+ &[Some("niri"), None, None]
+ ));
+ }
+
+ #[test]
+ fn linux_webkit_safe_mode_can_be_forced_on_for_niri() {
+ assert!(should_enable_linux_webkit_safe_mode_from_values(
+ Some("1"),
+ Some("/run/user/501/niri.sock"),
+ &[Some("niri"), None, None]
+ ));
+ }
+
+ #[test]
+ fn linux_webkit_safe_mode_can_be_disabled_explicitly() {
+ for value in ["0", "false", "off", "no", "native", "disabled"] {
+ assert!(
+ !should_enable_linux_webkit_safe_mode_from_values(
+ Some(value),
+ None,
+ &[None, None, None]
+ ),
+ "expected {value} to disable safe mode"
+ );
+ }
+ }
+}