diff --git a/.github/release-nest-v3 b/.github/release-nest-v3 index 3cacc0b..ca7bf83 100644 --- a/.github/release-nest-v3 +++ b/.github/release-nest-v3 @@ -1 +1 @@ -12 \ No newline at end of file +13 \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index f6edff3..16332af 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -526,7 +526,7 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38e2275cc4e4fc009b0669731a1e5ab7ebf11f469eaede2bab9309a5b4d6057f" dependencies = [ - "memoffset", + "memoffset 0.9.1", "rustc_version 0.4.0", ] @@ -1441,6 +1441,15 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +[[package]] +name = "memoffset" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +dependencies = [ + "autocfg", +] + [[package]] name = "memoffset" version = "0.9.1" @@ -1546,6 +1555,19 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "nix" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f3790c00a0150112de0f4cd161e3d7fc4b2d8a5542ffc35f099a2562aecb35c" +dependencies = [ + "bitflags 1.3.2", + "cc", + "cfg-if 1.0.0", + "libc", + "memoffset 0.6.5", +] + [[package]] name = "normpath" version = "1.2.0" @@ -1759,6 +1781,7 @@ dependencies = [ "rust-i18n", "serde", "serde_json", + "single-instance", "strfmt", "tokio", "tokio-uds", @@ -2223,6 +2246,19 @@ dependencies = [ "libc", ] +[[package]] +name = "single-instance" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4637485391f8545c9d3dbf60f9d9aab27a90c789a700999677583bcb17c8795d" +dependencies = [ + "libc", + "nix", + "thiserror", + "widestring", + "winapi 0.3.9", +] + [[package]] name = "slab" version = "0.4.9" @@ -2863,6 +2899,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "widestring" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c168940144dd21fd8046987c16a46a33d5fc84eec29ef9dcddc2ac9e31526b7c" + [[package]] name = "winapi" version = "0.2.8" diff --git a/Cargo.toml b/Cargo.toml index 18d0297..a67b120 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,4 +45,5 @@ reqwest = { version = "0.11", features = ["blocking"] } strfmt = "0.2.4" configparser = "3.1.0" ksni = "0.2.2" +single-instance = "0.3.3" diff --git a/debian/changelog b/debian/changelog index cbf186f..c30531e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -pikman-update-manager (1.0.1-100pika3) pikauwu; urgency=medium +pikman-update-manager (1.0.1-100pika4) pikauwu; urgency=medium * initial release diff --git a/src/bin/apt/apt_update/main.rs b/src/bin/apt/apt_update/main.rs index ef76573..d49f547 100644 --- a/src/bin/apt/apt_update/main.rs +++ b/src/bin/apt/apt_update/main.rs @@ -13,6 +13,10 @@ i18n!("locales", fallback = "en_US"); fn main() { let args: Vec = env::args().collect(); rust_i18n::set_locale(&args[1]); + let instance = single_instance::SingleInstance::new( + "com.github.pikaos-linux.pikmanupdatemanager.update.manager", + ) + .unwrap(); let hit_strfmt_trans_str = t!("apt_update_str_hit").to_string(); let fetch_strfmt_trans_str = t!("apt_update_str_fetch").to_string(); @@ -41,4 +45,6 @@ fn main() { panic!("{}", e.to_string()) } }; + + assert!(!instance.is_single()); } diff --git a/src/bin/gui/apt_update_page/mod.rs b/src/bin/gui/apt_update_page/mod.rs index 5e1df5a..5f1d767 100644 --- a/src/bin/gui/apt_update_page/mod.rs +++ b/src/bin/gui/apt_update_page/mod.rs @@ -65,27 +65,42 @@ pub fn apt_update_page( }); thread::spawn(move || { - let apt_update_command = Command::new("pkexec") - .args([ - "/usr/lib/pika/pikman-update-manager/scripts/apt_update", - "fr_FR", - ]) - .status() - .unwrap(); - match apt_update_command.code().unwrap() { - 0 => update_status_sender_clone0 - .send_blocking("FN_OVERRIDE_SUCCESSFUL".to_owned()) - .unwrap(), - 53 => {} - _ => { - update_status_sender_clone0 - .send_blocking(t!("update_status_error_perms").to_string()) - .unwrap(); - update_status_sender_clone0 - .send_blocking("FN_OVERRIDE_FAILED".to_owned()) + let instance = single_instance::SingleInstance::new( + "com.github.pikaos-linux.pikmanupdatemanager.update.manager", + ) + .unwrap(); + if instance.is_single() { + let current_locale = match std::env::var_os("LANG") { + Some(v) => v + .into_string() .unwrap() + .chars() + .take_while(|&ch| ch != '.') + .collect::(), + None => panic!("$LANG is not set"), + }; + let apt_update_command = Command::new("pkexec") + .args([ + "/usr/lib/pika/pikman-update-manager/scripts/apt_update", + ¤t_locale, + ]) + .status() + .unwrap(); + match apt_update_command.code().unwrap() { + 0 => update_status_sender_clone0 + .send_blocking("FN_OVERRIDE_SUCCESSFUL".to_owned()) + .unwrap(), + 53 => {} + _ => { + update_status_sender_clone0 + .send_blocking(t!("update_status_error_perms").to_string()) + .unwrap(); + update_status_sender_clone0 + .send_blocking("FN_OVERRIDE_FAILED".to_owned()) + .unwrap() + } } - } + }; }); let main_box = Box::builder() diff --git a/src/bin/gui/apt_update_page/process.rs b/src/bin/gui/apt_update_page/process.rs index e59d72e..46b676f 100644 --- a/src/bin/gui/apt_update_page/process.rs +++ b/src/bin/gui/apt_update_page/process.rs @@ -411,8 +411,20 @@ fn apt_full_upgrade_from_socket( }); thread::spawn(move || { + let current_locale = match std::env::var_os("LANG") { + Some(v) => v + .into_string() + .unwrap() + .chars() + .take_while(|&ch| ch != '.') + .collect::(), + None => panic!("$LANG is not set"), + }; let apt_upgrade_command = Command::new("pkexec") - .args(["/usr/lib/pika/pikman-update-manager/scripts/apt_full_upgrade"]) + .args([ + "/usr/lib/pika/pikman-update-manager/scripts/apt_full_upgrade", + ¤t_locale, + ]) .status() .unwrap(); match apt_upgrade_command.code().unwrap() { diff --git a/src/bin/gui/build_ui/mod.rs b/src/bin/gui/build_ui/mod.rs index 5ad3a44..2b25660 100644 --- a/src/bin/gui/build_ui/mod.rs +++ b/src/bin/gui/build_ui/mod.rs @@ -134,8 +134,8 @@ pub fn build_ui(app: &Application) { update_sys_tray.connect_activate(clone!( #[strong] tray_handle, - #[strong] - refresh_button, + /*#[strong] + refresh_button,*/ move |_, param| { let array: &[i32] = param.unwrap().fixed_array().unwrap(); let vec = array.to_vec(); @@ -175,7 +175,7 @@ pub fn build_ui(app: &Application) { .unwrap(), ); }); - if apt_update_count == -1 || flatpak_update_count == -1 { + /*if apt_update_count == -1 || flatpak_update_count == -1 { refresh_button.set_sensitive(false); refresh_button.set_tooltip_text(Some( &t!("pikman_indicator_flatpak_item_label_calculating").to_string(), @@ -184,7 +184,7 @@ pub fn build_ui(app: &Application) { refresh_button.set_sensitive(true); refresh_button .set_tooltip_text(Some(&t!("refresh_button_tooltip_text").to_string())); - } + }*/ } )); update_sys_tray.activate(Some(&glib::Variant::array_from_fixed_array(&[-1, -1])));