Skip to content

Commit

Permalink
Merge pull request #40 from Wolfmyths/future-update
Browse files Browse the repository at this point in the history
Update 2.2.0
  • Loading branch information
Wolfmyths authored May 2, 2024
2 parents 9114c2d + c60cad1 commit b7e0d68
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 10 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: 3.11
cache: 'pip'
Expand All @@ -41,7 +41,7 @@ jobs:
run: dir

- name: Create release artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Genshin-Stopwatch-Assets-${{ matrix.os }}
path: |
Expand Down Expand Up @@ -103,7 +103,7 @@ jobs:
args: zip -qq -r "Genshin-Stopwatch-${{ env.zipname }}.zip" "Genshin-Stopwatch-${{ matrix.os }}"

- name: Upload Artifact to Release Assets
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: Genshin-Stopwatch-${{ env.zipname }}.zip
2 changes: 1 addition & 1 deletion src/python/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class TimeFormats(StrEnum):
ONE = timedelta(seconds=1)

# Program Info
VERSION = Version(major=2, minor=0, patch=0)
VERSION = Version(major=2, minor=2, patch=0)
PROGRAM_NAME = 'Genshin Stopwatch'

# Object Names
Expand Down
8 changes: 7 additions & 1 deletion src/python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from saveConfig import saveConfig
from style import StyleManager, StyleSheets
from constants import VERSION, ICON, PROGRAM_NAME
import notify
import notify, os

if __name__ == '__main__':
import sys
Expand All @@ -34,4 +34,10 @@
# Checking to see if any static timers and stopwatches went off while the program was shutdown
notify.checkMissedNotify()

# Check to see if an old version was left behind after update (windows)
path = os.path.dirname(sys.executable)
old = os.path.join(path, "Genshin-Stopwatch_OLD.exe")
if os.path.exists(old):
os.remove(old)

app.exec()
92 changes: 92 additions & 0 deletions src/python/widgets/installUpdate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import PySide6.QtWidgets as qtw
import PySide6.QtGui as qtg
import PySide6.QtCore as qtc
import PySide6.QtNetwork as qtn

import tempfile, platform, zipfile, sys, os, shutil

from constants import ICON
from PySide6.QtCore import Slot


class updateApp(qtw.QDialog):
def __init__(self):
super().__init__()

self.setWindowTitle("Downloading update...")
self.setWindowIcon(qtg.QIcon(ICON))

layout = qtw.QVBoxLayout(self)

self.resize(400, 300)
self.message = qtw.QLabel(self, text="Downloading...")
layout.addWidget(self.message)
self.progress = qtw.QProgressBar(self)
layout.addWidget(self.progress)

self.target_dir = tempfile.mkdtemp(prefix="Genshin-Stopwatch_", suffix="_UPDATE")
if platform.system() == "Darwin":
self.platform = "MacOS"
elif platform.system() == "Linux":
self.platform = "Ubuntu"
# In GH releases, linux version is under ubuntu -_-
elif platform.system() == "Windows":
self.platform = "Windows"
self.url = qtc.QUrl(f"https://github.com/Wolfmyths/Genshin-Stopwatch/releases/latest/download/Genshin-Stopwatch-{self.platform}.zip")
self.path = qtc.QDir(self.target_dir).filePath(self.url.fileName())
self.file = qtc.QSaveFile(self.path)
self.manager = qtn.QNetworkAccessManager(self)
# appending bytes
if self.file.open(qtc.QIODevice.WriteOnly):
self.reply = self.manager.get(qtn.QNetworkRequest(self.url))
self.reply.downloadProgress.connect(self.on_progress)
self.reply.finished.connect(self.on_finished)
self.reply.readyRead.connect(self.on_ready_read)
self.reply.errorOccurred.connect(self.on_error)
else:
error = self.file.errorString()
print(f"Cannot open device: {error}")

def install(self):
with zipfile.ZipFile(self.path) as openzip:
openzip.extractall(self.target_dir)
latestExec = os.path.join(self.target_dir, f"Genshin-Stopwatch-{self.platform.lower()}-latest", "GenshinStopwatch")
execPath = sys.executable
if self.platform == "Windows":
latestExec += ".exe"
os.rename(sys.executable, "Genshin-Stopwatch_OLD.exe")
else:
os.remove(sys.executable)
shutil.copyfile(latestExec, execPath)
shutil.rmtree(self.target_dir)
try:
os.startfile(execPath)
except:
os.chmod(execPath, 755)
os.system(f".{execPath} & ")
finally:
qtc.QCoreApplication.quit()

@Slot()
def on_ready_read(self):
if self.reply:
if self.reply.error() == qtn.QNetworkReply.NoError:
self.file.write(self.reply.readAll())

@Slot()
def on_finished(self):
if self.reply:
self.reply.deleteLater()
if self.file:
self.file.commit()
self.install()

@Slot(int, int)
def on_progress(self, bytesReceived: int, bytesTotal: int):
self.progress.setRange(0, bytesTotal)
self.progress.setValue(bytesReceived)

@Slot(qtn.QNetworkReply.NetworkError)
def on_error(self, code: qtn.QNetworkReply.NetworkError):
if self.reply:
qtw.QMessageBox.warning(self, "Error Occurred", self.reply.errorString())
10 changes: 6 additions & 4 deletions src/python/widgets/updateAlert.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import webbrowser

import PySide6.QtWidgets as qtw
import PySide6.QtGui as qtg

from saveConfig import saveConfig, ConfigKeys

from constants import ICON

from widgets.installUpdate import updateApp


class UpdateAlert(qtw.QDialog):
def __init__(self, latestVersion: str, changelog: str) -> None:
super().__init__()
Expand All @@ -18,7 +19,7 @@ def __init__(self, latestVersion: str, changelog: str) -> None:

layout = qtw.QVBoxLayout()

self.message = qtw.QLabel(self, text=f'The latest update {latestVersion} has been released!\nWould you like to visit the download page?')
self.message = qtw.QLabel(self, text=f'The latest update {latestVersion} has been released!\nWould you like to download & install?')
layout.addWidget(self.message)

self.checkBox = qtw.QCheckBox(self, text='Do not automatically check for updates')
Expand All @@ -38,7 +39,8 @@ def __init__(self, latestVersion: str, changelog: str) -> None:
self.setLayout(layout)

def accept(self) -> None:
webbrowser.open_new_tab('https://github.com/Wolfmyths/Genshin-Stopwatch/releases/latest')
installer = updateApp()
installer.exec()
return super().accept()

def checkBoxClicked(self) -> None:
Expand Down

0 comments on commit b7e0d68

Please sign in to comment.