Skip to content

Commit

Permalink
fix: Fixed assertion for startup processes
Browse files Browse the repository at this point in the history
  • Loading branch information
PiotrekPKP committed May 28, 2022
1 parent 252869c commit 07bae2a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
10 changes: 10 additions & 0 deletions src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ pub const API_YOUTUBE_GET_PLAYLIST_ITEMS_URL: &str =

pub const MUSIC_YOUTUBE_URL: &str = "https://www.youtube.com/watch?v={VIDEO_ID}&list={LIST_ID}&index=1";

#[cfg(debug_assertions)]
pub const DBUS_SESSION_NAME: &str = "wm.crab.GDBus.LauncherServerDebug";
#[cfg(debug_assertions)]
pub const DBUS_OBJECT_PATH: &str = "/wm/crab/GDBus/LauncherObjectDebug";
#[cfg(debug_assertions)]
pub const DBUS_INTERFACE_NAME: &str = "wm.crab.GDBus.LauncherInterfaceDebug";

#[cfg(not(debug_assertions))]
pub const DBUS_SESSION_NAME: &str = "wm.crab.GDBus.LauncherServer";
#[cfg(not(debug_assertions))]
pub const DBUS_OBJECT_PATH: &str = "/wm/crab/GDBus/LauncherObject";
#[cfg(not(debug_assertions))]
pub const DBUS_INTERFACE_NAME: &str = "wm.crab.GDBus.LauncherInterface";
16 changes: 8 additions & 8 deletions src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ use gtk::glib::{MainLoop, Variant, VariantTy};
use crate::consts::*;
use crate::gio::glib::Sender;

const INTROSPECTION_XML: &str = "\
<node>\
<interface name='wm.crab.GDBus.LauncherInterface'>\
<method name='ShowWindow'/>\
</interface>\
</node>";

#[derive(Copy, Clone)]
pub enum CrabDaemonMethod {
ShowWindow
Expand Down Expand Up @@ -76,7 +69,14 @@ impl CrabDaemonServer {
}

fn on_bus_acquired(connection: DBusConnection, _name: &str, tx: Sender<bool>) {
let introspection_data = DBusNodeInfo::for_xml(INTROSPECTION_XML).unwrap();
let introspection_xml = format!("\
<node>\
<interface name='{}'>\
<method name='ShowWindow'/>\
</interface>\
</node>", DBUS_INTERFACE_NAME);

let introspection_data = DBusNodeInfo::for_xml(&introspection_xml).unwrap();

let _registration_id = connection.register_object(
DBUS_OBJECT_PATH,
Expand Down
9 changes: 8 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,14 @@ async fn run_daemon() {
fetch_playlists().await;

let s = System::new_all();
let is_running = s.processes_by_exact_name(APP_TITLE).count() > 1;

#[cfg(not(debug_assertions))]
let max_processes = 1;

#[cfg(debug_assertions)]
let max_processes = 2;

let is_running = s.processes_by_exact_name(APP_TITLE).count() > max_processes;

if is_running {
display_err(ERROR_DAEMON);
Expand Down

0 comments on commit 07bae2a

Please sign in to comment.