Skip to content

Commit d247495

Browse files
committed
Add check for update feature
1 parent da17820 commit d247495

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

dance.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from configparser import ConfigParser
88
from enum import Enum
99

10+
import aiohttp
1011
import hid
1112
from aiohttp import WSMsgType, web
1213
from pyjoycon import ButtonEventJoyCon, JoyCon
@@ -257,6 +258,26 @@ def save_config(parser):
257258
parser.write(fp)
258259

259260

261+
async def on_startup(app):
262+
print('''
263+
░░ ░░░░░░ ░░ ░░ ░░░░░░ ░░░░░ ░░░ ░░ ░░░░░░ ░░░░░░░
264+
▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒▒▒ ▒▒ ▒▒ ▒▒
265+
▒▒ ▒▒ ▒▒ ▒▒▒▒ ▒▒ ▒▒ ▒▒▒▒▒▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒▒▒▒
266+
▓▓ ▓▓ ▓▓ ▓▓ ▓▓ ▓▓ ▓▓ ▓▓ ▓▓ ▓▓ ▓▓ ▓▓ ▓▓ ▓▓
267+
█████ ██████ ██ ██████ ██ ██ ██ ████ ██████ ███████
268+
269+
Open http://localhost:32623 in your browser.''')
270+
271+
# Check for update
272+
async with aiohttp.ClientSession() as session:
273+
async with session.get('https://api.github.com/repos/redphx/joydance/releases/latest', ssl=False) as resp:
274+
json_body = await resp.json()
275+
latest_version = json_body['tag_name'][1:]
276+
print('Running version {}.'.format(JOYDANCE_VERSION))
277+
if JOYDANCE_VERSION != latest_version:
278+
print('\033[93m{}\033[00m'.format('Version {} is available: https://github.com/redphx/joydance'.format(latest_version)))
279+
280+
260281
async def html_handler(request):
261282
config = dict((parse_config()).items('joydance'))
262283
with open('static/index.html', 'r') as f:
@@ -311,6 +332,7 @@ def favicon_handler(request):
311332
app['joydance_connections'] = {}
312333
app['joycons_info'] = {}
313334

335+
app.on_startup.append(on_startup)
314336
app.add_routes([
315337
web.get('/', html_handler),
316338
web.get('/favicon.png', favicon_handler),

0 commit comments

Comments
 (0)