Skip to content

Commit

Permalink
feat: support waydroid (#687)
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveLauC authored Feb 16, 2024
1 parent e4085e0 commit 7a3f3a8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ pub enum Step {
Vcpkg,
Vim,
Vscode,
Waydroid,
Winget,
Wsl,
WslUpdate,
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ fn run() -> Result<()> {
unix::run_brew_formula(&ctx, unix::BrewVariant::Path)
})?;
runner.execute(Step::Lure, "LURE", || linux::run_lure_update(&ctx))?;
runner.execute(Step::Waydroid, "Waydroid", || linux::run_waydroid(&ctx))?;
}

#[cfg(target_os = "macos")]
Expand Down
47 changes: 46 additions & 1 deletion src/steps/os/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::error::{SkipStep, TopgradeError};
use crate::execution_context::ExecutionContext;
use crate::steps::generic::is_wsl;
use crate::steps::os::archlinux;
use crate::terminal::print_separator;
use crate::terminal::{print_separator, prompt_yesno};
use crate::utils::{require, require_option, which, PathExt, REQUIRE_SUDO};
use crate::{Step, HOME_DIR};

Expand Down Expand Up @@ -1020,6 +1020,51 @@ pub fn run_lure_update(ctx: &ExecutionContext) -> Result<()> {
exe.status_checked()
}

pub fn run_waydroid(ctx: &ExecutionContext) -> Result<()> {
let sudo = require_option(ctx.sudo().as_ref(), REQUIRE_SUDO.to_string())?;
let waydroid = require("waydroid")?;
let status = ctx.run_type().execute(&waydroid).arg("status").output_checked_utf8()?;
// example output of `waydroid status`:
//
// ```sh
// $ waydroid status
// Session: RUNNING
// Container: RUNNING
// Vendor type: MAINLINE
// IP address: 192.168.240.112
// Session user: w568w(1000)
// Wayland display: wayland-0
// ```
//
// ```sh
// $ waydroid status
// Session: STOPPED
// Vendor type: MAINLINE
// ```
let session = status
.stdout
.lines()
.find(|line| line.contains("Session:"))
.expect("the output of `waydroid status` should contain `Session:`");
let is_container_running = session.contains("RUNNING");
let assume_yes = ctx.config().yes(Step::Waydroid);

print_separator("Waydroid");

if is_container_running && !assume_yes {
let update_allowed =
prompt_yesno("Going to execute `waydroid upgrade`, which would STOP the running container, is this ok?")?;
if !update_allowed {
return Err(SkipStep("Skip the Waydroid step because the user don't want to proceed".to_string()).into());
}
}
ctx.run_type()
.execute(sudo)
.arg(&waydroid)
.arg("upgrade")
.status_checked()
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 7a3f3a8

Please sign in to comment.