TrezorCompatiblePlugin: make it a thread job

We shouldn't be using QT gui threads
This commit is contained in:
Neil Booth 2016-01-03 20:46:47 +09:00
parent 1ffc14df76
commit 6516b28840
1 changed files with 11 additions and 10 deletions

View File

@ -12,6 +12,7 @@ from electrum.plugins import BasePlugin, hook
from electrum.transaction import (deserialize, is_extended_pubkey, from electrum.transaction import (deserialize, is_extended_pubkey,
Transaction, x_to_xpub) Transaction, x_to_xpub)
from electrum.wallet import BIP32_HD_Wallet, BIP44_Wallet from electrum.wallet import BIP32_HD_Wallet, BIP44_Wallet
from electrum.util import ThreadJob
class DeviceDisconnectedError(Exception): class DeviceDisconnectedError(Exception):
pass pass
@ -138,7 +139,7 @@ class TrezorCompatibleWallet(BIP44_Wallet):
self.plugin.sign_transaction(self, tx, prev_tx, xpub_path) self.plugin.sign_transaction(self, tx, prev_tx, xpub_path)
class TrezorCompatiblePlugin(BasePlugin): class TrezorCompatiblePlugin(BasePlugin, ThreadJob):
# Derived classes provide: # Derived classes provide:
# #
# class-static variables: client_class, firmware_URL, handler_class, # class-static variables: client_class, firmware_URL, handler_class,
@ -166,20 +167,20 @@ class TrezorCompatiblePlugin(BasePlugin):
self.clients = set() self.clients = set()
# The device wallets we have seen to inform on reconnection # The device wallets we have seen to inform on reconnection
self.paired_wallets = set() self.paired_wallets = set()
# Do an initial scan
self.last_scan = 0 self.last_scan = 0
self.timer_actions()
@hook def thread_jobs(self):
def timer_actions(self):
# Scan connected devices every second. The test for libraries # Scan connected devices every second. The test for libraries
# available is necessary to recover wallets on machines without # available is necessary to recover wallets on machines without
# libraries # libraries
if self.libraries_available: return [self] if self.libraries_available else []
now = time.time()
if now > self.last_scan + 1: def run(self):
self.last_scan = now now = time.time()
self.scan_devices() if now > self.last_scan + 1:
self.last_scan = now
self.scan_devices()
for wallet in self.paired_wallets: for wallet in self.paired_wallets:
if now > wallet.last_operation + wallet.session_timeout: if now > wallet.last_operation + wallet.session_timeout:
client = self.lookup_client(wallet) client = self.lookup_client(wallet)