Skip to content

Commit

Permalink
Allow non-systemd and non-appimage systems to use local daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
davnotdev committed Feb 25, 2024
1 parent d937880 commit 866c4a8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
7 changes: 6 additions & 1 deletion burrow-gtk/src/components/settings/daemon_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ use std::process::Command;

#[derive(Debug)]
pub struct DaemonGroup {
system_setup: SystemSetup,
daemon_client: Arc<Mutex<Option<DaemonClient>>>,
already_running: bool,
}

pub struct DaemonGroupInit {
pub daemon_client: Arc<Mutex<Option<DaemonClient>>>,
pub system_setup: SystemSetup,
}

#[derive(Debug)]
Expand All @@ -28,7 +30,9 @@ impl AsyncComponent for DaemonGroup {
#[name(group)]
adw::PreferencesGroup {
#[watch]
set_sensitive: diag::is_appimage() && !model.already_running,
set_sensitive:
(model.system_setup == SystemSetup::AppImage || model.system_setup == SystemSetup::Other) &&
!model.already_running,
set_title: "Local Daemon",
set_description: Some("Run Local Daemon"),

Expand All @@ -46,6 +50,7 @@ impl AsyncComponent for DaemonGroup {
) -> AsyncComponentParts<Self> {
// Should be impossible to panic here
let model = DaemonGroup {
system_setup: init.system_setup,
daemon_client: init.daemon_client.clone(),
already_running: init.daemon_client.lock().await.is_some(),
};
Expand Down
16 changes: 8 additions & 8 deletions burrow-gtk/src/components/settings/diag_group.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use super::*;
use diag::{StatusTernary, SystemSetup};

#[derive(Debug)]
pub struct DiagGroup {
daemon_client: Arc<Mutex<Option<DaemonClient>>>,

init_system: SystemSetup,
system_setup: SystemSetup,
service_installed: StatusTernary,
socket_installed: StatusTernary,
socket_enabled: StatusTernary,
Expand All @@ -14,19 +13,20 @@ pub struct DiagGroup {

pub struct DiagGroupInit {
pub daemon_client: Arc<Mutex<Option<DaemonClient>>>,
pub system_setup: SystemSetup,
}

impl DiagGroup {
async fn new(daemon_client: Arc<Mutex<Option<DaemonClient>>>) -> Result<Self> {
let setup = SystemSetup::new();
let system_setup = SystemSetup::new();
let daemon_running = daemon_client.lock().await.is_some();

Ok(Self {
service_installed: setup.is_service_installed()?,
socket_installed: setup.is_socket_installed()?,
socket_enabled: setup.is_socket_enabled()?,
service_installed: system_setup.is_service_installed()?,
socket_installed: system_setup.is_socket_installed()?,
socket_enabled: system_setup.is_socket_enabled()?,
daemon_running,
init_system: setup,
system_setup,
daemon_client,
})
}
Expand All @@ -52,7 +52,7 @@ impl AsyncComponent for DiagGroup {

adw::ActionRow {
#[watch]
set_title: &format!("System Type: {}", model.init_system)
set_title: &format!("System Type: {}", model.system_setup)
},
adw::ActionRow {
#[watch]
Expand Down
1 change: 1 addition & 0 deletions burrow-gtk/src/components/settings/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::*;
use diag::{StatusTernary, SystemSetup};

mod daemon_group;
mod diag_group;
Expand Down
5 changes: 5 additions & 0 deletions burrow-gtk/src/components/settings_screen.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::*;
use diag::SystemSetup;

pub struct SettingsScreen {
diag_group: AsyncController<settings::DiagGroup>,
Expand Down Expand Up @@ -30,8 +31,11 @@ impl SimpleComponent for SettingsScreen {
root: &Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let system_setup = SystemSetup::new();

let diag_group = settings::DiagGroup::builder()
.launch(settings::DiagGroupInit {
system_setup,
daemon_client: Arc::clone(&init.daemon_client),
})
.forward(sender.input_sender(), |_| {
Expand All @@ -40,6 +44,7 @@ impl SimpleComponent for SettingsScreen {

let daemon_group = settings::DaemonGroup::builder()
.launch(settings::DaemonGroupInit {
system_setup,
daemon_client: Arc::clone(&init.daemon_client),
})
.forward(sender.input_sender(), |_| {
Expand Down
2 changes: 1 addition & 1 deletion burrow-gtk/src/diag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub enum StatusTernary {
// Realistically, we may not explicitly "support" non-systemd platforms which would simply this
// code greatly.
// Along with replacing [`StatusTernary`] with good old [`bool`].
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SystemSetup {
Systemd,
AppImage,
Expand Down

0 comments on commit 866c4a8

Please sign in to comment.