Skip to content

Commit

Permalink
Fix failure to launch on WSL
Browse files Browse the repository at this point in the history
  • Loading branch information
rgwood committed Feb 29, 2024
1 parent 8c03528 commit 2b81f0e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ clipboard-anywhere = "0.2.2"
chrono = { version = "0.4.31", default-features = false }
lazy_static = "1.4.0"
nix = { version = "0.27.1", features = ["user"] }
is-wsl = "0.4.0"

# build with `cargo build --profile profiling`
# to analyze performance with tooling like perf / samply / superluminal
Expand Down
19 changes: 12 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use systemctl_tui::{
#[derive(Parser, Debug)]
#[command(version = version(), about = "A simple TUI for systemd services")]
struct Args {
/// The scope of the services to display
#[clap(short, long, default_value = "all")]
scope: Scope,
/// The scope of the services to display. Defaults to "all" normally and "global" on WSL
#[clap(short, long)]
scope: Option<Scope>,
/// Enable performance tracing (in Chromium Event JSON format)
#[clap(short, long)]
trace: bool,
Expand All @@ -36,13 +36,18 @@ async fn main() -> Result<()> {
initialize_logging(args.trace)?;
initialize_panic_handler();

// There's probably a nicer way to do this than defining scope in separate places, but this is fine for now
// There's probably a nicer way to do this than defining the scope enum twice, but this is fine for now
let scope = match args.scope {
Scope::Global => systemd::Scope::Global,
Scope::User => systemd::Scope::User,
Scope::All => systemd::Scope::All,
Some(Scope::Global) => systemd::Scope::Global,
Some(Scope::User) => systemd::Scope::User,
Some(Scope::All) => systemd::Scope::All,
// So, WSL doesn't *really* support user services yet: https://github.com/microsoft/WSL/issues/8842
// Revisit this if that changes
None => if is_wsl::is_wsl() { systemd::Scope::Global } else { systemd::Scope::All },
};

eprintln!("Using scope: {:?}", scope);

let mut app = App::new(scope)?;
app.run().await?;

Expand Down

0 comments on commit 2b81f0e

Please sign in to comment.