Skip to content

Commit

Permalink
refactor(Command): Create _onCustom method
Browse files Browse the repository at this point in the history
  • Loading branch information
becem-gharbi committed Nov 20, 2023
1 parent 997bb02 commit a3161be
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
1 change: 1 addition & 0 deletions include/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace ESPAdmin
static void _onConfig(const String &message);
static void _onRestart();
static void _onLog(const String &message);
static void _onCustom(const String &message);
};
}

Expand Down
28 changes: 15 additions & 13 deletions src/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,7 @@ namespace ESPAdmin

else if (type == "custom")
{
if (onCustom == nullptr)
{
_logger.warn("no handler registered for custom commands");
}
else
{
onCustom(message);
}
_onCustom(message);
}
}

Expand All @@ -65,12 +58,9 @@ namespace ESPAdmin
{
Store::set(STORE_CONFIG, message.c_str());

if (onConfig == nullptr)
{
_logger.warn("no handler registered for config command");
}
else
if (onConfig != nullptr)
{

onConfig(Store::get(STORE_CONFIG));
}
}
Expand All @@ -89,4 +79,16 @@ namespace ESPAdmin
{
Store::logRemoteEnabled = message == "on" ? true : false;
}

void Command::_onCustom(const String &message)
{
if (onCustom == nullptr)
{
_logger.warn("no handler registered for custom commands");
}
else
{
onCustom(message);
}
}
}

0 comments on commit a3161be

Please sign in to comment.