mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Move update check into its own thread
This commit is contained in:
parent
941849c58f
commit
b64092f881
@ -258,9 +258,9 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
||||
self.device_info = ' '
|
||||
if not opts.no_update_check:
|
||||
self.update_checker = CheckForUpdates(self)
|
||||
QObject.connect(self.update_checker,
|
||||
SIGNAL('update_found(PyQt_PyObject)'), self.update_found)
|
||||
self.update_checker.start(2000)
|
||||
self.update_checker.update_found.connect(self.update_found,
|
||||
type=Qt.QueuedConnection)
|
||||
self.update_checker.start()
|
||||
####################### Status Bar #####################
|
||||
self.status_bar.initialize(self.system_tray_icon)
|
||||
self.status_bar.show_book_info.connect(self.show_book_info)
|
||||
@ -2493,7 +2493,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
||||
if write_settings:
|
||||
self.write_settings()
|
||||
self.check_messages_timer.stop()
|
||||
self.update_checker.stop()
|
||||
self.update_checker.terminate()
|
||||
self.listener.close()
|
||||
self.job_manager.server.close()
|
||||
while self.spare_servers:
|
||||
|
@ -3,7 +3,7 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
import traceback
|
||||
|
||||
from PyQt4.QtCore import QObject, SIGNAL, QTimer
|
||||
from PyQt4.QtCore import QThread, pyqtSignal
|
||||
import mechanize
|
||||
|
||||
from calibre.constants import __version__, iswindows, isosx
|
||||
@ -12,31 +12,27 @@ from calibre.utils.config import prefs
|
||||
|
||||
URL = 'http://status.calibre-ebook.com/latest'
|
||||
|
||||
class CheckForUpdates(QObject):
|
||||
class CheckForUpdates(QThread):
|
||||
|
||||
update_found = pyqtSignal(object)
|
||||
INTERVAL = 24*60*60
|
||||
|
||||
def __init__(self, parent):
|
||||
QObject.__init__(self, parent)
|
||||
self.timer = QTimer(self)
|
||||
self.first = True
|
||||
self.connect(self.timer, SIGNAL('timeout()'), self)
|
||||
self.start = self.timer.start
|
||||
self.stop = self.timer.stop
|
||||
QThread.__init__(self, parent)
|
||||
|
||||
def __call__(self):
|
||||
if self.first:
|
||||
self.timer.setInterval(1000*24*60*60)
|
||||
self.first = False
|
||||
|
||||
try:
|
||||
br = browser()
|
||||
req = mechanize.Request(URL)
|
||||
req.add_header('CALIBRE_VERSION', __version__)
|
||||
req.add_header('CALIBRE_OS',
|
||||
'win' if iswindows else 'osx' if isosx else 'oth')
|
||||
req.add_header('CALIBRE_INSTALL_UUID', prefs['installation_uuid'])
|
||||
version = br.open(req).read().strip()
|
||||
if version and version != __version__:
|
||||
self.emit(SIGNAL('update_found(PyQt_PyObject)'), version)
|
||||
except:
|
||||
traceback.print_exc()
|
||||
def run(self):
|
||||
while True:
|
||||
try:
|
||||
br = browser()
|
||||
req = mechanize.Request(URL)
|
||||
req.add_header('CALIBRE_VERSION', __version__)
|
||||
req.add_header('CALIBRE_OS',
|
||||
'win' if iswindows else 'osx' if isosx else 'oth')
|
||||
req.add_header('CALIBRE_INSTALL_UUID', prefs['installation_uuid'])
|
||||
version = br.open(req).read().strip()
|
||||
if version and version != __version__:
|
||||
self.update_found.emit(version)
|
||||
except:
|
||||
traceback.print_exc()
|
||||
self.sleep(self.INTERVAL)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user