Skip to content

Commit 1c4523f

Browse files
比较版本号
1 parent 5d2d052 commit 1c4523f

File tree

1 file changed

+18
-29
lines changed

1 file changed

+18
-29
lines changed

main.py

+18-29
Original file line numberDiff line numberDiff line change
@@ -239,35 +239,6 @@ def update(self):
239239
except Exception as e:
240240
print(f"更新时发生错误: {e}")
241241
logger.error(f"更新时发生错误: {e}")
242-
'''
243-
if self.checked:
244-
return
245-
else:
246-
self.checked = True
247-
if self.settings_data['update'] == 1:
248-
info = download_version()
249-
if info["version"] > self.settings_data["version"]:
250-
self.show_tooltip()
251-
else:
252-
print("已经是最新版本")
253-
elif self.settings_data['update'] == 2:
254-
result = WeatherLate(self.settings_data["AutoUpdate"])
255-
if result > 7:
256-
info = download_version()
257-
if info["version"] > self.settings_data["version"]:
258-
self.show_tooltip()
259-
else:
260-
print("已经是最新版本")
261-
now = datetime.now()
262-
formatted_date = now.strftime('%Y-%m-%d') # 格式:年-月-日
263-
self.settings_data["AutoUpdate"] = formatted_date
264-
with open('WCMain/settings.json', 'w') as file:
265-
json.dump(self.settings_data, file, indent=4)
266-
else:
267-
print("天数不足")
268-
'''
269-
270-
271242

272243
def show_tooltip(self):
273244
# 使用 QTimer 让提示信息在系统托盘图标上显示
@@ -277,6 +248,24 @@ def show_tooltip(self):
277248
QSystemTrayIcon.Information,
278249
2000
279250
))
251+
252+
def check_version(self,version1, version2):
253+
# 将版本号拆分为数字列表
254+
v1 = list(map(int, version1.split('.')))
255+
v2 = list(map(int, version2.split('.')))
256+
257+
# 填充零使长度一致
258+
max_len = max(len(v1), len(v2))
259+
v1 += [0] * (max_len - len(v1))
260+
v2 += [0] * (max_len - len(v2))
261+
262+
# 逐位比较
263+
for a, b in zip(v1, v2):
264+
if a > b:
265+
return 1
266+
elif a < b:
267+
return -1
268+
return 0
280269

281270
def icon_activated(self, reason):
282271
if reason == QSystemTrayIcon.Trigger:

0 commit comments

Comments
 (0)