Skip to content

Commit

Permalink
Add "check for updates" process at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
hasielhassan committed Sep 11, 2023
1 parent eb89047 commit 6e14552
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 3 deletions.
77 changes: 74 additions & 3 deletions modules/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
import re
import json
import pprint
import requests
import webbrowser
import qdarkstyle
import pygraphviz

from packaging import version as packaging_version

import Nodz
from Nodz import nodz_main

Expand All @@ -40,6 +44,8 @@ class PlumberManager(QtWidgets.QMainWindow):
PROJECT_DIR, 'config', 'data_icons.json'
)

settings = QtCore.QSettings("PlumberManager")

data_types = {}

def __init__(self, parent=None):
Expand All @@ -64,8 +70,6 @@ def __init__(self, parent=None):
)
)



self.nodz = nodz_main.Nodz(None)
self.nodz.loadConfig(filePath=self.custom_config_path)
self.nodz.config["icons_folder"] = os.path.join(
Expand Down Expand Up @@ -146,6 +150,12 @@ def __init__(self, parent=None):
self.nodz.signal_KeyPressed.connect(self.on_keyPressed)
"""

# Create a QTimer to delay the updates check dialog
self.update_timer = QtCore.QTimer(self)
self.update_timer.timeout.connect(self._checkForUpdates)
# Delay for half a second
self.update_timer.start(500)

######################################################################
# Test signals
######################################################################
Expand Down Expand Up @@ -241,6 +251,68 @@ def on_graphCleared(self):
def on_keyPressed(self, key):
print('key pressed : {}'.format(key))

def _checkForUpdates(self):
"""
"""
self.update_timer.stop()

try:
response = requests.get(
(
"https://api.github.com/repos/"
"hasielhassan/PlumberManager/"
"releases/latest"
)
).json()
except Exception as e:
print("Failed to check for updates: {}".format(str(e)))
return

title = response["name"]
version = response["tag_name"]
description = response["body"]
url = response["html_url"]

current_version = packaging_version.parse(self.version)
latest_version = packaging_version.parse(version)

skipped = self.settings.value("skipped_updates", None)
if skipped:
skipped = skipped.split(",")
else:
skipped = []

if version not in skipped and latest_version > current_version:

dialog = QtWidgets.QMessageBox(self)

# Set the title, message and icon
dialog.setWindowTitle(title)
dialog.setText(description)
dialog.setIcon(QtWidgets.QMessageBox.Information)

# Create custom buttons with your desired text
check_button = QtWidgets.QPushButton("Check Release")
remind_button = QtWidgets.QPushButton("Remind me later")
skip_button = QtWidgets.QPushButton("Skip Release")

# Add custom buttons to the message box
dialog.addButton(check_button, QtWidgets.QMessageBox.AcceptRole)
dialog.addButton(remind_button, QtWidgets.QMessageBox.AcceptRole)
dialog.addButton(skip_button, QtWidgets.QMessageBox.ActionRole)

# Display the message box and handle the result
result = dialog.exec_()

if result == 0:
webbrowser.open(url, new=2)
elif result == 2:
skipped.append(version)
as_string = ",".join(skipped)
self.settings.setValue("skipped_updates", as_string)
else:
pass

@classmethod
def loadDataTypes(cls, nodz):
"""
Expand Down Expand Up @@ -273,7 +345,6 @@ def loadDataTypes(cls, nodz):

print(pprint.pformat(cls.data_types))


def createProcess(self):
processName, ok = QtWidgets.QInputDialog.getText(
self, 'New Process', 'Process Name:'
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ PySide2
Qt.py
pygraphviz
qdarkstyle
webbrowser
packaging
git+https://github.com/hasielhassan/Nodz.git#egg=Nodz

0 comments on commit 6e14552

Please sign in to comment.