Don't run gnome shell extensions if unneeded (fix #835) (#893)

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

* fix

* Execute-elevated (#892)

* Introduce the execute elevated method (fix #885)

* fmt

* Fix nix with doas

* Bad import

* No gnome in macOS

* Unused imports
This commit is contained in:
Roey Darwish Dror 2022-04-11 20:15:18 +03:00 committed by GitHub
parent 9ed518c82a
commit d0e1212700
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 4 deletions

View File

@ -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)
})?;

View File

@ -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;
@ -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()