Calc3D_by_Risen/update.py

95 lines
3.2 KiB
Python
Raw Normal View History

2023-04-08 07:08:13 +03:00
import requests
import webbrowser
import json
import PySimpleGUI as Sgi
import os
import gettext
2023-04-08 07:08:13 +03:00
from texts import ver
with open(os.path.expanduser('setts.json')) as file:
old_data = json.load(file)
if old_data['settings']["locale"] == 'English':
locale = 'en_US'
else:
locale = 'ru_RU'
lang = gettext.translation('locale', localedir='locale', languages=[locale])
lang.install()
_ = lang.gettext
2023-04-08 07:08:13 +03:00
def upd_check():
with open(os.path.expanduser('setts.json')) as json_file:
2023-04-08 07:08:13 +03:00
data = json.load(json_file)
set_theme = data["settings"]["theme"]
version_new = requests.get('https://risenhome.xyz/feed/Risen.json').json()["version"]["ver"]
version_old = ver
if version_new > version_old:
Sgi.theme(set_theme)
layout = [
[Sgi.Text(_("Обновление"))],
[Sgi.Text(_("Вышла новая версия программы\nНужно обновиться"))],
[Sgi.Button(_(' Скачать ')), Sgi.Push(), Sgi.Button(_(' Отмена '))]
2023-04-08 07:08:13 +03:00
]
window = Sgi.Window(_("Проверка обновления"), layout, modal=True)
2023-04-08 07:08:13 +03:00
while True:
event, button = window.read()
if event == _(' Скачать '):
2023-04-08 07:08:13 +03:00
webbrowser.open('https://risenhome.xyz/calc.html', new=2, autoraise=True)
window.close()
elif event == _(' Отмена '):
2023-04-08 07:08:13 +03:00
window.close()
elif event == "Exit" or event == Sgi.WIN_CLOSED:
break
else:
Sgi.theme(set_theme)
layout = [
[Sgi.Text(_(f"Последняя версия: {version_new}\nВаша версия: {version_old}\n\nОбновление не требуется"))],
[Sgi.Button(_(' Закрыть '))]
2023-04-08 07:08:13 +03:00
]
window = Sgi.Window(_("Проверка обновления"), layout, modal=True)
2023-04-08 07:08:13 +03:00
while True:
event, button = window.read()
if event == _(' Закрыть '):
2023-04-08 07:08:13 +03:00
window.close()
elif event == "Exit" or event == Sgi.WIN_CLOSED:
break
def upd_start():
with open(os.path.expanduser('~\Documents\Calc3DbyRisen\setts.json')) as json_file:
data = json.load(json_file)
set_theme = data["settings"]["theme"]
version_new = requests.get('https://risenhome.xyz/feed/Risen.json').json()["version"]["ver"]
version_old = ver
if version_new > version_old:
Sgi.theme(set_theme)
layout = [
[Sgi.Text(_("Обновление"))],
[Sgi.Text(_("Вышла новая версия программы\nНужно обновиться"))],
[Sgi.Button(_(' Скачать ')), Sgi.Push(), Sgi.Button(' Отмена ')]
2023-04-08 07:08:13 +03:00
]
window = Sgi.Window(_("Вышла новая версия!"), layout, modal=True)
2023-04-08 07:08:13 +03:00
while True:
event, button = window.read()
if event == _(' Скачать '):
2023-04-08 07:08:13 +03:00
webbrowser.open('https://risenhome.xyz', new=2, autoraise=True)
window.close()
elif event == _(' Отмена '):
2023-04-08 07:08:13 +03:00
window.close()
elif event == "Exit" or event == Sgi.WIN_CLOSED:
break