M module-apps/apps-common/ApplicationCommon.cpp => module-apps/apps-common/ApplicationCommon.cpp +16 -3
@@ 836,6 836,11 @@ namespace app
LOG_ERROR("no blueprint to handle %s popup - fallback", std::string(magic_enum::enum_name(id)).c_str());
blueprint = popupBlueprintFallback(id);
}
+ if (data->getDisposition().windowtype != gui::popup::Disposition::WindowType::Popup) {
+ LOG_ERROR("setting popup window type to popup - fallback");
+ data->setDisposition(gui::popup::Disposition{
+ gui::popup::Disposition::Priority::Normal, gui::popup::Disposition::WindowType::Popup, id});
+ }
auto request = gui::popup::Request(id, std::move(data), *blueprint);
windowsPopupQueue->pushRequest(std::move(request));
tryShowPopup();
@@ 857,8 862,8 @@ namespace app
if (not retval) {
LOG_ERROR("Popup %s handling failure, please check registered blueprint!", popup.c_str());
}
- return retval;
LOG_ERROR("no blueprint for popup: %s", popup.c_str());
+ return retval;
}
return false;
}
@@ 867,8 872,12 @@ namespace app
{
const auto popupName = gui::popup::resolveWindowName(id);
LOG_INFO("abort popup: %s from window %s", popupName.c_str(), getCurrentWindow()->getName().c_str());
- windowsStack().pop(popupName);
- returnToPreviousWindow();
+ if (not windowsStack().pop(popupName)) {
+ return;
+ }
+ if (popupName == getCurrentWindow()->getName()) {
+ returnToPreviousWindow();
+ }
}
bool ApplicationCommon::userInterfaceDBNotification([[maybe_unused]] sys::Message *msg,
@@ 988,4 997,8 @@ namespace app
{
return simLockSubject;
}
+ void ApplicationCommon::registerOnPopCallback(std::function<void(WindowsStack &)> callback)
+ {
+ windowsStack().registerOnPopCallback(std::move(callback));
+ }
} /* namespace app */
M module-apps/apps-common/ApplicationCommon.hpp => module-apps/apps-common/ApplicationCommon.hpp +2 -0
@@ 273,6 273,8 @@ namespace app
/// Find and pop window from stack by window name
void popWindow(const std::string &window);
+ void registerOnPopCallback(std::function<void(WindowsStack &)> callback);
+
/// Pops the current window from the windows stack
void popCurrentWindow();
M module-apps/apps-common/WindowsStack.cpp => module-apps/apps-common/WindowsStack.cpp +23 -0
@@ 2,6 2,8 @@
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "WindowsStack.hpp"
+
+#include <utility>
#include "WindowsFactory.hpp"
#include "windows/AppWindow.hpp"
@@ 67,6 69,9 @@ namespace app
auto ret = findInStack(window);
if (ret != stack.end()) {
stack.erase(std::next(ret), stack.end());
+ if (onPopCallback) {
+ onPopCallback(*this);
+ }
return true;
}
return false;
@@ 112,5 117,23 @@ namespace app
{
return std::find_if(stack.begin(), stack.end(), [&](auto &el) { return el.name == window; });
}
+ void WindowsStack::registerOnPopCallback(std::function<void(WindowsStack &)> callback)
+ {
+ onPopCallback = std::move(callback);
+ }
+ void WindowsStack::dropPendingPopups()
+ {
+ auto it = stack.rbegin();
+ while (it != stack.rend()) {
+ LOG_DEBUG("Current window on stack: %s, type: %s",
+ it->name.c_str(),
+ magic_enum::enum_name(it->disposition.windowtype).data());
+ if (it->disposition.windowtype == gui::popup::Disposition::WindowType::Popup) {
+ LOG_DEBUG("Erasing: %s", it->name.c_str());
+ stack.erase(std::next(it).base());
+ }
+ std::advance(it, 1);
+ }
+ }
} // namespace app
M module-apps/apps-common/WindowsStack.hpp => module-apps/apps-common/WindowsStack.hpp +5 -1
@@ 40,8 40,9 @@ namespace app
class WindowsStack
{
- std::vector<WindowData> stack;
+ std::function<void(WindowsStack &)> onPopCallback = nullptr;
std::map<std::string, std::unique_ptr<gui::AppWindow>> windows{};
+ std::vector<WindowData> stack;
decltype(stack)::iterator findInStack(const std::string &);
public:
@@ 70,8 71,11 @@ namespace app
bool pop(const std::string &window);
bool popLastWindow();
bool drop(const std::string &window);
+ void dropPendingPopups();
void clear();
bool rebuildWindows(app::WindowsFactory &windowsFactory, ApplicationCommon *app);
+ void registerOnPopCallback(std::function<void(WindowsStack &)> callback);
};
+
} // namespace app
M products/BellHybrid/apps/application-bell-main/ApplicationBellMain.cpp => products/BellHybrid/apps/application-bell-main/ApplicationBellMain.cpp +18 -17
@@ 24,6 24,7 @@
#include <common/popups/BedtimeNotificationWindow.hpp>
#include <apps-common/WindowsPopupFilter.hpp>
#include <common/windows/BellTurnOffWindow.hpp>
+#include <WindowsStack.hpp>
namespace app
{
@@ 34,23 35,23 @@ namespace app
std::uint32_t stackDepth)
: Application(name, parent, statusIndicators, startInBackground, stackDepth)
{
-
- getPopupFilter().addAppDependentFilter([&](const gui::PopupRequestParams &popupParams) {
- auto val = ((isCurrentWindow(gui::popup::resolveWindowName(gui::popup::ID::Reboot))) ||
- (isCurrentWindow(gui::popup::resolveWindowName(gui::popup::ID::PowerOff))) ||
- (isCurrentWindow(gui::BellTurnOffWindow::name)));
- if (val) {
- LOG_INFO("popup blocked");
- return !val;
- }
- if (not(((popupParams.getPopupId() == gui::popup::ID::AlarmActivated ||
- popupParams.getPopupId() == gui::popup::ID::AlarmDeactivated)) and
- (not isHomeScreenFocused()))) {
- LOG_INFO("popup blocked");
- return false;
- }
- return true;
- });
+ registerOnPopCallback([](WindowsStack &windowsStack) { windowsStack.dropPendingPopups(); });
+ // getPopupFilter().addAppDependentFilter([&](const gui::PopupRequestParams &popupParams) {
+ // auto val = ((isCurrentWindow(gui::popup::resolveWindowName(gui::popup::ID::Reboot))) ||
+ // (isCurrentWindow(gui::popup::resolveWindowName(gui::popup::ID::PowerOff))) ||
+ // (isCurrentWindow(gui::BellTurnOffWindow::name)));
+ // if (val) {
+ // LOG_INFO("popup blocked");
+ // return !val;
+ // }
+ // if (not(((popupParams.getPopupId() == gui::popup::ID::AlarmActivated ||
+ // popupParams.getPopupId() == gui::popup::ID::AlarmDeactivated)) and
+ // (not isHomeScreenFocused()))) {
+ // LOG_INFO("popup blocked");
+ // return false;
+ // }
+ // return true;
+ // });
bus.channels.push_back(sys::BusChannel::ServiceDBNotifications);
addActionReceiver(manager::actions::ShowAlarm, [this](auto &&data) {