Jelajahi Sumber

优化版本升级模块

Ricky 2 tahun lalu
induk
melakukan
506ed58ca3
6 mengubah file dengan 63 tambahan dan 42 penghapusan
  1. 3 3
      bin/windows/version.txt
  2. 2 2
      constant/constant.py
  3. TEMPAT SAMPAH
      img/loading.gif
  4. 2 1
      run.py
  5. 25 34
      spider/upgradespider.py
  6. 31 2
      ui/main/main.py

+ 3 - 3
bin/windows/version.txt

@@ -6,8 +6,8 @@ VSVersionInfo(
   ffi=FixedFileInfo(
     # filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4)
     # Set not needed items to zero 0.
-    filevers=(4, 7, 7, 20230424),
-    prodvers=(4, 7, 7, 20230424),
+    filevers=(4, 7, 7, 20230425),
+    prodvers=(4, 7, 7, 20230425),
     # Contains a bitmask that specifies the valid bits 'flags'r
     mask=0x3f,
     # Contains a bitmask that specifies the Boolean attributes of the file.
@@ -31,7 +31,7 @@ VSVersionInfo(
         u'080404b0',
         [StringStruct(u'CompanyName', u'个人'),
         StringStruct(u'FileDescription', u'若依框架修改器'),
-        StringStruct(u'FileVersion', u'4.7.7.202304024'),
+        StringStruct(u'FileVersion', u'4.7.7.202304025'),
         StringStruct(u'LegalCopyright', u'Copyright (C) 2020-2023 Ricky. All Rights Reserved'),
         StringStruct(u'ProductName', u'常用工具'),
         StringStruct(u'ProductVersion', u'4.7.7')])

+ 2 - 2
constant/constant.py

@@ -6,8 +6,8 @@
 """
 系统常量
 """
-APP_VERSION_INT = 420230424
-APP_VERSION_STRING = '4.7.7.20230424'
+APP_VERSION_INT = 420230425
+APP_VERSION_STRING = '4.7.7.20230425'
 PYTHON_VERSION_STRING = '3.7.9'
 WXPYTHON_VERSION_STRING = '4.1.0'
 # 禁止修改的目录

TEMPAT SAMPAH
img/loading.gif


+ 2 - 1
run.py

@@ -22,7 +22,8 @@ if __name__ == '__main__':
     frame.Show(True)
     try:
         # 检测更新
-        upgradespider.check()
+        t = upgradespider.UpgradeThread(frame, False)
+        t.start()
         app.MainLoop()
 
     except Exception as err:

+ 25 - 34
spider/upgradespider.py

@@ -14,39 +14,30 @@ from constant import constant
 from loguru import logger
 
 
-def _get(show_no_new_version_tip=False):
-    """
-    异步解析
+class UpgradeThread(threading.Thread):
+    def __init__(self, parent, show_no_new_version_tip=False):
+        """
+        :param parent:  主线程UI
+        """
+        super(UpgradeThread, self).__init__()
+        self.parent = parent
+        self.show_no_new_version_tip = show_no_new_version_tip
+        self.setDaemon(True)
 
-    参数:
-        show_no_new_version_tip (bool): 是否显示没有新版本提示,默认为False
-    """
-    url = 'https://gitee.com/lpf_project/common-tools/tags'
-    wb_data = requests.get(url)
-    soup = BeautifulSoup(wb_data.text, 'html.parser')
-    tags = soup.select('div.tag-item-action.tag-name>a')
-    is_has_new_version = False
-    for tag in tags:
-        version = ''.join(list(filter(str.isdigit, tag['title'])))
+    def run(self):
+        url = 'https://gitee.com/lpf_project/RuoYi-MT/releases'
+        wb_data = requests.get(url)
+        soup = BeautifulSoup(wb_data.text, 'html.parser')
+        tags = soup.select('div .release-tag-item .release-meta .tag-name')
+        if len(tags) == 0:
+            return
+        content = soup.select(
+            'div .release-tag-item .release-body .content .markdown-body p')[0].text
+        tag = tags[0]
+        version = ''.join(list(filter(str.isdigit, tag['data-tag-name'])))
         if int(version) > constant.APP_VERSION_INT:
-            is_has_new_version = True
-            logger.info('检查更新结果:发现新的版本-{}', tag['title'])
-            wx.MessageDialog(
-                None, '发现新的版本【%s】,请前往gitee下载,\ngitee地址可以查看“关于我们”中的“软件官网”' %
-                tag['title'], '版本升级提醒', wx.OK).ShowModal()
-            break
-    if not is_has_new_version:
-        logger.info('检查更新结果:当前版本是最新版本!')
-        if show_no_new_version_tip:
-            wx.MessageDialog(None, '当前版本是最新版本!', '检测更新', wx.OK).ShowModal()
-
-
-def check(show_no_new_version_tip=False):
-    """
-    检测更新
-
-    参数:
-        show_no_new_version_tip (bool): 是否显示没有新版本提示,默认为False
-    """
-    thread = threading.Thread(target=_get, args=(show_no_new_version_tip, ))
-    thread.start()
+            wx.CallAfter(self.parent.upgrade_call_after, True,
+                         self.show_no_new_version_tip, tag['data-tag-name'], content)
+        else:
+            wx.CallAfter(self.parent.upgrade_call_after,
+                         False, self.show_no_new_version_tip)

+ 31 - 2
ui/main/main.py

@@ -131,6 +131,7 @@ class Main(frame.MainFrame):
         self.m_statusbar.SetStatusText(
             '  WxPython版本:' + constant.WXPYTHON_VERSION_STRING, 2)
         self.m_statusbar.SetStatusText('  联系作者(RICKY):QQ11748854', 3)
+
         self.Centre()
 
     def task_start(self):
@@ -172,6 +173,32 @@ class Main(frame.MainFrame):
         self.m_text_log.AppendText(message)
         self.m_text_log.ShowPosition(self.m_text_log.GetLastPosition())
 
+    def upgrade_call_after(self, is_new_version, show_no_new_version_tip, title, message):
+        """
+        接收更新程序线程传递消息,弹窗提示框
+
+        参数:
+            self (object): 当前对象
+            is_new_version (bool): 是否是新版本
+            show_no_new_version_tip (bool): 是否显示提示
+            title (str): 标题
+            message (str): 消息
+        """
+        if is_new_version:
+            logger.info('检查更新结果:发现新的版本-{}', title)
+            dlg = wx.GenericMessageDialog(
+                self, '新版本:%s\n\n更新日志:\n%s' %
+                (title, message), '版本更新提醒', wx.OK | wx.CANCEL)
+            dlg.SetOKCancelLabels('前往升级', '忽略更新')
+            if dlg.ShowModal() == wx.ID_OK:
+                wx.LaunchDefaultBrowser(
+                    'https://gitee.com/lpf_project/RuoYi-MT/releases')
+            dlg.Destroy()
+        else:
+            logger.info('检查更新结果:当前版本是最新版本!')
+            if show_no_new_version_tip:
+                wx.MessageDialog(self, '当前版本是最新版本!', '检测更新', wx.OK).ShowModal()
+
     def check_input(self):
         """
         校验输入框
@@ -230,7 +257,8 @@ class Main(frame.MainFrame):
 
     # 实现退出菜单事件
     def OnMenuClickEventExit(self, event):
-        dlg = wx.MessageDialog(None, '确认退出程序吗?', '退出提醒', wx.YES_NO)
+        dlg = wx.MessageDialog(self, '确认退出程序吗?', '退出提醒', wx.YES_NO)
+        dlg.SetYesNoLabels('退出', '取消')
         if dlg.ShowModal() == wx.ID_YES:
             self.Destroy()
         dlg.Destroy()
@@ -292,7 +320,8 @@ class Main(frame.MainFrame):
 
     # 实现检测更新事件
     def OnUpgrade(self, event):
-        upgradespider.check(True)
+        t = upgradespider.UpgradeThread(self, True)
+        t.start()
 
     # 实现使用指南事件
     def OnManual(self, event):