Skip to content

Commit

Permalink
add version manager
Browse files Browse the repository at this point in the history
  • Loading branch information
cosven committed May 9, 2016
1 parent f27ba92 commit a4a5525
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
5 changes: 4 additions & 1 deletion feeluown/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
import asyncio

from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPainter, QImage, QPixmap, QIcon
Expand All @@ -13,6 +13,7 @@
from .theme import ThemeManager
from .ui import Ui
from .utils import darker
from .version import VersionManager
from feeluown.libs.widgets.base import FFrame


Expand All @@ -24,6 +25,7 @@ def __init__(self):
self.theme_manager = ThemeManager(self)
self.hotkey_manager = Hotkey(self)
self.plugins_manager = PluginsManager(self)
self.version_manager = VersionManager(self)
self.theme_manager.set_theme(DEFAULT_THEME_NAME)

self.ui = Ui(self)
Expand Down Expand Up @@ -86,6 +88,7 @@ def paintEvent(self, event):

def _init_managers(self):
self.plugins_manager.scan()
asyncio.Task(self.version_manager.check_release())

def set_theme_style(self):
theme = self.theme_manager.current_theme
Expand Down
36 changes: 36 additions & 0 deletions feeluown/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import asyncio
import logging
from functools import partial


logger = logging.getLogger(__name__)


class VersionManager(object):
current_version = 'v9.0a'

def __init__(self, app):
self._app = app

@asyncio.coroutine
def check_release(self):
url = 'https://api.github.com/repos/cosven/FeelUOwn/releases'
logger.info('正在查找新版本...')
try:
loop = asyncio.get_event_loop()
future = loop.run_in_executor(
None, partial(self._app.request.get, url, timeout=5))
res = yield from future
if not res.status_code == 200:
logger.warning('connect to api.github.com timeout')
return
releases = res.json()
for release in releases:
if release['tag_name'] > self.current_version:
title = u'发现新版本 %s hoho' % release['tag_name']
logger.info(title)
content = release['name']
self._app.message(title)
break
except Exception as e:
logger.error(str(e))

0 comments on commit a4a5525

Please sign in to comment.