Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 99 additions & 1 deletion GUI/about.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import wx
import wx.adv

from core.tools import *
import threading
from core.config import Config
import webbrowser
import datetime

class AboutWindow():
def __init__(self):
Expand All @@ -17,3 +20,98 @@ def __init__(self):

def Show(self):
wx.adv.AboutBox(self.info)

class UpdateWindow(wx.Dialog):
def __init__(self):
super().__init__(None, title="检查更新 - Boss Key", style=wx.DEFAULT_DIALOG_STYLE | wx.STAY_ON_TOP | wx.RESIZE_BORDER)
self.SetIcon(wx.Icon(wx.Image(Config.icon).ConvertToBitmap()))

self.init_Load_UI()

self.SetSize((500, 600))

self.Center()

self.onCheckUpdate()

def init_Load_UI(self):
self.panel = wx.Panel(self)
self.sizer = wx.BoxSizer(wx.VERTICAL)

self.ai=wx.ActivityIndicator(self.panel)
self.ai.Start()

text = wx.StaticText(self.panel, label="正在获取版本信息,请稍后...")

# 使元素完全居中
self.sizer.AddStretchSpacer(3)
self.sizer.Add(self.ai, 0, wx.ALIGN_CENTER)
self.sizer.AddStretchSpacer()
self.sizer.Add(text, 0, wx.ALIGN_CENTER)
self.sizer.AddStretchSpacer(3)
self.panel.SetSizer(self.sizer)

def onCheckUpdate(self):
def checkUpdate():
try:
info = check_update()
except:
wx.CallAfter(self.init_error_UI)
return

wx.CallAfter(self.init_real_UI,info)
threading.Thread(target=checkUpdate).start()

def init_real_UI(self,info):
## 清空原有元素
self.sizer.Clear()
self.ai.Stop()
self.ai.Destroy()

for i in self.panel.GetChildren():
i.Destroy()

## 重绘UI

current_version = wx.StaticText(self.panel, label="当前版本:"+Config.AppVersion)
self.sizer.Add(current_version, 0, wx.ALIGN_LEFT|wx.EXPAND|wx.ALL, 5)

new_version = wx.StaticText(self.panel, label="最新版本:"+info['tag_name'])
self.sizer.Add(new_version, 0, wx.ALIGN_LEFT|wx.EXPAND|wx.ALL, 5)

release_time = wx.StaticText(self.panel, label="发布时间:"+datetime.datetime.strftime(info['published_at'], "%Y-%m-%d %H:%M:%S"))
self.sizer.Add(release_time, 0, wx.ALIGN_LEFT|wx.EXPAND|wx.ALL, 5)

info_label = wx.StaticText(self.panel, label="更新内容:")
info_text = wx.TextCtrl(self.panel, style=wx.TE_MULTILINE | wx.TE_READONLY)
if Config.AppVersion == info['tag_name']:
addtion_info = "您的版本已经是最新版本 :) \n\n"
else:
addtion_info = "有更新版本可用,请前往下载 :) \n\n"
info_text.SetValue(addtion_info+info['body'])
self.sizer.Add(info_label, 0, wx.ALIGN_LEFT|wx.EXPAND|wx.ALL, 5)
self.sizer.Add(info_text, 1, wx.ALIGN_LEFT|wx.EXPAND|wx.ALL, 5)

button_sizer = wx.BoxSizer(wx.VERTICAL)
for i in info['assets']:
download_button = wx.Button(self.panel, label=i['name'])
download_button.Bind(wx.EVT_BUTTON, lambda e: self.Btn_click(i['browser_download_url'],Config.AppVersion == info['tag_name']))
button_sizer.Add(download_button, 0, wx.ALIGN_LEFT|wx.EXPAND|wx.ALL, 5)

self.sizer.Add(button_sizer, 0, wx.ALIGN_LEFT|wx.EXPAND|wx.ALL, 5)

self.panel.SetSizer(self.sizer)
self.sizer.Layout()

def init_error_UI(self):
self.ai.Stop()
wx.MessageBox("无法连接至更新服务器,情稍后再试","检查更新失败",wx.OK | wx.ICON_ERROR)
self.Close()

def Btn_click(self,url,is_latest):
if is_latest:
ask=wx.MessageBox("您的版本已经是最新版本,是否仍前往下载","无需更新",wx.OK | wx.ICON_INFORMATION | wx.CANCEL | wx.CANCEL_DEFAULT)
if ask == wx.CANCEL:
return
webbrowser.open(url)
self.Hide()
12 changes: 11 additions & 1 deletion GUI/taskbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class TaskBarIcon(wx.adv.TaskBarIcon):

MENU_SETTING,MENU_EXIT,MENU_STARTUP = wx.NewIdRef(count=3)
MENU_SETTING,MENU_EXIT,MENU_STARTUP,MENU_UPDATE = wx.NewIdRef(count=4)

def __init__(self):
super().__init__()
Expand All @@ -21,12 +21,15 @@ def BindEVT(self):
self.Bind(wx.EVT_MENU, self.onStartup, id=self.MENU_STARTUP)
self.Bind(wx.EVT_MENU, self.onExit, id=self.MENU_EXIT)
self.Bind(wx.EVT_MENU, self.onAbout, id=wx.ID_ABOUT)
self.Bind(wx.EVT_MENU, self.onUpdate, id=self.MENU_UPDATE)

def CreatePopupMenu(self):
menu = wx.Menu()
menu.Append(self.MENU_SETTING, '设置')
menu.Append(self.MENU_STARTUP, '开机自启', kind=wx.ITEM_CHECK)
menu.Check(self.MENU_STARTUP, tool.checkStartup("Boss Key Application",Config.file_path))
menu.AppendSeparator()
menu.Append(self.MENU_UPDATE, '检查更新')
menu.Append(wx.ID_ABOUT, '关于')
menu.AppendSeparator()
menu.Append(self.MENU_EXIT, '退出')
Expand All @@ -53,3 +56,10 @@ def onAbout(self,e):
def onExit(self,e):
Config.HotkeyWindow.Close()
sys.exit(0)

def onUpdate(self,e):
if Config.UpdateWindow!="":
Config.UpdateWindow.Show()
else:
Config.UpdateWindow=about.UpdateWindow()
Config.UpdateWindow.Show()
1 change: 1 addition & 0 deletions core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Config:
SettingWindow=""
HotkeyWindow=""
TaskBarIcon=""
UpdateWindow=""

recording_hotkey = False
recorded_hotkey = None
Expand Down
23 changes: 8 additions & 15 deletions core/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
def check_update():
requests.packages.urllib3.disable_warnings()
# 获取最新版本信息
response = requests.get("https://ivanhanloth.github.io/Boss-Key/releases.json", verify=False,timeout=10)
try:
response = requests.get("https://ivanhanloth.github.io/Boss-Key/releases.json", verify=False,timeout=10)

if response.status_code != 200:
raise Exception("无法检查更新")
except:
raise Exception("无法检查更新")

if response.status_code != 200:
return None

releases = json.loads(response.text)

for release in releases:
Expand All @@ -25,17 +28,7 @@ def check_update():
# 找到最新的版本
latest_release = max(releases, key=lambda x: x['published_at'])

# 找到指定tag的版本
target_release = next((release for release in releases if release['tag_name'] == Config.AppVersion), None)

if target_release is None:
return None

# 比较发布时间
if target_release['published_at'] < latest_release['published_at']:
return latest_release
else:
return None
return latest_release

def modifyStartup(name: str, file_path: str):
key = OpenKey(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Run", 0, KEY_ALL_ACCESS)
Expand Down