Skip to content

Commit

Permalink
Refactor snapcast settings handling and add executable path validation
Browse files Browse the repository at this point in the history
  • Loading branch information
chicco-carone committed Nov 4, 2024
1 parent 4032c12 commit 9e9bb92
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
25 changes: 21 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,27 @@ def main():
log_level,
)

if not snapcast_settings.should_ignore_popup() or os.path.exists(snapcast_settings.read_setting("Snapclient/Custom_Path")) is False:
dialog = PathInputDialog("snapclient", log_level)
if dialog.exec() == QDialog.Accepted:
snapcast_settings.set_ignore_popup(dialog.ignore_popup_checkbox.isChecked())
def is_executable(file_path):
return os.path.isfile(file_path) and os.access(file_path, os.X_OK)

snapclient_path = snapcast_settings.read_setting("Snapclient/Custom_Path")
snapserver_path = snapcast_settings.read_setting("Snapserver/Custom_Path")

if not snapcast_settings.read_setting("Snapclient/Ignore_Popup"):
if not is_executable(snapclient_path):
dialog = PathInputDialog("snapclient", log_level)
if dialog.exec() == QDialog.Accepted:
snapcast_settings.set_ignore_popup(dialog.ignore_popup_checkbox.isChecked())
new_path = dialog.get_path()
snapcast_settings.write_setting("Snapclient/Custom_Path", new_path)

if not snapcast_settings.read_setting("Snapserver/Ignore_Popup"):
if not is_executable(snapserver_path):
dialog = PathInputDialog("snapserver", log_level)
if dialog.exec() == QDialog.Accepted:
snapcast_settings.set_ignore_popup(dialog.ignore_popup_checkbox.isChecked())
new_path = dialog.get_path()
snapcast_settings.write_setting("Snapserver/Custom_Path", new_path)

combined_window.show()
sys.exit(app.exec())
Expand Down
19 changes: 1 addition & 18 deletions snapcast_gui/fileactions/snapcast_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def ensure_settings(self) -> None:
"Snapserver/autostart": False,
"Snapserver/Config_Before_Start": "",
"Snapserver/Config_After_Start": "",
"Snapserver/Ignore_Popup": True,
"Shortcuts/Open_Settings": "Ctrl+O",
"Shortcuts/Connect_Disconnect": "Ctrl+C",
"Shortcuts/Toggle_Snapclient": "Ctrl+E",
Expand Down Expand Up @@ -174,21 +175,3 @@ def remove_ip(self, ip: str) -> None:
self.logger.debug(
"IP Address {} removed from config file.".format(ip)
)

def should_ignore_popup(self) -> bool:
"""
Reads the setting for ignoring the popup and returns its value.
Returns:
bool: True if the popup should be ignored, False otherwise.
"""
return self.read_setting("Snapclient/Ignore_Popup")

def set_ignore_popup(self, value: bool) -> None:
"""
Updates the setting for ignoring the popup.
Args:
value (bool): The new value for the setting.
"""
self.update_setting("Snapclient/Ignore_Popup", str(value))

0 comments on commit 9e9bb92

Please sign in to comment.