Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 20 additions & 8 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,15 +806,22 @@ fn open_captcha_window(app: &AppHandle, auto: bool) -> Result<(), String> {
}
return Ok(());
}
let win = tauri::WebviewWindowBuilder::new(
// Linux: window background_color 会让 WebKitGTK(2.5x) 整个 webview 不渲染(黑屏),
// 前端页面自带深色背景,这里仅在非 Linux 平台设置以避免启动白闪。
#[allow(unused_mut)]
let mut builder = tauri::WebviewWindowBuilder::new(
app,
"captcha",
tauri::WebviewUrl::App("captcha.html".into()),
)
.title(i18n::tr("title.captcha"))
.theme(Some(tauri::Theme::Dark))
.background_color(tauri::window::Color(10, 10, 12, 255))
.inner_size(w, h)
.theme(Some(tauri::Theme::Dark));
#[cfg(not(target_os = "linux"))]
{
builder = builder.background_color(tauri::window::Color(10, 10, 12, 255));
}
let win = builder
.inner_size(w, h)
.min_inner_size(340.0, 280.0)
.maximizable(false)
.resizable(false)
Expand Down Expand Up @@ -907,15 +914,20 @@ async fn open_settings(app: AppHandle) -> Result<(), String> {
let _ = win.set_focus();
return Ok(());
}
let win = tauri::WebviewWindowBuilder::new(
#[allow(unused_mut)]
let mut builder = tauri::WebviewWindowBuilder::new(
&app,
"settings",
tauri::WebviewUrl::App("settings.html".into()),
)
.title(i18n::tr("title.settings"))
.theme(Some(tauri::Theme::Dark))
.background_color(tauri::window::Color(10, 10, 12, 255))
.inner_size(w, h)
.theme(Some(tauri::Theme::Dark));
#[cfg(not(target_os = "linux"))]
{
builder = builder.background_color(tauri::window::Color(10, 10, 12, 255));
}
let win = builder
.inner_size(w, h)
.min_inner_size(440.0, 540.0)
.resizable(true)
.additional_browser_args("--disable-features=msWebOOUI,msPdfOOUI,msSmartScreenProtection --no-proxy-server")
Expand Down
15 changes: 15 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,22 @@ fn ensure_cli_console() {
}
}

#[cfg(target_os = "linux")]
fn linux_webkit_workaround() {
// WebKitGTK 的 DMABUF 渲染器在 Wayland 下会触发 Gdk Error 71(protocol
// error)直接崩溃,NVIDIA 驱动上必现。回退到旧渲染路径。
let on_wayland = match std::env::var("WAYLAND_DISPLAY") {
Ok(v) => !v.trim().is_empty(),
Err(_) => std::env::var("XDG_SESSION_TYPE").map(|v| v.trim() == "wayland").unwrap_or(false),
};
if on_wayland && std::env::var_os("WEBKIT_DISABLE_DMABUF_RENDERER").is_none() {
std::env::set_var("WEBKIT_DISABLE_DMABUF_RENDERER", "1");
}
}

fn main() {
#[cfg(target_os = "linux")]
linux_webkit_workaround();
let args: Vec<String> = std::env::args().collect();
if let Some(pos) = args.iter().position(|a| a == "--cli") {
let cli_args: Vec<String> = args.iter().skip(pos + 1).cloned().collect();
Expand Down
34 changes: 28 additions & 6 deletions src-tauri/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,29 @@ pub fn zcode_running() -> bool {
return false;
}
["zcode", "ZCode"].iter().any(|name| {
no_window("pgrep")
.args(["-x", name])
.output()
.map(|o| o.status.success())
.unwrap_or(false)
let out = match no_window("pgrep").args(["-x", name]).output() {
Ok(o) => o,
Err(_) => return false,
};
if !out.status.success() {
return false;
}
// pgrep 会把僵尸进程也算匹配上;我们 spawn 的 ZCode 退出后若尚未回收
// 就是僵尸,必须按进程状态排除,否则强制切换的 kill 会误判超时。
String::from_utf8_lossy(&out.stdout)
.split_whitespace()
.any(|pid| {
no_window("ps")
.args(["-o", "state=", "-p", pid])
.output()
.ok()
.map(|o| {
let st = String::from_utf8_lossy(&o.stdout);
let st = st.trim();
!st.is_empty() && !st.starts_with('Z')
})
.unwrap_or(false)
})
})
}

Expand Down Expand Up @@ -398,9 +416,13 @@ pub fn launch_zcode(path: &str) -> Result<(), String> {
if !p.exists() {
return Err(trf("err.zcode.missing", &[("path", path)]));
}
detached(Command::new(&p))
let mut child = detached(Command::new(&p))
.spawn()
.map_err(|e| trf("err.zcode.launch", &[("e", &e.to_string())]))?;
// 后台回收,避免 ZCode 退出后残留僵尸进程(详见 zcode_running 注释)。
std::thread::spawn(move || {
let _ = child.wait();
});
Ok(())
}

Expand Down
17 changes: 17 additions & 0 deletions src-tauri/tauri.linux.conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"app": {
"windows": [
{
"title": "Z·SWITCH",
"width": 680,
"height": 820,
"minWidth": 520,
"minHeight": 640,
"resizable": true,
"center": true,
"theme": "Dark",
"additionalBrowserArgs": "--disable-features=msWebOOUI,msPdfOOUI,msSmartScreenProtection --no-proxy-server"
}
]
}
}