Skip to content

Commit

Permalink
fix(updater): hide Powershell window when executing updater on windows (
Browse files Browse the repository at this point in the history
#147)

* Hide Powershell window when executing updater on windows

Co-authored-by: Janrupf <[email protected]>

* Update hide-powershell-window.md

---------

Co-authored-by: Janrupf <[email protected]>
  • Loading branch information
jan-br and Janrupf authored Jan 30, 2024
1 parent 57b379a commit 3ee2290
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changes/hide-powershell-window.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"cargo-packager-updater": patch
"@crabnebula/updater": patch
---

Prevent powershell window from opening when the msi and nsis installer are executed.
8 changes: 6 additions & 2 deletions crates/updater/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ impl Update {
// └── ...
#[cfg(windows)]
fn install_inner(&self, bytes: Vec<u8>) -> Result<()> {
use std::{io::Write, process::Command};
use std::{io::Write, os::windows::process::CommandExt, process::Command};

let extension = match self.format {
UpdateFormat::Nsis => ".exe",
Expand All @@ -777,6 +777,8 @@ impl Update {
|p| format!("{p}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"),
);

const CREATE_NO_WINDOW: u32 = 0x08000000;

// we support 2 type of files exe & msi for now
// If it's an `exe` we expect an installer not a runtime.
match self.format {
Expand Down Expand Up @@ -810,7 +812,8 @@ impl Update {

// Run the installer
let mut cmd = Command::new(powershell_path);
cmd.args(["-NoProfile", "-WindowStyle", "Hidden"])
cmd.creation_flags(CREATE_NO_WINDOW)
.args(["-NoProfile", "-WindowStyle", "Hidden"])
.args(["Start-Process"])
.arg(installer_path);
if !installer_args.is_empty() {
Expand Down Expand Up @@ -856,6 +859,7 @@ impl Update {

// run the installer and relaunch the application
let powershell_install_res = Command::new(powershell_path)
.creation_flags(CREATE_NO_WINDOW)
.args(["-NoProfile", "-WindowStyle", "Hidden"])
.args([
"Start-Process",
Expand Down

0 comments on commit 3ee2290

Please sign in to comment.