Skip to content

Commit

Permalink
Handle need restart after installation for winget
Browse files Browse the repository at this point in the history
  • Loading branch information
panther7 committed Jan 22, 2023
1 parent 7de4b75 commit c80a21c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 60 deletions.
106 changes: 51 additions & 55 deletions wingetui/storeEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,64 +209,60 @@ def finish(self, returncode: int, output: str = "") -> None:
self.adminstr = [sudoPath]
self.cmdline_args.append("--global")
self.runInstallation()
return
elif returncode == 1603:
self.adminstr = [sudoPath]
self.runInstallation()
else:
self.finishedInstallation = True
self.cancelButton.setEnabled(True)
removeProgram(self.installId)
try: self.waitThread.kill()
except: pass
try: self.t.kill()
except: pass
try: self.p.kill()
except: pass
if not(self.canceled):
if(returncode == 0):
self.callInMain.emit(lambda: globals.trayIcon.showMessage(_("{0} succeeded").format(self.actionName.capitalize()), _("{0} was {1} successfully!").format(self.programName, self.actionDone), QIcon(getMedia("notif_info"))))
self.cancelButton.setText("OK")
self.cancelButton.setIcon(QIcon(realpath+"/resources/tick.png"))
self.cancelButton.clicked.connect(self.close)
self.info.setText(_("{0} was {1} successfully!").format(self.programName, self.actionDone))
self.progressbar.setValue(1000)
if type(self) == PackageInstallerWidget:
if self.packageItem:
globals.uninstall.addItem(self.packageItem.text(0), self.packageItem.text(1), self.packageItem.text(2), self.packageItem.text(3)) # Add the package on the uninstaller
globals.uninstall.updatePackageNumber()
self.startCoolDown()
else:
globals.trayIcon.setIcon(QIcon(getMedia("yellowicon")))
self.cancelButton.setText(_("OK"))
self.cancelButton.setIcon(QIcon(realpath+"/resources/warn.png"))
self.cancelButton.clicked.connect(self.close)
self.progressbar.setValue(1000)
self.err = ErrorMessage(self.window())
if(returncode == 2): # if the installer's hash does not coincide
errorData = {
"titlebarTitle": f"WingetUI - {self.programName} {self.actionName}",
"mainTitle": _("{0} aborted").format(self.actionName.capitalize()),
"mainText": _("The checksum of the installer does not coincide with the expected value, and the authenticity of the installer can't be verified. If you trust the publisher, {0} the package again skipping the hash check.").format(self.actionVerb),
"buttonTitle": _("Close"),
"errorDetails": output.replace("-\|/", "").replace("▒", "").replace("█", ""),
"icon": QIcon(getMedia("notif_warn")),
"notifTitle": _("Can't {0} {1}").format(self.actionVerb, self.programName),
"notifText": _("The installer has an invalid checksum"),
"notifIcon": QIcon(getMedia("notif_warn")),
}
else: # if there's a generic error
errorData = {
"titlebarTitle": _("WingetUI - {0} {1}").format(self.programName, self.actionName),
"mainTitle": _("{0} failed").format(self.actionName.capitalize()),
"mainText": _("We could not {0} {1}. Please try again later. Click on \"Show details\" to get the logs from the installer.").format(self.actionVerb, self.programName),
"buttonTitle": _("Close"),
"errorDetails": output.replace("-\|/", "").replace("▒", "").replace("█", ""),
"icon": QIcon(getMedia("notif_warn")),
"notifTitle": _("Can't {0} {1}").format(self.actionVerb, self.programName),
"notifText": _("{0} {1} failed").format(self.programName.capitalize(), self.actionName),
"notifIcon": QIcon(getMedia("notif_warn")),
}
self.err.showErrorMessage(errorData)
return
self.finishedInstallation = True
self.cancelButton.setEnabled(True)
removeProgram(self.installId)
try: self.waitThread.kill()
except: pass
try: self.t.kill()
except: pass
try: self.p.kill()
except: pass
if self.canceled:
return
self.cancelButton.setText(_("OK"))
self.cancelButton.clicked.connect(self.close)
self.progressbar.setValue(1000)
if (returncode == 0 or returncode == 3):
if returncode == 0:
self.cancelButton.setIcon(QIcon(realpath+"/resources/tick.png"))
self.info.setText(_("{action} was successfully!").format(action = self.actionDone))
if returncode == 3: # if the installer need restart computer
self.cancelButton.setIcon(QIcon(realpath+"/resources/warn.png"))
self.info.setText(_("Restart your PC to finish installation"))
self.callInMain.emit(lambda: globals.trayIcon.showMessage(_("{0} succeeded").format(self.actionName.capitalize()), _("{0} was {1} successfully!").format(self.programName, self.actionDone), QIcon(getMedia("notif_info"))))
if type(self) == PackageInstallerWidget:
if self.packageItem:
globals.uninstall.addItem(self.packageItem.text(0), self.packageItem.text(1), self.packageItem.text(2), self.packageItem.text(3)) # Add the package on the uninstaller
globals.uninstall.updatePackageNumber()
self.startCoolDown()
return
globals.trayIcon.setIcon(QIcon(getMedia("yellowicon")))
self.cancelButton.setIcon(QIcon(realpath+"/resources/warn.png"))
self.err = ErrorMessage(self.window())
warnIcon = QIcon(getMedia("notif_warn"))
dialogData = {
"titlebarTitle": _("WingetUI - {0} {1}").format(self.programName, self.actionName),
"buttonTitle": _("Close"),
"errorDetails": output.replace("-\|/", "").replace("▒", "").replace("█", ""),
"icon": warnIcon,
"notifTitle": _("Can't {0} {1}").format(self.actionVerb, self.programName),
"notifIcon": warnIcon,
}
if returncode == 2: # if the installer's hash does not coincide
dialogData["mainTitle"] = _("{0} aborted").format(self.actionName.capitalize())
dialogData["mainText"] = _("The checksum of the installer does not coincide with the expected value, and the authenticity of the installer can't be verified. If you trust the publisher, {0} the package again skipping the hash check.").format(self.actionVerb)
dialogData["notifText"] = _("The installer has an invalid checksum")
else: # if there's a generic error
dialogData["mainTitle"] = _("{0} failed").format(self.actionName.capitalize())
dialogData["mainText"] = _("We could not {0} {1}. Please try again later. Click on \"Show details\" to get the logs from the installer.").format(self.actionVerb, self.programName)
dialogData["notifText"] = _("{0} {1} failed").format(self.programName.capitalize(), self.actionName)
self.err.showErrorMessage(dialogData)

def startCoolDown(self):
if not getSettings("MaintainSuccessfulInstalls"):
Expand Down
12 changes: 7 additions & 5 deletions wingetui/wingetHelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ def getInfo(signal: Signal, title: str, id: str, useId: bool) -> None:

def installAssistant(p: subprocess.Popen, closeAndInform: Signal, infoSignal: Signal, counterSignal: Signal) -> None:
print(f"🟢 winget installer assistant thread started for process {p}")
outputCode = 0
counter = 0
output = ""
while p.poll() is None:
Expand All @@ -370,14 +369,17 @@ def installAssistant(p: subprocess.Popen, closeAndInform: Signal, infoSignal: Si
counterSignal.emit(counter)
output += line+"\n"
p.wait()
outputCode = p.returncode
if outputCode == 0x8A150011:
outputCode = 2
match p.returncode:
case 0x8A150011:
outputCode = 2
case 0x8A150109: # need restart
outputCode = 3
case _:
outputCode = p.returncode
closeAndInform.emit(outputCode, output)

def uninstallAssistant(p: subprocess.Popen, closeAndInform: Signal, infoSignal: Signal, counterSignal: Signal) -> None:
print(f"🟢 winget installer assistant thread started for process {p}")
outputCode = 0
counter = 0
output = ""
while p.poll() is None:
Expand Down

0 comments on commit c80a21c

Please sign in to comment.