From e39391854d9f4629c51fac0abfcae5de4505faa8 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Mon, 11 Dec 2023 02:44:07 +0700 Subject: [PATCH] update checker --- src/espmega_lightshow/__main__.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/espmega_lightshow/__main__.py b/src/espmega_lightshow/__main__.py index 1a3f200..2878df1 100644 --- a/src/espmega_lightshow/__main__.py +++ b/src/espmega_lightshow/__main__.py @@ -18,6 +18,7 @@ import shutil import traceback import webbrowser +import subprocess @dataclass class PhysicalLightEntity: @@ -1419,6 +1420,23 @@ def open_github(): company_label = ttk.Label(about_popup, text="SIWAT SYSTEM 2023") company_label.pack() +# Check for updates using pip +def check_for_updates(): + # Run pip in a subprocess + process = subprocess.Popen(["pip", "install", "--upgrade", "espmega-lightshow"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = process.communicate() + # Check if pip returned an error + if process.returncode != 0: + messagebox.showerror("Update Error", f"An error occured while checking for updates.\n{stderr.decode('utf-8')}") + else: + return_message = stdout.decode("utf-8") + print(return_message) + # Check if pip returned a message + if ("Requirement already satisfied: espmega-lightshow" in return_message): + messagebox.showinfo("Update", "No updates found.") + else: + messagebox.showinfo("Update", "Update found.\nPlease restart the program to apply the update.") + # Create the help menu help_menu = tk.Menu(menu_bar, tearoff=False) help_menu.add_command(label="About", command=open_about_popup)