Skip to content

Commit

Permalink
Reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
ozankaraali committed May 26, 2024
1 parent 2c8d3bb commit 81f8bc0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
25 changes: 15 additions & 10 deletions config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import platform
import shutil


class ConfigManager:
CURRENT_VERSION = "1.1.3" # Set your current version here

Expand All @@ -17,22 +18,24 @@ def __init__(self):
self.load_config()

def _get_config_path(self):
app_name = 'qitv'
if platform.system() == 'Linux':
config_dir = os.path.join(os.getenv('HOME', ''), f'.config/{app_name}')
elif platform.system() == 'Darwin': # macOS
config_dir = os.path.join(os.getenv('HOME', ''), f'Library/Application Support/{app_name}')
elif platform.system() == 'Windows':
config_dir = os.path.join(os.getenv('APPDATA', ''), app_name)
app_name = "qitv"
if platform.system() == "Linux":
config_dir = os.path.join(os.getenv("HOME", ""), f".config/{app_name}")
elif platform.system() == "Darwin": # macOS
config_dir = os.path.join(
os.getenv("HOME", ""), f"Library/Application Support/{app_name}"
)
elif platform.system() == "Windows":
config_dir = os.path.join(os.getenv("APPDATA", ""), app_name)
else:
raise RuntimeError("Unsupported operating system")

os.makedirs(config_dir, exist_ok=True)
return os.path.join(config_dir, 'config.json')
return os.path.join(config_dir, "config.json")

def _migrate_old_config(self):
try:
old_config_path = 'config.json'
old_config_path = "config.json"
if os.path.isfile(old_config_path) and not os.path.isfile(self.config_path):
shutil.copy(old_config_path, self.config_path)
os.remove(old_config_path)
Expand Down Expand Up @@ -93,7 +96,9 @@ def save_window_settings(self, pos, window_name):

def apply_window_settings(self, window_name, window):
settings = self.config["window_positions"][window_name]
window.setGeometry(settings["x"], settings["y"], settings["width"], settings["height"])
window.setGeometry(
settings["x"], settings["y"], settings["width"], settings["height"]
)

def save_config(self):
with open(self.config_path, "w") as f:
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
qdarktheme.setup_theme("auto")
player.show()
channel_list.show()
check_for_updates() # Check for updates after initializing the UI
check_for_updates()
sys.exit(app.exec_())
20 changes: 15 additions & 5 deletions update_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from PyQt5.QtWidgets import QMessageBox
from config_manager import ConfigManager


def check_for_updates():
repo = "ozankaraali/QiTV"
api_url = f"https://api.github.com/repos/{repo}/releases/latest"
Expand All @@ -10,35 +11,44 @@ def check_for_updates():
response.raise_for_status()
latest_release = response.json()
latest_version = extract_version_from_tag(latest_release["name"])
if latest_version and compare_versions(latest_version, ConfigManager.CURRENT_VERSION):
if latest_version and compare_versions(
latest_version, ConfigManager.CURRENT_VERSION
):
show_update_dialog(latest_version, latest_release["html_url"])
else:
print("No new updates found or version is pre-release.")
except requests.RequestException as e:
print(f"Error checking for updates: {e}")


def extract_version_from_tag(tag):
# Handle common tag formats like 'v1.2.3', 'release-1.2.3', or '1.2.3'
import re
match = re.search(r'(\d+\.\d+\.\d+)', tag)

match = re.search(r"(\d+\.\d+\.\d+)", tag)
if match:
return match.group(0)
else:
print(f"Unexpected version format found: '{tag}'")
return None


def compare_versions(latest_version, current_version):
latest_version_parts = list(map(int, latest_version.split('.')))
current_version_parts = list(map(int, current_version.split('.')))
latest_version_parts = list(map(int, latest_version.split(".")))
current_version_parts = list(map(int, current_version.split(".")))
return latest_version_parts > current_version_parts


def show_update_dialog(latest_version, release_url):
msg = QMessageBox()
msg.setIcon(QMessageBox.Information)
msg.setText(f"A new version ({latest_version}) is available!")
msg.setInformativeText("Would you like to open the release page to download the update?")
msg.setInformativeText(
"Would you like to open the release page to download the update?"
)
msg.setWindowTitle("Update Available")
msg.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
if msg.exec_() == QMessageBox.Yes:
import webbrowser

webbrowser.open(release_url)
2 changes: 1 addition & 1 deletion video_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from PyQt5.QtWidgets import QMainWindow, QFrame, QHBoxLayout
from PyQt5.QtGui import QIcon


class VideoPlayer(QMainWindow):
def __init__(self, config_manager, *args, **kwargs):
super(VideoPlayer, self).__init__(*args, **kwargs)
Expand All @@ -22,7 +23,6 @@ def __init__(self, config_manager, *args, **kwargs):
t_lay_parent = QHBoxLayout()
t_lay_parent.setContentsMargins(0, 0, 0, 0)


self.video_frame = QFrame()
self.video_frame.mouseDoubleClickEvent = self.mouseDoubleClickEvent
self.video_frame.installEventFilter(self)
Expand Down

0 comments on commit 81f8bc0

Please sign in to comment.