Skip to content

Commit

Permalink
feat(cli): update YASB CLI version to 1.0.3 and add uninstall functio…
Browse files Browse the repository at this point in the history
…nality
  • Loading branch information
amnweb committed Dec 1, 2024
1 parent 5a059f3 commit ddc20ef
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/core/utils/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
just_fix_windows_console()

YASB_VERSION = BUILD_VERSION
YASB_CLI_VERSION = "1.0.2"
YASB_CLI_VERSION = "1.0.3"

OS_STARTUP_FOLDER = os.path.join(os.environ['APPDATA'], r'Microsoft\Windows\Start Menu\Programs\Startup')
INSTALLATION_PATH = os.path.abspath(os.path.join(__file__, "../../.."))
Expand Down Expand Up @@ -282,6 +282,22 @@ def delete_task():
print(f"Failed to delete task YASB or task does not exist.")

class CLIUpdateHandler():

def get_installed_product_code():
ERROR_NO_MORE_ITEMS = 259
MAX_GUID_CHARS = 39
msi = ctypes.windll.msi
product_code = ctypes.create_unicode_buffer(MAX_GUID_CHARS + 1)
index = 0
while True:
result = msi.MsiEnumRelatedProductsW("{3f620cf5-07b5-47fd-8e37-9ca8ad14b608}", 0, index, product_code)
if result == ERROR_NO_MORE_ITEMS:
break
elif result == 0:
return product_code.value
index += 1
return None

def update_yasb(YASB_VERSION):
# Fetch the latest tag from the GitHub API
api_url = f"https://api.github.com/repos/amnweb/yasb/releases/latest"
Expand Down Expand Up @@ -331,11 +347,17 @@ def update_yasb(YASB_VERSION):
# Step 4: Run the MSI installer in silent mode and restart the application
if is_process_running("yasb.exe"):
subprocess.run(["taskkill", "/f", "/im", "yasb.exe"], creationflags=subprocess.CREATE_NO_WINDOW)


# Construct the uninstall command as a string
product_code = CLIUpdateHandler.get_installed_product_code()
if product_code is not None:
uninstall_command = f'msiexec /x {product_code} /passive'
else:
uninstall_command = ""
# Construct the install command as a string
install_command = f'msiexec /i "{os.path.abspath(msi_path)}" /passive /norestart'
run_after_command = f'"{EXE_PATH}"'
combined_command = f'{install_command} && {run_after_command}'
combined_command = f'{uninstall_command} && {install_command} && {run_after_command}'

# Finally run update and restart the application
subprocess.Popen(combined_command, shell=True)
Expand Down

0 comments on commit ddc20ef

Please sign in to comment.