-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcheck.py
69 lines (60 loc) · 2.5 KB
/
check.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
# -*-coding:utf-8 -*-
import os
import flet as ft
import requests
GITHUB_URL = "https://github.com/Bronya0/epub-merge"
UPDATE_URL = "https://api.github.com/repos/Bronya0/epub-merge/releases/latest"
BASEDIR = os.path.dirname(__file__)
def close_dlg(e):
e.page.dialog.open = False
e.page.update()
def version_check(page: ft.Page):
print("开始检查版本……", UPDATE_URL)
res = requests.get(UPDATE_URL)
if res.status_code != 200:
res = requests.get(UPDATE_URL)
if res.status_code != 200:
res = requests.get(UPDATE_URL)
if res.status_code != 200:
return
latest_version = res.json()['tag_name']
body = res.json()['body']
version = open(f'{BASEDIR}/assets/version.txt', 'r', encoding='utf-8').read().rstrip().replace('\n', '')
if version != latest_version:
print("需要更新 {} -> {}".format(version, latest_version))
page.dialog = ft.AlertDialog(
modal=False,
title=ft.Text("🎉🎉发现新版本: {}".format(latest_version)),
actions=[
ft.Row(
controls=[
ft.Column(
[
ft.Column(
[
ft.Text(f"当前版本:{version}"),
ft.Text(body, selectable=True),
],
scroll=ft.ScrollMode.ALWAYS,
height=180,
width=600
),
ft.Row(
[
ft.TextButton(text="前往下载", url=GITHUB_URL),
ft.TextButton(text="下次再说", on_click=close_dlg, tooltip="长期未更新可能会导致故障累积",
style=ft.ButtonStyle(color=ft.colors.GREY)),
]
)
],
scroll=ft.ScrollMode.ALWAYS,
)],
scroll=ft.ScrollMode.ALWAYS,
)
],
actions_alignment=ft.MainAxisAlignment.CENTER,
shape=ft.RoundedRectangleBorder(radius=8),
open=True,
)
page.update()