Genericize plugin handling of thread jobs
Move it to the Plugins class so all plugins get it for free.
This commit is contained in:
@@ -26,6 +26,13 @@ from util import *
|
||||
from i18n import _
|
||||
from util import print_error, profiler
|
||||
|
||||
hook_names = set()
|
||||
hooks = {}
|
||||
|
||||
def hook(func):
|
||||
hook_names.add(func.func_name)
|
||||
return func
|
||||
|
||||
class Plugins:
|
||||
|
||||
@profiler
|
||||
@@ -40,6 +47,7 @@ class Plugins:
|
||||
|
||||
self.plugins = {}
|
||||
self.windows = []
|
||||
self.network = None
|
||||
self.descriptions = plugins.descriptions
|
||||
for item in self.descriptions:
|
||||
name = item['name']
|
||||
@@ -118,6 +126,17 @@ class Plugins:
|
||||
x += (lambda: self.wallet_plugin_loader(config, name),)
|
||||
wallet.wallet_types.append(x)
|
||||
|
||||
@hook
|
||||
def set_network(self, network):
|
||||
if network != self.network:
|
||||
jobs = [job in plugin.thread_jobs()
|
||||
for plugin in self.plugins.values()]
|
||||
if self.network:
|
||||
self.network.remove_jobs(jobs)
|
||||
self.network = network
|
||||
if network:
|
||||
network.add_jobs(jobs)
|
||||
|
||||
def trigger(self, event, *args, **kwargs):
|
||||
for plugin in self.plugins.values():
|
||||
getattr(plugin, event)(*args, **kwargs)
|
||||
@@ -130,13 +149,6 @@ class Plugins:
|
||||
self.windows.remove(window)
|
||||
self.trigger('on_close_window', window)
|
||||
|
||||
hook_names = set()
|
||||
hooks = {}
|
||||
|
||||
def hook(func):
|
||||
hook_names.add(func.func_name)
|
||||
return func
|
||||
|
||||
def run_hook(name, *args):
|
||||
return _run_hook(name, False, *args)
|
||||
|
||||
@@ -194,6 +206,9 @@ class BasePlugin:
|
||||
def requires_settings(self):
|
||||
return False
|
||||
|
||||
def thread_jobs(self):
|
||||
return []
|
||||
|
||||
@hook
|
||||
def load_wallet(self, wallet, window): pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user