From 47579ff019b8697db9fd09ebfd3cfc2af2501610 Mon Sep 17 00:00:00 2001 From: Tsubasa6848 <116721335+Tsubasa6848@users.noreply.github.com> Date: Fri, 5 Jan 2024 11:01:51 +0800 Subject: [PATCH] feat: add auto clean task --- src/Cleaner.cpp | 7 +++++-- src/Global.h | 2 ++ src/Plugin.cpp | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Cleaner.cpp b/src/Cleaner.cpp index a5bce81..1338418 100644 --- a/src/Cleaner.cpp +++ b/src/Cleaner.cpp @@ -104,8 +104,11 @@ void CleanTask() { }); } -void CountEntitiesTask() { - // +void AutoCleanTask() { + auto_clean_task->cancel(); + auto_clean_task = scheduler.add(1min, [] { + CleanTask(); + }); } } // namespace Cleaner \ No newline at end of file diff --git a/src/Global.h b/src/Global.h index 9f7284d..a40666a 100644 --- a/src/Global.h +++ b/src/Global.h @@ -5,7 +5,9 @@ extern ll::Logger logger; extern void RegisterCommands(); extern void UnregisterCommands(); +static std::shared_ptr> auto_clean_task; namespace Cleaner { extern void CleanTask(); + extern void AutoCleanTask(); } \ No newline at end of file diff --git a/src/Plugin.cpp b/src/Plugin.cpp index 4039c9e..0f7dd09 100644 --- a/src/Plugin.cpp +++ b/src/Plugin.cpp @@ -10,6 +10,7 @@ Plugin::Plugin(ll::plugin::NativePlugin& self) : mSelf(self) { bool Plugin::enable() { RegisterCommands(); + Cleaner::AutoCleanTask(); logger.info("Cleaner Loaded!"); logger.info("Author: Tsubasa6848"); logger.info("Repository: https://github.com/GroupMountain/Cleaner"); @@ -19,6 +20,7 @@ bool Plugin::enable() { bool Plugin::disable() { logger.info("Disabling Cleaner..."); // Code for disabling the plugin goes here. + auto_clean_task->cancel(); UnregisterCommands(); logger.info("Cleaner Disabled!"); return true;