// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md #include "AppWindow.hpp" #include "ApplicationCommon.hpp" #include "data/AlarmPopupRequestParams.hpp" #include "data/AudioErrorParams.hpp" #include "service-db/Settings.hpp" #include "service-db/agents/settings/SystemSettings.hpp" #include "popups/data/PopupData.hpp" namespace app { void ApplicationCommon::registerPopupBlueprints() { using namespace gui::popup; popupBlueprint.registerBlueprint( ID::PhoneModes, [&](gui::popup::ID /*id*/, std::unique_ptr ¶ms) { auto popupParams = dynamic_cast(params.get()); if (popupParams == nullptr) { return false; } const auto &mode = popupParams->getPhoneMode(); auto flightModeSetting = settings->getValue(settings::Cellular::offlineMode, settings::SettingsScope::Global); bool flightMode = flightModeSetting == "1"; const auto &popupName = resolveWindowName(gui::popup::ID::PhoneModes); if (const auto currentWindowName = getCurrentWindow()->getName(); currentWindowName == popupName) { updateCurrentWindow(std::make_unique(mode, flightMode)); } else { switchWindowPopup(popupName, popupParams->getDisposition(), std::make_unique(mode, flightMode), SwitchReason::Popup); } return true; }); popupBlueprint.registerBlueprint( ID::Volume, [&](gui::popup::ID /*id*/, std::unique_ptr ¶ms) { auto volumeParams = dynamic_cast(params.get()); if (volumeParams == nullptr) { return false; } LOG_INFO("Playback: %s, volume: %s", audio::str(volumeParams->getAudioContext().second).c_str(), std::to_string(volumeParams->getVolume()).c_str()); auto volume = volumeParams->getVolume(); auto context = volumeParams->getAudioContext(); auto source = volumeParams->getRequestSource(); auto popupData = std::make_unique(volume, context, source); const auto popupName = resolveWindowName(gui::popup::ID::Volume); if (const auto currentWindowName = getCurrentWindow()->getName(); currentWindowName == popupName) { updateCurrentWindow(std::move(popupData)); } else { switchWindowPopup( popupName, volumeParams->getDisposition(), std::move(popupData), SwitchReason::Popup); } return true; }); popupBlueprint.registerBlueprint( ID::BluetoothAuthenticate, [&](gui::popup::ID id, std::unique_ptr ¶ms) { switchWindowPopup(resolveWindowName(id), gui::popup::popupDisposition(id, gui::popup::Disposition::Priority::High), std::move(params), SwitchReason::Popup); return true; }); popupBlueprint.registerBlueprint( ID::BluetoothInfo, [&](gui::popup::ID id, std::unique_ptr ¶ms) { switchWindowPopup(resolveWindowName(id), gui::popup::popupDisposition(id, gui::popup::Disposition::Priority::High), std::move(params), SwitchReason::Popup); return true; }); popupBlueprint.registerBlueprint( ID::PhoneLock, [&](gui::popup::ID id, std::unique_ptr & /*params*/) { switchWindowPopup(resolveWindowName(id), gui::popup::popupDisposition(id, gui::popup::Disposition::Priority::Normal), nullptr, SwitchReason::PhoneLock); return true; }); auto phoneLockBlueprint = [&](gui::popup::ID id, std::unique_ptr ¶ms) { auto popupParams = dynamic_cast(params.get()); if (popupParams == nullptr) { LOG_ERROR("This is most probably due to wrong unique_ptr handling - please check"); return false; } switchWindowPopup( gui::popup::resolveWindowName(id), popupParams->getDisposition(), std::make_unique(popupParams->getLock(), popupParams->getPhoneLockInputTypeAction())); return true; }; popupBlueprint.registerBlueprint(ID::PhoneLockInput, phoneLockBlueprint); popupBlueprint.registerBlueprint(ID::PhoneLockChangeInfo, phoneLockBlueprint); auto simLockBlueprint = [&](gui::popup::ID id, std::unique_ptr ¶ms) { auto popupParams = dynamic_cast(params.get()); if (popupParams == nullptr) { return false; } switchWindowPopup(gui::popup::resolveWindowName(id), popupParams->getDisposition(), std::make_unique(popupParams->getLock(), popupParams->getSimInputTypeAction(), popupParams->getErrorCode())); return true; }; popupBlueprint.registerBlueprint(ID::SimLock, simLockBlueprint); popupBlueprint.registerBlueprint(ID::SimInfo, simLockBlueprint); popupBlueprint.registerBlueprint( ID::Alarm, [&](gui::popup::ID id, std::unique_ptr ¶ms) { auto popupParams = dynamic_cast(params.get()); if (popupParams == nullptr) { return false; } popupParams->setDisposition(gui::popup::Disposition{gui::popup::Disposition::Priority::High, gui::popup::Disposition::WindowType::Popup, params->getPopupId()}); switchWindowPopup(gui::popup::resolveWindowName(id), popupParams->getDisposition(), std::make_unique(popupParams)); return true; }); auto audioErrorBlueprint = [&](gui::popup::ID id, std::unique_ptr ¶ms) { auto popupParams = dynamic_cast(params.get()); if (popupParams == nullptr) { return false; } switchWindowPopup(gui::popup::resolveWindowName(id), popupParams->getDisposition(), std::make_unique(popupParams), SwitchReason::Popup); return true; }; popupBlueprint.registerBlueprint(ID::AudioError, audioErrorBlueprint); } std::optional ApplicationCommon::popupBlueprintFallback(gui::popup::ID id) { popupBlueprint.registerBlueprint( id, [&](gui::popup::ID id, std::unique_ptr &p) -> bool { switchWindowPopup( gui::popup::resolveWindowName(id), p->getDisposition(), nullptr, SwitchReason::PhoneLock); return true; }); return *popupBlueprint.getBlueprint(id); } } // namespace app