Skip to content

Commit 9aa0e62

Browse files
committed
fix: updater lanza PowerShell interactivo (UAC)
1 parent 8a55073 commit 9aa0e62

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

app/ui/frames/settings/tabs/updates_tab.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,16 +197,26 @@ def _worker():
197197
ps_script = f"""param([int]$Pid, [string]$Installer, [string]$ExePath, [string]$LogPath)\n\n$ErrorActionPreference = 'Stop'\n\nfunction Log([string]$Msg) {{\n $ts = (Get-Date).ToString('yyyy-MM-dd HH:mm:ss')\n \"$ts $Msg\" | Out-File -FilePath $LogPath -Encoding UTF8 -Append\n}}\n\nLog \"update: waiting pid=$Pid\"\nwhile (Get-Process -Id $Pid -ErrorAction SilentlyContinue) {{ Start-Sleep -Milliseconds 250 }}\n\ntry {{\n Log \"update: starting installer=$Installer\"\n # Inno Setup suele requerir elevacion para Program Files.\n $p = Start-Process -FilePath $Installer -ArgumentList '/SP- /VERYSILENT /SUPPRESSMSGBOXES /NORESTART' -Verb RunAs -Wait -PassThru\n Log \"update: installer exitcode=$($p.ExitCode)\"\n if ($p.ExitCode -eq 0) {{\n Log \"update: relaunch $ExePath\"\n Start-Process -FilePath $ExePath\n }} else {{\n Log \"update: install failed\"\n }}\n}} catch {{\n Log \"update: exception $($_.Exception.Message)\"\n}}\n"""
198198
ps_path.write_text(ps_script, encoding="utf-8")
199199

200-
creationflags = 0
201-
creationflags |= getattr(subprocess, "DETACHED_PROCESS", 0)
202-
creationflags |= getattr(subprocess, "CREATE_NEW_PROCESS_GROUP", 0)
200+
# Nota: DETACHED_PROCESS puede hacer que el UAC / elevación no aparezca.
201+
# Preferimos ocultar la ventana de PowerShell pero mantenerlo interactivo.
202+
creationflags = getattr(subprocess, "CREATE_NEW_PROCESS_GROUP", 0)
203+
startupinfo = None
204+
if os.name == "nt" and hasattr(subprocess, "STARTUPINFO"):
205+
try:
206+
startupinfo = subprocess.STARTUPINFO()
207+
startupinfo.dwFlags |= getattr(subprocess, "STARTF_USESHOWWINDOW", 0)
208+
startupinfo.wShowWindow = 0 # SW_HIDE
209+
except Exception:
210+
startupinfo = None
203211

204212
subprocess.Popen(
205213
[
206214
"powershell",
207215
"-NoProfile",
208216
"-ExecutionPolicy",
209217
"Bypass",
218+
"-WindowStyle",
219+
"Hidden",
210220
"-File",
211221
str(ps_path),
212222
"-Pid",
@@ -220,6 +230,7 @@ def _worker():
220230
],
221231
cwd=str(tmp_dir),
222232
creationflags=creationflags,
233+
startupinfo=startupinfo,
223234
close_fds=True,
224235
)
225236

0 commit comments

Comments
 (0)