Ver código fonte

feat(flutter): Add notify test

huangrunheng 3 anos atrás
pai
commit
4ec8df7a76

+ 2 - 2
module/notify/notify.py

@@ -21,11 +21,11 @@ class Notifier:
 
         if not self.enable:
             return
+        config = {}
         try:
-            config = {}
             for item in yaml.safe_load_all(_config):
                 config.update(item)
-        except Exception:
+        except Exception as e:
             logger.error("Fail to load onepush config, skip sending")
             return
         self.config = config

+ 17 - 0
module/server/home_router.py

@@ -3,6 +3,8 @@
 # github https://github.com/runhey
 from fastapi import APIRouter
 
+from module.logger import logger
+
 
 home_app = APIRouter(
     prefix="/home",
@@ -17,4 +19,19 @@ async def home_test():
 async def home_menu():
     return {'Home': [], 'Updater': [], 'Tool': []}
 
+@home_app.post('/notify_test')
+async def notify_test(setting: str, title: str, content: str):
+    from module.notify.notify import Notifier
+    try:
+        notifier = Notifier(setting, True)
+        if notifier.push(title=title, content=content):
+            del notifier
+            return True
+        else:
+            del notifier
+            return False
+    except Exception as e:
+        logger.exception(e)
+        return str(e)
+
 

+ 2 - 0
module/server/script_process.py

@@ -71,6 +71,8 @@ class ScriptProcess(ScriptWSManager):
                     if not data:
                         await sleep(0.5)
                         continue
+                    if 'state' in data and data['state'] == ScriptState.WARNING:
+                        self.state = ScriptState.WARNING
                     await self.broadcast_state(data)
                 except QueueEmpty as e:
                     logger.warning(f'QueueEmpty: {e}')