diff --git a/backend.py b/backend.py index 5cdb407..396e418 100644 --- a/backend.py +++ b/backend.py @@ -6,6 +6,30 @@ import re import pathlib import json +import socket + +def checkConnection(host="8.8.8.8", port=53, timeout=3): + try: + socket.setdefaulttimeout(timeout) + socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port)) + return True + except socket.error: + return False + +def regainedConnection() -> bool : + global lostConnection + checkedConnection = checkConnection() + if checkedConnection == True : + if checkedConnection == lostConnection : + lostConnection = not checkedConnection + return True + else : + return False + else : + lostConnection = not checkedConnection + return True + +lostConnection = True def getArch() -> str : arch = platform.machine() @@ -57,26 +81,37 @@ # Get the versions of the Godot Engine and sort them from latest to oldest -def verOptions(mono: str) -> list: +def verOptions(mono: str, curVersion: list|None) -> list: tag_list = [] - response = requestGitHubInfo() - installed_files = getAllFiles(mono) - installed_files.sort(reverse=True) + + if regainedConnection() : + response = requestGitHubInfo() + else : + response = curVersion if type(response) == dict : - return ['No options available'] + installed_files = getAllFiles(mono) + installed_files.sort(reverse=True) + if installed_files != [] : + return installed_files + else: + tag_list.append('No options available') + elif curVersion != None and checkConnection() : + return curVersion for i in response : tag_list.append(i['tag_name']) - - tag_list.sort(reverse=True) if tag_list != [] : + tag_list.sort(reverse=True) tag_list.pop() - elif installed_files != [] : - tag_list = installed_files else : - tag_list.append('No options available') + installed_files = getAllFiles(mono) + installed_files.sort(reverse=True) + if installed_files != [] : + return installed_files + else: + tag_list.append('No options available') return tag_list diff --git a/main.py b/main.py index f1bfb25..38d594c 100644 --- a/main.py +++ b/main.py @@ -40,10 +40,7 @@ app_path.set(fd.askdirectory(initialdir=pathlib.Path.home(),mustexist=True)) def isInstalled(*event) -> None : - global CUR_VERSION - if CUR_VERSION != backend.verOptions(mono.get()) : - updateVersionList() - + global strvar DOWNLOAD_BUTTON = tk.Button(CANVAS,activebackground="#aaa",bg="#888",text="Download",command=tryDownload) REMOVE_BUTTON = tk.Button(CANVAS,activebackground="#aaa",bg="#888",text="Remove",command=tryRemove) @@ -92,22 +89,25 @@ tokenSetting.place(height=24,width=264,x=96,y=124) tk.Button(settingsCanvas,text="Save",activebackground='#aaa',bg='#888',command=saveSettings).place(height=36,width=90,x=195,y=180) - VERSION_MENU.destroy() - updateVersionList() - FRONTEND.event_generate('<>',when='tail') - def updateVersionList() -> None : global CUR_VERSION - CUR_VERSION = backend.verOptions(mono.get()) - strvar.set(CUR_VERSION[0]) - VERSION_MENU = ttk.Combobox(master=CANVAS,textvariable=strvar,values=CUR_VERSION,state='readonly',font="Sans 12",style='M.TCombobox') - VERSION_MENU.bind('<>',isInstalled) - VERSION_MENU.bind('',isInstalled) - VERSION_MENU.place(width=256,height=36,relx=0.31,y=120) + global VERSION_MENU + global strvar + updatedList = backend.verOptions(mono.get(),CUR_VERSION) + if CUR_VERSION != updatedList : + CUR_VERSION = updatedList + strvar = tk.StringVar(CANVAS,CUR_VERSION[0]) + VERSION_MENU = ttk.Combobox(master=CANVAS,textvariable=strvar,values=CUR_VERSION,state='readonly',font="Sans 12",style='M.TCombobox') + VERSION_MENU.bind('<>',isInstalled) + VERSION_MENU.bind('',isInstalled) + VERSION_MENU.place(width=256,height=36,relx=0.31,y=120) + isInstalled() def setMono() -> None : MONO_CHECK.event_generate('<>',when='tail') +CUR_VERSION = None + FRONTEND = tk.Tk() FRONTEND.geometry("650x480") FRONTEND.resizable(False,False) @@ -117,21 +117,15 @@ ttk.Style().configure("M.TCombobox",background="#888") ttk.Style().map("M.TCombobox",background=[('active','#aaa')]) -CANVAS = tk.Canvas(FRONTEND,bg="#4811a9") +CANVAS = tk.Canvas(FRONTEND,bg="#11a9a9") LAUNCH_BUTTON = tk.Button(CANVAS,activebackground="#aaa",bg="#888",text="Launch",command=tryLaunch) DOWNLOAD_BUTTON = tk.Button(CANVAS,activebackground="#aaa",bg="#888",text="Download",command=tryDownload) REMOVE_BUTTON = tk.Button(CANVAS,activebackground="#aaa",bg="#888",text="Remove",command=tryRemove) mono = tk.StringVar(CANVAS,'no_mono') -CUR_VERSION = backend.verOptions(mono.get()) -strvar = tk.StringVar(CANVAS,CUR_VERSION[0]) -VERSION_MENU = ttk.Combobox(master=CANVAS,textvariable=strvar,values=CUR_VERSION,state='readonly',font="Sans 12",style='M.TCombobox') -VERSION_MENU.bind('<>',isInstalled) -VERSION_MENU.bind('',isInstalled) - -MONO_CHECK = tk.Checkbutton(CANVAS,text="Mono Version",bg="#7245be",fg='#000',activebackground="#804ed8",activeforeground="#000",offvalue='no_mono',onvalue='mono',variable=mono,command=isInstalled) +MONO_CHECK = tk.Checkbutton(CANVAS,text="Mono Version",bg="#45b6be",fg='#000',activebackground="#4ed8cc",activeforeground="#000",offvalue='no_mono',onvalue='mono',variable=mono,command=updateVersionList) Menubar = tk.Menu(CANVAS,type='menubar') @@ -144,9 +138,8 @@ Menubar.add_cascade(label='File',menu=file_menu) CANVAS.place(relheight=1,relwidth=1) -CANVAS.create_text(325,36,font="Sans 24",text="Godot Version Manager") +CANVAS.create_text(325,36,font="JetBrainsMono 24",text="Godot Version Manager") LAUNCH_BUTTON.place(width=72,height=36,relx=0.55,y=380) -isInstalled() updateVersionList() MONO_CHECK.place(width=128,height=24,relx=0.75,y=126)