Change in updater
This commit is contained in:
parent
64bd228e8e
commit
b2817e7332
1 changed files with 28 additions and 28 deletions
|
@ -479,6 +479,7 @@ class UpdaterWindow(QMainWindow, Ui_Updater_Window):
|
|||
super(UpdaterWindow, self).__init__()
|
||||
self.ui = Ui_Updater_Window()
|
||||
self.ui.setupUi(self)
|
||||
self.dev_mode = True if optimalab35_localversion == "0.0.1" else False
|
||||
from PyPiUpdater import PyPiUpdater
|
||||
# Update log file location
|
||||
self.update_log_file = os.path.expanduser("~/.config/OptimaLab35/update_log.json")
|
||||
|
@ -492,8 +493,6 @@ class UpdaterWindow(QMainWindow, Ui_Updater_Window):
|
|||
self.ol35_last_state = self.ppu_ol35.get_last_state()
|
||||
self.o35_last_state = self.ppu_o35.get_last_state()
|
||||
|
||||
#self.last_update = self.ppu_o35.last_update_date_string()
|
||||
|
||||
# Track which packages need an update
|
||||
self.updates_available = {"OptimaLab35": False, "optima35": False}
|
||||
|
||||
|
@ -501,11 +500,6 @@ class UpdaterWindow(QMainWindow, Ui_Updater_Window):
|
|||
|
||||
def define_gui_interaction(self):
|
||||
"""Setup UI interactions."""
|
||||
if self.optimalab35_localversion == "0.0.1":
|
||||
self.dev_mode()
|
||||
return
|
||||
else:
|
||||
self.ui.label_dev.setVisible(False)
|
||||
|
||||
self.ui.label_optimalab35_localversion.setText(self.optimalab35_localversion)
|
||||
self.ui.label_optima35_localversion.setText(self.optima35_localversion)
|
||||
|
@ -519,13 +513,18 @@ class UpdaterWindow(QMainWindow, Ui_Updater_Window):
|
|||
# Connect buttons to functions
|
||||
self.ui.check_for_update_Button.clicked.connect(self.check_for_updates)
|
||||
self.ui.update_and_restart_Button.clicked.connect(self.update_and_restart)
|
||||
self.ui.label_last_check_2.setText(str(self.ol35_last_state[0]))
|
||||
self.ui.label_last_check_2.setText(self.time_to_string(self.ol35_last_state[0]))
|
||||
|
||||
def dev_mode(self):
|
||||
self.ui.update_and_restart_Button.setEnabled(False)
|
||||
self.ui.check_for_update_Button.setEnabled(False)
|
||||
self.ui.label_dev.setStyleSheet("QLabel { background-color : red; color : black; }")
|
||||
|
||||
def time_to_string(self, time_time):
|
||||
dt_obj = datetime.fromtimestamp(time_time)
|
||||
date_string = dt_obj.strftime("%d %h %H:%M")
|
||||
return date_string
|
||||
|
||||
def check_for_updates(self):
|
||||
"""Check for updates and update the UI."""
|
||||
self.ui.check_for_update_Button.setEnabled(False)
|
||||
|
@ -533,29 +532,31 @@ class UpdaterWindow(QMainWindow, Ui_Updater_Window):
|
|||
self.ui.label_optima35_latestversion.setText("Checking...")
|
||||
|
||||
# Check OptimaLab35 update
|
||||
is_newer_ol35, latest_version_ol35 = self.ppu_ol35.check_for_update(True)
|
||||
if is_newer_ol35 is None:
|
||||
self.ui.label_optimalab35_latestversion.setText(latest_version_ol35[0:13])
|
||||
ol35_pkg_info = self.ppu_ol35.check_for_update()
|
||||
if ol35_pkg_info[0] is None:
|
||||
self.ui.label_optimalab35_latestversion.setText(ol35_pkg_info[1][0:13])
|
||||
else:
|
||||
self.ui.label_optimalab35_latestversion.setText(latest_version_ol35)
|
||||
self.updates_available["OptimaLab35"] = is_newer_ol35
|
||||
self.ui.label_optimalab35_latestversion.setText(ol35_pkg_info[1])
|
||||
self.updates_available["OptimaLab35"] = ol35_pkg_info[0]
|
||||
|
||||
# Check optima35 update
|
||||
is_newer_o35, latest_version_o35 = self.ppu_o35.check_for_update(True)
|
||||
if is_newer_o35 is None:
|
||||
self.ui.label_optima35_latestversion.setText(latest_version_o35[0:13])
|
||||
o35_pkg_info = self.ppu_o35.check_for_update()
|
||||
if o35_pkg_info[0] is None:
|
||||
self.ui.label_optima35_latestversion.setText(o35_pkg_info[1][0:13])
|
||||
else:
|
||||
self.ui.label_optima35_latestversion.setText(latest_version_o35)
|
||||
self.updates_available["optima35"] = is_newer_o35
|
||||
self.ui.label_optima35_latestversion.setText(o35_pkg_info[1])
|
||||
self.updates_available["optima35"] = o35_pkg_info[0]
|
||||
|
||||
# Enable update button if any update is available
|
||||
if any(self.updates_available.values()):
|
||||
self.ui.update_and_restart_Button.setEnabled(True)
|
||||
if self.dev_mode:
|
||||
self.ui.update_and_restart_Button.setEnabled(False)
|
||||
self.ui.update_and_restart_Button.setText("Update disabled")
|
||||
else:
|
||||
self.ui.update_and_restart_Button.setEnabled(True)
|
||||
|
||||
self.ppu_o35.record_update_check()
|
||||
self.ppu_ol35.record_update_check()
|
||||
last_date = self.ppu_ol35.get_last_state()
|
||||
self.ui.label_last_check_2.setText(last_date[0])
|
||||
last_date = self.time_to_string(self.ppu_ol35.get_last_state()[0])
|
||||
self.ui.label_last_check_2.setText(last_date)
|
||||
self.ui.label_latest_version.setText("Online version")
|
||||
self.ui.check_for_update_Button.setEnabled(True)
|
||||
|
||||
|
@ -570,7 +571,7 @@ class UpdaterWindow(QMainWindow, Ui_Updater_Window):
|
|||
# Confirm update
|
||||
msg = QMessageBox()
|
||||
msg.setWindowTitle("Update Available")
|
||||
msg.setText(f"Updating: {', '.join(packages_to_update)}\nRestart after update?")
|
||||
msg.setText(f"Updating: {', '.join(packages_to_update)}\nUpdate and restart app?")
|
||||
msg.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
|
||||
result = msg.exec()
|
||||
|
||||
|
@ -579,11 +580,11 @@ class UpdaterWindow(QMainWindow, Ui_Updater_Window):
|
|||
|
||||
for package in packages_to_update:
|
||||
if package == "OptimaLab35":
|
||||
success, message = self.ppu_ol35.update_package()
|
||||
pkg_info = self.ppu_ol35.update_package()
|
||||
elif package == "optima35":
|
||||
success, message = self.ppu_o35.update_package()
|
||||
pkg_info = self.ppu_o35.update_package()
|
||||
|
||||
update_results.append(f"{package}: {'✔ Success' if success else '❌ Failed'}\n{message}")
|
||||
update_results.append(f"{package}: {'Success' if pkg_info[0] else 'Failed'}\n{pkg_info[1]}")
|
||||
|
||||
# Show summary of updates
|
||||
# Show update completion message
|
||||
|
@ -600,7 +601,6 @@ class UpdaterWindow(QMainWindow, Ui_Updater_Window):
|
|||
def restart_program(self):
|
||||
"""Restart the Python program after an update."""
|
||||
print("Restarting the application...")
|
||||
|
||||
# Close all running Qt windows before restarting
|
||||
app = QApplication.instance()
|
||||
if app:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue