Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

Commit

Permalink
[0.1.2] 支持Coding Artifact更新
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraZiling committed May 17, 2023
1 parent ae2ffa1 commit 8b6b2f6
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
/old_src/requestUrl.txt
/src/data/
/src/configs/
/src/temp/
2 changes: 1 addition & 1 deletion src/assets/configs/application.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"application_version": "0.1.2",
"application_version": "0.1.1",
"ui_version": "0.8.7"
}
3 changes: 2 additions & 1 deletion src/modules/Scripts/Utils/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def installUpdate():
if os.path.exists(f"{utils.workingDir}/asta.py"):
return
with open('temp/update.bat', 'w') as f:
f.write(UPDATE_SCRIPT_MODEL.format(filename=os.listdir(f"{utils.workingDir}/temp")[0]))
target = [i for i in os.listdir(f"{utils.workingDir}/temp") if not ".bat" in i]
f.write(UPDATE_SCRIPT_MODEL.format(filename=target[0]))

subprocess.Popen(
[
Expand Down
29 changes: 17 additions & 12 deletions src/modules/Views/ViewFunctions/settingsFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,27 @@
class UpdateThread(QThread):
trigger = Signal(int, str)

def __init__(self, info, parent=None):
def __init__(self, info, downloadWay, parent=None):
super(UpdateThread, self).__init__(parent)
self.info = info
self.downloadWay = downloadWay

def run(self):
self.trigger.emit(0, "正在从 Github Release 获取更新")
try:
compressed_url = self.info['assets'][0]['browser_download_url']
file_name = self.info['assets'][0]['name']
except ConnectionError:
self.trigger.emit(1, "更新失败")
return
except requests.exceptions.SSLError:
self.trigger.emit(1, "更新失败")
return
url = compressed_url
self.trigger.emit(0, f"正在从 {self.downloadWay} 获取更新")
if "Github" in self.downloadWay:
try:
compressed_url = self.info['assets'][0]['browser_download_url']
file_name = self.info['assets'][0]['name']
except ConnectionError:
self.trigger.emit(1, "更新失败")
return
except requests.exceptions.SSLError:
self.trigger.emit(1, "更新失败")
return
url = compressed_url
else:
url = f"https://sangonomiya-generic.pkg.coding.net/asta/release/[{self.info['tag_name']}]Asta.zip"
file_name = f"Asta.zip"
if not os.path.exists('temp'):
os.mkdir('temp')
resp = requests.get(url, stream=True)
Expand Down
33 changes: 21 additions & 12 deletions src/modules/Views/settings_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from ..Core.GachaReport import gacha_report_read
from ..Core.GachaReport.gacha_report_utils import getDefaultGameDataPath
from ..Scripts.UI import custom_icon, custom_dialog
from ..Scripts.UI.custom_dialog import ComboboxDialog
from ..Scripts.UI.style_sheet import StyleSheet
from ..Scripts.Utils import config_utils, log_recorder as log, updater
from ..Scripts.Utils.updater import installUpdate, cleanUpdateZip
Expand Down Expand Up @@ -270,26 +271,34 @@ def updateThreadStatusChanged(self, status, content):
installUpdate()
self.updateThreadStateTooltip = None

def __updateCheckCardClicked(self):
cleanUpdateZip()
newVersion = updater.isNeedUpdate(utils.appVersion)
if newVersion is None:
InfoBar.success("提示", "Asta 无需更新", InfoBarPosition.TOP_RIGHT, parent=self.window())
return
elif isinstance(newVersion, tuple):
InfoBar.error("错误", f"Asta 更新请求超过限额\n请于{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(newVersion[1]['X-RateLimit-Reset'])))}之后再试", InfoBarPosition.TOP_RIGHT, parent=self.window())
return
w = MessageBox("更新", f"发现新版本: {newVersion['tag_name']}\n是否更新?", self)
if w.exec():
def __updateReturnSignal(self, msg):
if msg:
downloadWay = "Github Release" if "Github" in msg else "Coding Artifact"
self.updateCheckCard.setEnabled(False)
self.updateThread = UpdateThread(newVersion)
self.updateThread = UpdateThread(self.newVersion, downloadWay)
self.updateThreadStateTooltip = StateToolTip("正在更新", "下载更新中...", self)
self.updateThreadStateTooltip.closedSignal.connect(self.__updateThreadStateTooltipClosed)
self.updateThreadStateTooltip.move(5, 5)
self.updateThreadStateTooltip.show()
self.updateThread.start()
self.updateThread.trigger.connect(self.updateThreadStatusChanged)

def __updateCheckCardClicked(self):
cleanUpdateZip()
self.newVersion = updater.isNeedUpdate(utils.appVersion)
if self.newVersion is None:
InfoBar.success("提示", "Asta 无需更新", InfoBarPosition.TOP_RIGHT, parent=self.window())
return
elif isinstance(self.newVersion, tuple):
InfoBar.error("错误",
f"Asta 更新请求超过限额\n请于{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(self.newVersion[1]['X-RateLimit-Reset'])))}之后再试",
InfoBarPosition.TOP_RIGHT, parent=self.window())
return
w = ComboboxDialog("更新", f"发现新版本: {self.newVersion['tag_name']}\n是否更新?",
["Coding Artifact (国内推荐)", "Github Release (国外推荐)"], self)
w.returnSignal.connect(self.__updateReturnSignal)
w.exec()

def __connectSignalToSlot(self):
cfg.appRestartSig.connect(lambda: InfoBar.warning("警告", self.tr(
"更改将在应用重启后更新"), parent=self.window(), position=InfoBarPosition.TOP_RIGHT))
Expand Down

0 comments on commit 8b6b2f6

Please sign in to comment.