Skip to content

Commit

Permalink
Merge pull request #1 from kbkozlev/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
kbkozlev authored Oct 19, 2023
2 parents c16f68e + b2e1dba commit ac0b923
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
59 changes: 56 additions & 3 deletions main.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import PySimpleGUI as sg
import pyautogui as pag
import keyboard
import logging
from functions import get_latest_version, create_process, countdown, graceful_exit, get_hotkey, correct_key, is_capslock_on
from functions import get_latest_version, create_process, countdown, graceful_exit, get_hotkey, correct_key, \
is_capslock_on
from threading import Thread, Event
from mouse_jiggler import jiggler
from configurator import Configurator
Expand Down Expand Up @@ -40,6 +41,44 @@ def about_window():
window.close()


def new_version(current_release, latest_release, download_url):
global update_check
layout = [[sg.Push(), sg.T('New Version Available', font=(FONT_FAMILY, 12, 'bold'), justification='c'), sg.Push()],
[sg.T(s=30)],
[sg.T('Current Version:', s=13, justification='r'), sg.T(f'{current_release}',
font=(FONT_FAMILY, 10, 'bold'))],
[sg.T(f'Latest Version:', s=13, justification='r'), sg.T(f'{latest_release}',
font=(FONT_FAMILY, 10, 'bold'))],
[sg.T()],
[sg.Push(), sg.B('Download', key='-DOWNLOAD-', s=8, button_color='#93b7a6'), sg.B('Cancel',
key='-EXIT-', s=8,
button_color='#db5656'),
sg.Push()]]

window = sg.Window("New Version Available", layout, icon=ICON, keep_on_top=True)

while True:
event, values = window.read()

match event:
case sg.WIN_CLOSED:
break

case '-DOWNLOAD-':
if latest_release is not None:
current_release = re.sub(r'[^0-9]', '', current_release)
latest_release = re.sub(r'[^0-9]', '', latest_release)

if int(latest_release) > int(current_release):
webbrowser.open(download_url)
window.close()

case '-EXIT-':
window.close()

update_check = False


def updates_window(current_release):
latest_release, download_url = get_latest_version()
layout = [[sg.Push(), sg.T('Version Info', font=(FONT_FAMILY, 12, 'bold'), justification='c'), sg.Push()],
Expand Down Expand Up @@ -81,7 +120,7 @@ def updates_window(current_release):


def main_window():
global hot_key, bgp
global hot_key, bgp, update_check

app_menu = [['Help', ['About', 'Check for Updates']]]

Expand Down Expand Up @@ -123,6 +162,9 @@ def main_window():
while True:
event, values = window.read(timeout=10)

if update_check:
new_version(RELEASE, latest_release_name, download_url)

keyboard.add_hotkey(hot_key, lambda: graceful_exit(thread_event, window, pag))

if event in ('Exit', sg.WIN_CLOSED):
Expand Down Expand Up @@ -229,7 +271,7 @@ if __name__ == '__main__':
if sys.platform.startswith('win'):
multiprocess.freeze_support()

RELEASE = '1.0.3'
RELEASE = '1.0.2'
WINDOW_TITLE = "X-Sleep"
FONT_FAMILY = "Arial"
HOURS = list(range(0, 24))
Expand All @@ -247,5 +289,16 @@ if __name__ == '__main__':
conf = Configurator()
conf.create_on_start()
hot_key = get_hotkey(conf)
update_check = False

try:
latest_release_name, download_url = get_latest_version()
if latest_release_name is not None:
current_release = re.sub(r'[^0-9]', '', RELEASE)
latest_release = re.sub(r'[^0-9]', '', latest_release_name)
if int(latest_release) > int(current_release):
update_check = True
except Exception as e:
logging.error(e)

main_window()
2 changes: 1 addition & 1 deletion version.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Version: 1.0.2
Version: 1.0.3
CompanyName: Kaloian Kozlev
FileDescription: X-Sleep GUI / Mouse jiggler
InternalName: X-Sleep GUI
Expand Down

0 comments on commit ac0b923

Please sign in to comment.