Skip to content

Commit

Permalink
Install update from GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
elibroftw committed Apr 19, 2024
1 parent 5ce9fb7 commit 42d1a22
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 65 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Music Caster by Elijah Lopez Changelog

5.19.0
- [Feat] Update from GUI

5.18.9
- [Fix] Locally played track scrubbing

Expand Down
8 changes: 4 additions & 4 deletions build_files/mc_version_info.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# For more details about fixed file info 'ffi' see: http://msdn.microsoft.com/en-us/library/ms646997.aspx
VSVersionInfo(
ffi=FixedFileInfo(
prodvers=(5, 18, 9, 0),
filevers=(5, 18, 9, 0),
prodvers=(5, 19, 0, 0),
filevers=(5, 19, 0, 0),
# Contains a bitmask that specifies the valid bits 'flags'r
mask=0x17,
# Contains a bitmask that specifies the Boolean attributes of the file.
Expand All @@ -27,12 +27,12 @@ VSVersionInfo(
'000004b0',
[StringStruct('CompanyName', 'Elijah Lopez'),
StringStruct('FileDescription', 'Music Caster'),
StringStruct('FileVersion', '5.18.9.0'),
StringStruct('FileVersion', '5.19.0.0'),
StringStruct('InternalName', 'Music Caster'),
StringStruct('LegalCopyright', 'Copyright (c) 2019 - 2024, Elijah Lopez'),
StringStruct('OriginalFilename', 'Music Caster.exe'),
StringStruct('ProductName', 'Music Caster'),
StringStruct('ProductVersion', '5.18.9.0')])
StringStruct('ProductVersion', '5.19.0.0')])
]),
VarFileInfo([VarStruct('Translation', [0, 1200])])
]
Expand Down
2 changes: 1 addition & 1 deletion build_files/setup_script.iss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#define MyAppName "Music Caster"
#define MyAppVersion "5.18.9"
#define MyAppVersion "5.19.0"
#define MyAppPublisher "Elijah Lopez"
#define MyAppURL "https://elijahlopez.ca/software#music-caster"
#define MyAppExeName "Music Caster.exe"
Expand Down
3 changes: 3 additions & 0 deletions src/gui/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def QueueTab(queue, listbox_selected, listbox_height, accent_color, text_color,
select_file_values = [t('Play'), t('Queue'), t('Play Next')]
select_files = t('Select Files')
select_folder = t('Select Folder')
install_update_text = t('Install Update')
biggest_word = len(max(*select_file_values, select_files, select_folder, key=len))
combo_w = ceil(biggest_word * 0.95)
queue_controls = [Sg.Column([[
Expand All @@ -149,6 +150,8 @@ def QueueTab(queue, listbox_selected, listbox_height, accent_color, text_color,
button_width=biggest_word, pad=(5, (7, 5))),
StyledButton(select_folder, accent_color, background_color, key='select_folders',
button_width=biggest_word),
StyledButton(install_update_text, accent_color, background_color, key='install_update',
button_width=biggest_word, visible=State.update_available and not State.installing_update),
]], justification='center')]
move_to_next_up = {'image_data': PLAY_NEXT_ICON, 'button_color': (background_color, background_color), 'tooltip': t('Move to next up')}
listbox_controls = [
Expand Down
3 changes: 2 additions & 1 deletion src/languages/da.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ næste nummer
Der er ikke nok plads på den valgte disk til at auto-opdatere
Der er ikke nok plads på den valgte disk til at gemme indstillingerne
Ingen timer sat
Ikke forbundet til et 'cast device'
Ikke forbundet til et 'cast device'
Ikke logget ind på deezer.com
Intet afspilles
Notifikationer
Expand Down Expand Up @@ -199,3 +199,4 @@ Kopier URIs
rediger metadata
Eksperimentelle funktioner
Playlist gemt
Opdatering
3 changes: 2 additions & 1 deletion src/languages/de.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sprache: Deutsch
# Sprache: Deutsch (German)
# Credits: Bernd Miller
# Jede Zeile, die mit einem # beginnt, wird ignoriert!
# Wenn eine Zeile $X enthält, $X nicht übersetzen, sondern im Kontext behandeln.
Expand Down Expand Up @@ -199,3 +199,4 @@ URIs kopieren
metadaten bearbeiten
experimentelle funktionen
Playlist gespeichert
Aktualisieren
1 change: 1 addition & 0 deletions src/languages/en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,4 @@ copy URIs
edit metadata
Experimental features
Playlist saved
Install Update
1 change: 1 addition & 0 deletions src/languages/es.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,4 @@ copiar URIs
editar metadatos
caracteristicas experimentales
Lista de reproducción guardada
Actualizar
1 change: 1 addition & 0 deletions src/languages/fr.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,4 @@ copier les URI
modifier les métadonnées
Fonctionnalités expérimentales
Liste de lecture enregistrée
Mise à jour
1 change: 1 addition & 0 deletions src/languages/it.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,4 @@ copia URIs
modificare i metadati
caratteristiche sperimentali
Playlist salvata
Aggiornamento
1 change: 1 addition & 0 deletions src/languages/nl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,4 @@ kopieer URI
metagegevens bewerken
experimentele functies
Afspeellijst opgeslagen
Installeer update
1 change: 1 addition & 0 deletions src/languages/ru.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,4 @@ cover.* изображение замещает встроенную в файл
редактировать метаданные
Экспериментальные функции
Плейлист сохранен
Обновлять
1 change: 1 addition & 0 deletions src/languages/uk.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,4 @@ cover.* зображення заміщає вбудованну в файл о
редагувати метадані
Експериментальні функції
Список відтворення збережено
Оновлення
4 changes: 3 additions & 1 deletion src/meta.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = latest_version = '5.18.9'
VERSION = latest_version = '5.19.0'
UPDATE_MESSAGE = """
[NEW] Better Error Capturing
[MSG] Language translators wanted
Expand Down Expand Up @@ -84,6 +84,8 @@ class State:
# experimental setting
using_tcl_theme = False
settings = {}
update_available = False
installing_update = False


class PlayingStatus:
Expand Down
125 changes: 68 additions & 57 deletions src/music_caster.py
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,10 @@ def get_devices():
return lo_devices


class UpdateFailed(Exception):
pass


class StatusCastListener(CastStatusListener):
"""Cast status listener"""

Expand Down Expand Up @@ -2416,8 +2420,8 @@ class UpdateChecker(threading.Timer):
latest_version = VERSION

def __init__(self):
# check for an update every 4 hours
super().__init__(14_400, self.check_for_updates)
# check for an update every 30 minutes
super().__init__(1800, self.check_for_updates)
self.daemon = True
self.start()

Expand All @@ -2426,7 +2430,8 @@ def check_for_updates(self):
if release:
# avoid showing a notification for the same latest version
self.latest_version = release['version']
if settings['notifications']: tray_notify('update_available', context=self.latest_version)
if settings['notifications']:
tray_notify('update_available', context=self.latest_version)


def background_thread():
Expand Down Expand Up @@ -3220,6 +3225,11 @@ def read_main_window():
elif main_event == 'select_folders':
Thread(target=folder_action, name='FolderAction', daemon=True,
args=[main_values['fs_action']]).start()
elif main_event == 'install_update':
if not State.installing_update:
gui_window['install_update'].update(visible=False)
Thread(target=auto_update, daemon=True, name='Updater').start()

# ???
elif main_event == 'play_all':
if not any(filter(lambda thread: thread.name == 'PlayAll', threading.enumerate())):
Expand Down Expand Up @@ -3680,64 +3690,65 @@ def start_on_login_modifications():
def auto_update():
""" auto_start should be True when checking for updates at startup up,
false when checking for updates before exiting """
with suppress(requests.RequestException):
State.installing_update = True
with suppress(requests.RequestException, UpdateFailed):
app_log.info(f'called auto_update(), IS_FROZEN={IS_FROZEN}')
release = get_latest_release(VERSION, VERSION, force=(not IS_FROZEN or is_debug()))
if release:
latest_ver = release['version']
setup_dl_link = release['setup']
app_log.info(f'Update found: v{latest_ver}')
print('Installer Link:', setup_dl_link)
if int(VERSION.split('.', 1)[0]) < int(latest_ver.split('.', 1)[0]):
if not is_os_64bit():
tray_notify(f"The update v{latest_ver}, is 64-bit only")
tray_notify("I've turned off auto-update for you, so you don't have to worry")
return update_settings('auto_update', False)
if is_debug() or not setup_dl_link:
return app_log.info(f'Not updating because: DEBUG: {DEBUG} or not setup_dl_link={setup_dl_link}')
if IS_FROZEN:
if platform.system() in {'Linux', 'Darwin'}:
if not release:
app_log.info(f'auto_update: no update found, or no internet, or API rate limited')
raise UpdateFailed
latest_ver = release['version']
setup_dl_link = release['setup']
app_log.info(f'Update found: v{latest_ver}')
print('Installer Link:', setup_dl_link)
if is_debug() or not setup_dl_link:
app_log.info(f'Not updating because: DEBUG: {DEBUG} or not setup_dl_link={setup_dl_link}')
raise UpdateFailed
if IS_FROZEN:
if platform.system() in {'Linux', 'Darwin'}:
tray_notify('update_available', context=latest_ver)
State.update_available = True
if not gui_window.was_closed():
gui_window['install_update'].update(visible=True)
elif os.path.exists(UNINSTALLER):
installer_path = get_installer_path()
# only show message on startup to not confuse the user
cmd = [installer_path, '/VERYSILENT', '/FORCECLOSEAPPLICATIONS',
'/MERGETASKS="!desktopicon"', '&&', 'Music Caster.exe']
cmd.extend(sys.argv[1:])
if gui_window.was_closed() and not args.minimized:
cmd.append('-m')
download_update = t('Downloading update $VER').replace('$VER', latest_ver)
tray_notify(download_update)
tray_tooltip = download_update
tray_process_queue.put({'tooltip': tray_tooltip})
try:
# download setup, close tray, run setup, and exit
download(setup_dl_link, installer_path)
tray_notify(t('Update downloaded, restarting now'))
time.sleep(0.3)
Popen(cmd, shell=True)
daemon_commands.put('__EXIT__') # tell main thread to exit
except OSError as e:
if e.errno == errno.ENOSPC:
tray_notify(t('ERROR') + ': ' + t('No space left on device to auto-update'))
except Exception:
tray_notify('update_available', context=latest_ver)
elif os.path.exists(UNINSTALLER):
installer_path = get_installer_path()
# only show message on startup to not confuse the user
cmd = [installer_path, '/VERYSILENT', '/FORCECLOSEAPPLICATIONS',
'/MERGETASKS="!desktopicon"', '&&', 'Music Caster.exe']
cmd.extend(sys.argv[1:])
if gui_window.was_closed() and not args.minimized:
cmd.append('-m')
download_update = t('Downloading update $VER').replace('$VER', latest_ver)
tray_notify(download_update)
tray_tooltip = download_update
tray_process_queue.put({'tooltip': tray_tooltip})
try:
# download setup, close tray, run setup, and exit
download(setup_dl_link, installer_path)
tray_notify(t('Update downloaded, restarting now'))
time.sleep(0.3)
Popen(cmd, shell=True)
daemon_commands.put('__EXIT__') # tell main thread to exit
except OSError as e:
if e.errno == errno.ENOSPC:
tray_notify(t('ERROR') + ': ' + t('No space left on device to auto-update'))
except Exception:
elif os.path.exists('Updater.exe'):
# portable installation
try:
startfile('Updater')
daemon_commands.put('__EXIT__') # tell main thread to exit
except OSError as e:
if e == errno.ECANCELED:
# user cancelled update, don't try auto-updating again
# inform user what we were trying to do though
update_settings('auto_update', False)
tray_notify('update_available', context=latest_ver)
elif os.path.exists('Updater.exe'):
# portable installation
try:
startfile('Updater')
daemon_commands.put('__EXIT__') # tell main thread to exit
except OSError as e:
if e == errno.ECANCELED:
# user cancelled update, don't try auto-updating again
# inform user what we were trying to do though
update_settings('auto_update', False)
tray_notify('update_available', context=latest_ver)
else:
# unins000.exe or updater.exe was deleted; better to inform user there is an update available
tray_notify('update_available', context=latest_ver)
else:
app_log.info(f'auto_update: no update found, or no internet, or API rate limited')
else:
# unins000.exe or updater.exe was deleted; better to inform user there is an update available
tray_notify('update_available', context=latest_ver)
State.installing_update = False


def cast_monitor(sent: bool = True, msg: dict = None):
Expand Down

0 comments on commit 42d1a22

Please sign in to comment.