refactor: cleanup

This commit is contained in:
zhom
2026-06-24 02:00:44 +04:00
parent fe3ae13928
commit 8588a44fb5
22 changed files with 172 additions and 82 deletions
+4 -4
View File
@@ -1492,7 +1492,7 @@ impl AppAutoUpdater {
// Create the restart script content
let script_content = format!(
r#"#!/bin/bash
r#"#!/bin/sh
# Wait for the current process to exit
while kill -0 {} 2>/dev/null; do
sleep 0.5
@@ -1521,7 +1521,7 @@ rm "{}"
.output();
// Execute the restart script in the background
let mut cmd = Command::new("bash");
let mut cmd = Command::new("sh");
cmd.arg(script_path.to_str().unwrap());
// Detach the process completely
@@ -1668,7 +1668,7 @@ rm "{}"
// Create the restart script content
let script_content = format!(
r#"#!/bin/bash
r#"#!/bin/sh
# Wait for the current process to exit
while kill -0 {} 2>/dev/null; do
sleep 0.5
@@ -1697,7 +1697,7 @@ rm "{}"
.output();
// Execute the restart script in the background
let mut cmd = Command::new("bash");
let mut cmd = Command::new("sh");
cmd.arg(script_path.to_str().unwrap());
// Detach the process completely
+24 -8
View File
@@ -85,7 +85,11 @@ impl GroupManager {
// Check if group with this name already exists
if groups_data.groups.iter().any(|g| g.name == name) {
return Err(format!("Group with name '{name}' already exists").into());
return Err(
serde_json::json!({ "code": "GROUP_ALREADY_EXISTS" })
.to_string()
.into(),
);
}
let sync_enabled = crate::sync::is_sync_configured();
@@ -131,14 +135,18 @@ impl GroupManager {
.iter()
.any(|g| g.name == name && g.id != id)
{
return Err(format!("Group with name '{name}' already exists").into());
return Err(
serde_json::json!({ "code": "GROUP_ALREADY_EXISTS" })
.to_string()
.into(),
);
}
let group = groups_data
.groups
.iter_mut()
.find(|g| g.id == id)
.ok_or_else(|| format!("Group with id '{id}' not found"))?;
.ok_or_else(|| serde_json::json!({ "code": "GROUP_NOT_FOUND" }).to_string())?;
group.name = name;
group.updated_at = Some(crate::proxy_manager::now_secs());
@@ -204,7 +212,11 @@ impl GroupManager {
let initial_len = groups_data.groups.len();
groups_data.groups.retain(|g| g.id != id);
if groups_data.groups.len() == initial_len {
return Err(format!("Group with id '{id}' not found").into());
return Err(
serde_json::json!({ "code": "GROUP_NOT_FOUND" })
.to_string()
.into(),
);
}
self.save_groups_data(&groups_data)?;
Ok(())
@@ -229,7 +241,11 @@ impl GroupManager {
groups_data.groups.retain(|g| g.id != id);
if groups_data.groups.len() == initial_len {
return Err(format!("Group with id '{id}' not found").into());
return Err(
serde_json::json!({ "code": "GROUP_NOT_FOUND" })
.to_string()
.into(),
);
}
self.save_groups_data(&groups_data)?;
@@ -334,7 +350,7 @@ pub async fn create_profile_group(
let group_manager = GROUP_MANAGER.lock().unwrap();
group_manager
.create_group(&app_handle, name)
.map_err(|e| format!("Failed to create group: {e}"))
.map_err(|e| e.to_string())
}
#[tauri::command]
@@ -346,7 +362,7 @@ pub async fn update_profile_group(
let group_manager = GROUP_MANAGER.lock().unwrap();
group_manager
.update_group(&app_handle, group_id, name)
.map_err(|e| format!("Failed to update group: {e}"))
.map_err(|e| e.to_string())
}
#[tauri::command]
@@ -357,7 +373,7 @@ pub async fn delete_profile_group(
let group_manager = GROUP_MANAGER.lock().unwrap();
group_manager
.delete_group(&app_handle, group_id)
.map_err(|e| format!("Failed to delete group: {e}"))
.map_err(|e| e.to_string())
}
#[tauri::command]
+13 -7
View File
@@ -634,19 +634,25 @@ pub mod linux {
}
}
// Additional Linux-specific environment variables for better compatibility
cmd.env(
"DISPLAY",
std::env::var("DISPLAY").unwrap_or(":0".to_string()),
);
// Propagate DISPLAY only when this session actually has an X11 display.
// Forcing DISPLAY=:0 breaks Wayland-only sessions (there is no X server on
// :0, so any X11 client launched with it set will fail to connect). When
// DISPLAY is set the child already inherits it from our environment, so
// setting it explicitly here is purely defensive; when it's unset we leave
// it unset and let the browser use Wayland.
if let Ok(display) = std::env::var("DISPLAY") {
cmd.env("DISPLAY", display);
}
// Set MOZ_ENABLE_WAYLAND for better Wayland support
if std::env::var("WAYLAND_DISPLAY").is_ok() {
cmd.env("MOZ_ENABLE_WAYLAND", "1");
}
// Disable GPU acceleration if running in headless environments
if std::env::var("DISPLAY").is_err() || std::env::var("WAYLAND_DISPLAY").is_err() {
// Warn only when running truly headless — i.e. NEITHER X11 nor Wayland is
// available. Using OR here would fire on every normal Wayland-only session
// (DISPLAY unset) or X11-only session (WAYLAND_DISPLAY unset).
if std::env::var("DISPLAY").is_err() && std::env::var("WAYLAND_DISPLAY").is_err() {
log::info!("No display detected, browser may fail to start");
}