From bd61196c3cd5bdb4fe968a850e0183fc20c4fc36 Mon Sep 17 00:00:00 2001
From: Simone Margaritelli <evilsocket@gmail.com>
Date: Fri, 8 Nov 2019 15:47:12 +0100
Subject: [PATCH] new: the auto-update plugin now triggers an on_updating event
 that other plugins can intercept (see led plugin)

---
 pwnagotchi/defaults.yml                   | 1 +
 pwnagotchi/plugins/default/auto-update.py | 1 +
 pwnagotchi/plugins/default/example.py     | 2 +-
 pwnagotchi/plugins/default/led.py         | 6 +++++-
 4 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/pwnagotchi/defaults.yml b/pwnagotchi/defaults.yml
index ac6fb0b..2e42fc6 100644
--- a/pwnagotchi/defaults.yml
+++ b/pwnagotchi/defaults.yml
@@ -87,6 +87,7 @@ main:
             # o=on space=off, comment the ones you don't want
             patterns:
                 loaded: 'oo  oo  oo oo  oo  oo  oo'
+                updating: 'oo  oo  oo oo  oo  oo  oo'
                 # internet_available: 'oo  oo  oo oo  oo  oo  oo'
                 ready: 'oo  oo  oo oo  oo  oo  oo'
                 ai_ready: 'oo  oo  oo oo  oo  oo  oo'
diff --git a/pwnagotchi/plugins/default/auto-update.py b/pwnagotchi/plugins/default/auto-update.py
index 0a4b0ff..3bd181a 100644
--- a/pwnagotchi/plugins/default/auto-update.py
+++ b/pwnagotchi/plugins/default/auto-update.py
@@ -198,6 +198,7 @@ class AutoUpdate(plugins.Plugin):
             if num_updates > 0:
                 if self.options['install']:
                     for update in to_install:
+                        plugins.on('updating')
                         if install(display, update):
                             num_installed += 1
                 else:
diff --git a/pwnagotchi/plugins/default/example.py b/pwnagotchi/plugins/default/example.py
index e66df3d..035a30d 100644
--- a/pwnagotchi/plugins/default/example.py
+++ b/pwnagotchi/plugins/default/example.py
@@ -25,7 +25,7 @@ class Example(plugins.Plugin):
     def on_loaded(self):
         logging.warning("WARNING: this plugin should be disabled! options = " % self.options)
 
-    # called in manual mode when there's internet connectivity
+    # called hen there's internet connectivity
     def on_internet_available(self, agent):
         pass
 
diff --git a/pwnagotchi/plugins/default/led.py b/pwnagotchi/plugins/default/led.py
index c3a32e6..02d8e30 100644
--- a/pwnagotchi/plugins/default/led.py
+++ b/pwnagotchi/plugins/default/led.py
@@ -69,7 +69,11 @@ class Led(plugins.Plugin):
             finally:
                 self._is_busy = False
 
-    # called in manual mode when there's internet connectivity
+    # called when the unit is updating its software
+    def on_updating(self):
+        self._on_event('updating')
+
+    # called when there's internet connectivity
     def on_internet_available(self, agent):
         self._on_event('internet_available')