Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(microsoft_store): Add Microsoft Store step for Windows #963

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions locales/app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -610,3 +610,19 @@ _version: 2
en: "Windows Update"
es: "Actualización de Windows"
zh_TW: "Windows 更新"
"Microsoft Store":
en: "Microsoft Store"
es: "Tienda de Microsoft"
zh_TW: "Microsoft 店鋪"
"Scanning for updates...":
en: "Scanning for updates..."
es: "Buscando actualizaciones..."
zh_TW: "正在掃描更新..."
"Success, Microsoft Store apps are being updated in the background":
en: "Success, Microsoft Store apps are being updated in the background"
es: "Éxito, las aplicaciones de Microsoft Store se están actualizando en segundo plano"
zh_TW: "成功,Microsoft Store 應用程式正在後台更新"
"Unable to update Microsoft Store apps, manual intervention is required":
en: "Unable to update Microsoft Store apps, manual intervention is required"
es: "No se pueden actualizar las aplicaciones de Microsoft Store, se requiere intervención manual"
zh_TW: "無法更新 Microsoft Store 應用,需手動幹預"
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ pub enum Step {
Mas,
Maza,
Micro,
MicrosoftStore,
Mise,
Myrepos,
Nix,
Expand Down
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ fn run() -> Result<()> {
runner.execute(Step::Scoop, "Scoop", || windows::run_scoop(&ctx))?;
runner.execute(Step::Winget, "Winget", || windows::run_winget(&ctx))?;
runner.execute(Step::System, "Windows update", || windows::windows_update(&ctx))?;
runner.execute(Step::MicrosoftStore, "Microsoft Store", || {
windows::microsoft_store(&ctx)
})?;
}

#[cfg(target_os = "linux")]
Expand Down
8 changes: 8 additions & 0 deletions src/steps/os/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ pub fn windows_update(ctx: &ExecutionContext) -> Result<()> {
}
}

pub fn microsoft_store(ctx: &ExecutionContext) -> Result<()> {
let powershell = powershell::Powershell::windows_powershell();

print_separator(t!("Microsoft Store"));

powershell.microsoft_store(ctx)
}

pub fn reboot() -> Result<()> {
// If this works, it won't return, but if it doesn't work, it may return a useful error
// message.
Expand Down
39 changes: 39 additions & 0 deletions src/steps/powershell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,43 @@ impl Powershell {
.args(["-NoProfile", &install_windowsupdate_verbose, accept_all])
.status_checked()
}

#[cfg(windows)]
pub fn microsoft_store(&self, ctx: &ExecutionContext) -> Result<()> {
let powershell = require_option(self.path.as_ref(), t!("Powershell is not installed").to_string())?;

let mut command = if let Some(sudo) = ctx.sudo() {
let mut command = ctx.run_type().execute(sudo);
command.arg(powershell);
command
} else {
ctx.run_type().execute(powershell)
};

println!("{}", t!("Scanning for updates..."));

// Scan for updates using the MDM UpdateScanMethod
// This method is also available for non-MDM devices
let update_command = "(Get-CimInstance -Namespace \"Root\\cimv2\\mdm\\dmmap\" -ClassName \"MDM_EnterpriseModernAppManagement_AppManagement01\" | Invoke-CimMethod -MethodName UpdateScanMethod).ReturnValue";

command.args(["-NoProfile", update_command]);

command
.output_checked_with_utf8(|output| {
if output.stdout.trim() == "0" {
println!(
"{}",
t!("Success, Microsoft Store apps are being updated in the background")
);
Ok(())
} else {
println!(
"{}",
t!("Unable to update Microsoft Store apps, manual intervention is required")
);
Err(())
}
})
.map(|_| ())
}
}