Merge pull request #677 from dadav/fix/plugins_setup_ui
Fix/plugins setup ui
This commit is contained in:
commit
19973574e7
pwnagotchi/plugins
@ -3,6 +3,7 @@ import glob
|
|||||||
import _thread
|
import _thread
|
||||||
import importlib, importlib.util
|
import importlib, importlib.util
|
||||||
import logging
|
import logging
|
||||||
|
from pwnagotchi.ui import view
|
||||||
|
|
||||||
default_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "default")
|
default_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "default")
|
||||||
loaded = {}
|
loaded = {}
|
||||||
@ -27,13 +28,15 @@ def toggle_plugin(name, enable=True):
|
|||||||
global loaded, database
|
global loaded, database
|
||||||
if not enable and name in loaded:
|
if not enable and name in loaded:
|
||||||
if getattr(loaded[name], 'on_unload', None):
|
if getattr(loaded[name], 'on_unload', None):
|
||||||
loaded[name].on_unload()
|
loaded[name].on_unload(view.ROOT)
|
||||||
del loaded[name]
|
del loaded[name]
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if enable and name in database and name not in loaded:
|
if enable and name in database and name not in loaded:
|
||||||
load_from_file(database[name])
|
load_from_file(database[name])
|
||||||
one(name, 'loaded')
|
one(name, 'loaded')
|
||||||
|
one(name, 'ui_setup', view.ROOT)
|
||||||
|
one(name, 'ready', view.ROOT._agent)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
@ -466,13 +466,14 @@ class BTTether(plugins.Plugin):
|
|||||||
logging.info("BT-TETHER: Successfully loaded ...")
|
logging.info("BT-TETHER: Successfully loaded ...")
|
||||||
self.ready = True
|
self.ready = True
|
||||||
|
|
||||||
def on_unload(self):
|
def on_unload(self, ui):
|
||||||
self.ui.remove_element('bluetooth')
|
with ui._lock:
|
||||||
|
ui.remove_element('bluetooth')
|
||||||
|
|
||||||
def on_ui_setup(self, ui):
|
def on_ui_setup(self, ui):
|
||||||
self.ui = ui
|
with ui._lock:
|
||||||
ui.add_element('bluetooth', LabeledValue(color=BLACK, label='BT', value='-', position=(ui.width() / 2 - 15, 0),
|
ui.add_element('bluetooth', LabeledValue(color=BLACK, label='BT', value='-', position=(ui.width() / 2 - 15, 0),
|
||||||
label_font=fonts.Bold, text_font=fonts.Medium))
|
label_font=fonts.Bold, text_font=fonts.Medium))
|
||||||
|
|
||||||
def on_ui_update(self, ui):
|
def on_ui_update(self, ui):
|
||||||
if not self.ready:
|
if not self.ready:
|
||||||
|
@ -26,7 +26,7 @@ class Example(plugins.Plugin):
|
|||||||
logging.warning("WARNING: this plugin should be disabled! options = " % self.options)
|
logging.warning("WARNING: this plugin should be disabled! options = " % self.options)
|
||||||
|
|
||||||
# called before the plugin is unloaded
|
# called before the plugin is unloaded
|
||||||
def on_unload(self):
|
def on_unload(self, ui):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# called hen there's internet connectivity
|
# called hen there's internet connectivity
|
||||||
|
Loading…
x
Reference in New Issue
Block a user