Skip to content

Commit

Permalink
fix: 更新提示不要因为网络错误提示
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhldr committed Dec 8, 2024
1 parent 5d3ef3f commit 7ddfd27
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion data/gtk/lfy.cmb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
(1,215,"GtkWidget","margin-top","5",0,None,None,None,None,None,None,None,None),
(1,216,"(item)","action","app.copy2translate",0,None,None,None,None,None,None,None,None),
(1,216,"(item)","label","Copy to translate",1,None,None,None,None,None,None,None,None),
(2,5,"AdwPreferencesPage","icon-name","applications-system-symbolic",None,None,None,None,None,None,None,None,None),
(2,5,"AdwPreferencesPage","icon-name","dialog-password-symbolic",None,None,None,None,None,None,None,None,None),
(2,5,"AdwPreferencesPage","title","General",1,None,None,None,None,None,None,None,None),
(2,15,"AdwActionRow","subtitle","setup API Key for translation Server, click on the right to the details",1,None,None,None,None,None,None,None,None),
(2,15,"AdwActionRow","subtitle-lines","3",None,None,None,None,None,None,None,None,None),
Expand Down
6 changes: 3 additions & 3 deletions data/gtk/preference.ui
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Created with Cambalache 0.90.4 -->
<!-- Created with Cambalache 0.94.0 -->
<interface>
<requires lib="gtk" version="4.12"/>
<requires lib="libadwaita" version="1.5"/>
<requires lib="libadwaita" version="1.6"/>
<template class="PreferencesDialog" parent="AdwPreferencesDialog">
<child>
<object class="AdwPreferencesPage" id="app_general">
<property name="icon-name">applications-system-symbolic</property>
<property name="icon-name">dialog-password-symbolic</property>
<property name="title" translatable="yes">General</property>
<child>
<object class="AdwPreferencesGroup" id="apg_translate">
Expand Down
33 changes: 19 additions & 14 deletions lfy/utils/check_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from lfy.api.server import TIME_OUT
from lfy.utils.debug import get_logger

MSG_UPDATE_ERROR = "Please update. There is a problem with the current version configuration.\n\n"
MSG_UPDATE_ERROR += PACKAGE_URL


def get_by_url(url, bz=""):
"""通过url获取更新信息
Expand All @@ -18,29 +21,33 @@ def get_by_url(url, bz=""):
bz (str, optional): 备注. Defaults to "".
Returns:
dict: 更新信息
dict/str/None: 更新信息,网络错误的None,无须理会,str为错误信息
"""

try:
request = requests.get(url, timeout=TIME_OUT)
if request.status_code == 200:
get_logger().info("%s update msg ok", bz)
return request.json()
data = request.json()
if "version" in data:
return data

return MSG_UPDATE_ERROR
except requests.exceptions.ConnectTimeout as e:
get_logger().error(e)
return {}
except requests.exceptions.ProxyError as e:
get_logger().error(e)
return {}
except Exception as e: # pylint: disable=W0718
get_logger().error(e)

return None


def get_by_gitee():
"""gitee
Returns:
_type_: _description_
dict/str/None: 更新信息,网络错误的None,无须理会,str为错误信息
"""
url = "https://gitee.com/yuhldr/lfy/raw/main/data/version.json"

Expand All @@ -51,7 +58,7 @@ def get_by_github():
"""github
Returns:
_type_: _description_
dict/str/None: 更新信息,网络错误的None,无须理会,str为错误信息
"""
url = "https://raw.githubusercontent.com/ldrfy/lfy/main/data/version.json"

Expand Down Expand Up @@ -92,20 +99,18 @@ def main():
Returns:
str: 更新信息或None
"""
s = "Please update. There is a problem with the current version configuration.\n\n"
s += PACKAGE_URL
try:
data = get_by_github()
if data is None or "version" not in data:
if not isinstance(data, dict):
data = get_by_gitee()
if data is None or "version" not in data:
return s

if not isinstance(data, dict):
return data

v = data["version"]
if compare_versions(v, VERSION):
return f'New version: {v}\n\nplease upgrade it:\n{data["url"]}\n\n{data["msg"]}'
return None
# pylint: disable=W0718
except Exception as e:
except Exception as e: # pylint: disable=W0718
get_logger().error(e)
return s
return MSG_UPDATE_ERROR

0 comments on commit 7ddfd27

Please sign in to comment.