From d2474959ce65df23d209f934d3f252375e5e780e Mon Sep 17 00:00:00 2001 From: redphx <96280+redphx@users.noreply.github.com> Date: Sat, 23 Apr 2022 10:20:05 +0700 Subject: [PATCH] Add check for update feature --- dance.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/dance.py b/dance.py index b7c243a..8801129 100644 --- a/dance.py +++ b/dance.py @@ -7,6 +7,7 @@ import time from configparser import ConfigParser from enum import Enum +import aiohttp import hid from aiohttp import WSMsgType, web from pyjoycon import ButtonEventJoyCon, JoyCon @@ -257,6 +258,26 @@ def save_config(parser): parser.write(fp) +async def on_startup(app): + print(''' + ░░ ░░░░░░ ░░ ░░ ░░░░░░ ░░░░░ ░░░ ░░ ░░░░░░ ░░░░░░░ + ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒▒▒ ▒▒ ▒▒ ▒▒ + ▒▒ ▒▒ ▒▒ ▒▒▒▒ ▒▒ ▒▒ ▒▒▒▒▒▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒▒▒▒ +▓▓ ▓▓ ▓▓ ▓▓ ▓▓ ▓▓ ▓▓ ▓▓ ▓▓ ▓▓ ▓▓ ▓▓ ▓▓ ▓▓ + █████ ██████ ██ ██████ ██ ██ ██ ████ ██████ ███████ + +Open http://localhost:32623 in your browser.''') + + # Check for update + async with aiohttp.ClientSession() as session: + async with session.get('https://api.github.com/repos/redphx/joydance/releases/latest', ssl=False) as resp: + json_body = await resp.json() + latest_version = json_body['tag_name'][1:] + print('Running version {}.'.format(JOYDANCE_VERSION)) + if JOYDANCE_VERSION != latest_version: + print('\033[93m{}\033[00m'.format('Version {} is available: https://github.com/redphx/joydance'.format(latest_version))) + + async def html_handler(request): config = dict((parse_config()).items('joydance')) with open('static/index.html', 'r') as f: @@ -311,6 +332,7 @@ app = web.Application() app['joydance_connections'] = {} app['joycons_info'] = {} +app.on_startup.append(on_startup) app.add_routes([ web.get('/', html_handler), web.get('/favicon.png', favicon_handler),