Skip to content

Commit

Permalink
修复无法获取最新版本号的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiyiYo committed Feb 22, 2025
1 parent ea1bc09 commit ebb66ca
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
26 changes: 25 additions & 1 deletion app/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,28 @@ def runDetachedProcess(executable: Union[str, Path], args=None, cwd=None):
if cwd:
process.setWorkingDirectory(str(cwd))

process.startDetached(str(executable).replace("\\", "/"), args or [])
process.startDetached(str(executable).replace("\\", "/"), args or [])

def getSystemProxy():
""" get system proxy """
if sys.platform == "win32":
try:
import winreg

with winreg.OpenKey(winreg.HKEY_CURRENT_USER, r'Software\Microsoft\Windows\CurrentVersion\Internet Settings') as key:
enabled, _ = winreg.QueryValueEx(key, 'ProxyEnable')

if enabled:
return "http://" + winreg.QueryValueEx(key, 'ProxyServer')
except:
pass
elif sys.platform == "darwin":
s = os.popen('scutil --proxy').read()
info = dict(re.findall('(?m)^\s+([A-Z]\w+)\s+:\s+(\S+)', s))

if info.get('HTTPEnable') == '1':
return f"http://{info['HTTPProxy']}:{info['HTTPPort']}"
elif info.get('ProxyAutoConfigEnable') == '1':
return info['ProxyAutoConfigURLString']

return os.environ.get("http_proxy")
13 changes: 12 additions & 1 deletion app/service/version_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from PySide6.QtCore import QVersionNumber

from ..common.setting import VERSION
from ..common.utils import getSystemProxy
from ..common.exception_handler import exceptionHandler


Expand All @@ -20,7 +21,17 @@ def __init__(self):
def getLatestVersion(self):
""" get latest version """
url = "https://api.github.com/repos/zhiyiYo/Fluent-M3U8/releases/latest"
response = requests.get(url, timeout=2)
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36 Edg/112.0.1722.64"
}

proxy = getSystemProxy()
proxies = {
"http": proxy,
"https": proxy
}

response = requests.get(url, headers=headers, timeout=5, allow_redirects=True, proxies=proxies)
response.raise_for_status()

# parse version
Expand Down
2 changes: 1 addition & 1 deletion app/view/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def onVersionInfoFetched(self, success, ignore=False):
if success:
self.showMessageBox(
self.tr('Updates available'),
self.tr('A new version')+f" {self.versionManager.lastestVersion[1:]} " +self.tr('is available. Do you want to download this version?'),
self.tr('A new version')+f" {self.versionManager.lastestVersion} " +self.tr('is available. Do you want to download this version?'),
True,
lambda: openUrl(RELEASE_URL)
)
Expand Down

0 comments on commit ebb66ca

Please sign in to comment.