Skip to content

Commit

Permalink
Don't run gnome shell extensions if unneeded (fix r-darwish#835) (r-d…
Browse files Browse the repository at this point in the history
…arwish#893)

* Don't call gnome shell extensions if it's not registered in dbus (fix r-darwish#835)

* fix

* Execute-elevated (r-darwish#892)

* Introduce the execute elevated method (fix r-darwish#885)

* fmt

* Fix nix with doas

* Bad import

* No gnome in macOS

* Unused imports
  • Loading branch information
r-darwish authored Apr 11, 2022
1 parent 9ed518c commit d0e1212
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ fn run() -> Result<()> {
runner.execute(Step::Tmux, "tmux", || tmux::run_tpm(&base_dirs, run_type))?;
runner.execute(Step::Tldr, "TLDR", || unix::run_tldr(run_type))?;
runner.execute(Step::Pearl, "pearl", || unix::run_pearl(run_type))?;
#[cfg(not(target_os = "macos"))]
runner.execute(Step::GnomeShellExtensions, "Gnome Shell Extensions", || {
unix::upgrade_gnome_extensions(&ctx)
})?;
Expand Down
27 changes: 23 additions & 4 deletions src/steps/os/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
use crate::error::SkipStep;
use crate::error::TopgradeError;
use crate::execution_context::ExecutionContext;
#[cfg(target_os = "macos")]
use crate::executor::CommandExt;
use crate::executor::{Executor, ExecutorExitStatus, RunType};
use crate::executor::{CommandExt, Executor, ExecutorExitStatus, RunType};
use crate::terminal::print_separator;
use crate::utils::{require, require_option, PathExt};
#[cfg(not(target_os = "macos"))]
use crate::utils::require_option;
use crate::utils::{require, PathExt};
use crate::Step;
use anyhow::Result;
use directories::BaseDirs;
Expand Down Expand Up @@ -135,12 +135,31 @@ pub fn run_fish_plug(ctx: &ExecutionContext) -> Result<()> {
ctx.run_type().execute(&fish).args(&["-c", "plug update"]).check_run()
}

#[cfg(not(target_os = "macos"))]
pub fn upgrade_gnome_extensions(ctx: &ExecutionContext) -> Result<()> {
let gdbus = require("gdbus")?;
require_option(
env::var("XDG_CURRENT_DESKTOP").ok().filter(|p| p.contains("GNOME")),
"Desktop doest not appear to be gnome".to_string(),
)?;
let output = Command::new("gdbus")
.args(&[
"call",
"--session",
"--dest",
"org.freedesktop.DBus",
"--object-path",
"/org/freedesktop/DBus",
"--method",
"org.freedesktop.DBus.ListActivatableNames",
])
.check_output()?;

debug!("Checking for gnome extensions: {}", output);
if !output.contains("org.gnome.Shell.Extensions") {
return Err(SkipStep(String::from("Gnome shell extensions are unregistered in DBus")).into());
}

print_separator("Gnome Shell extensions");

ctx.run_type()
Expand Down

0 comments on commit d0e1212

Please sign in to comment.