From 203f81977f0b69865f54949ff4bcd9487caddddb Mon Sep 17 00:00:00 2001 From: lblach Date: Thu, 18 Feb 2021 08:14:49 +0100 Subject: [PATCH] [EGD-5756] Add Update Window Create Update Window(s) to control and visualize the MuditaOS update process on Pure. --- image/assets/images/circle_update.vpi | Bin 0 -> 7289 bytes image/assets/lang/Deutsch.json | 5 + image/assets/lang/English.json | 5 + image/assets/lang/Espanol.json | 5 + image/assets/lang/Francais.json | 5 + image/assets/lang/Polski.json | 5 + module-apps/CMakeLists.txt | 2 +- .../ApplicationDesktop.cpp | 10 +- .../application-desktop/CMakeLists.txt | 2 + .../data/LockPhoneData.hpp | 1 + .../application-desktop/windows/Names.hpp | 21 +- .../windows/UpdateProgress.cpp | 181 ++++++++++++++++++ .../windows/UpdateProgress.hpp | 47 +++++ module-gui/gui/widgets/Style.hpp | 2 +- .../service-desktop/ServiceDesktop.cpp | 1 + .../endpoints/update/UpdateMuditaOS.cpp | 71 ++++++- .../endpoints/update/UpdateMuditaOS.hpp | 1 + module-sys/SystemManager/SystemManager.cpp | 10 + 18 files changed, 355 insertions(+), 19 deletions(-) create mode 100644 image/assets/images/circle_update.vpi create mode 100644 module-apps/application-desktop/windows/UpdateProgress.cpp create mode 100644 module-apps/application-desktop/windows/UpdateProgress.hpp diff --git a/image/assets/images/circle_update.vpi b/image/assets/images/circle_update.vpi new file mode 100644 index 0000000000000000000000000000000000000000..d7feae64e907b74437c45e5390599fb5bb1d6684 GIT binary patch literal 7289 zcmbW6ZEsXn6ov21^u3+l7HD}#3Wzm`3MQa@Abv0rgk zbhO2!ojd28z1CiPpVxclWB0M!TkpE=ao=^5-L9L>yKZY|c&hxk-=y_HX`RqIrS))o zc&aR`2mL-)_ZzE~Vl@>Ct1a5~bQzXt50?8q2Hiceh*v5aKbIO0YL}ht?-_j@76l!x zQh77l61&@JJMN+C?iSyf*Nhp#_q#nG-JN1RO)BK)tHzJp0o*a_C|XgNkq---6xDjz zj;zeu;ixTqf7BwVyJ;Ucl8;HKgX_t^)ZcI~Usr2*hwEwK51-eqjH=RYA*7g~7Qm>aN(j_Ae>|@vLRQ-zDq4Sa`zYuTA-)IS<2I%EJrQ!BZ8W>d@8) zORQfmu|BYZ3u;MPe{aecY<0e={i7+Lx7E3(_Rpq#&Q|+P?W?A|Z>v4k5>w>xuWUvA zo~<-tveoOxs<+i{WA&!7+I8OMs#Qi)mTj4{%=fuDZ5?@|_HBb6tacht?^I4v?U-x3 zseRv|wtKB_wkq2GP8Qqd(8^T%5f8RVp0;eYDXSFYhm4|rb77TYvsFTE_6O+M5H>vU ztShWEZt>5uJKZSXQ%)yEgV)-G-{{Z5y51-;U6!@VlCd+`)jnU zsV2p13nJogU{rMSNT#Pn(~Rd#nGbAa0WUZoaA0E9Hy$5r{rT`%V)#M~LW4x|pi>^P zuJe|%SqajNMgN+6W;Ha35tJ>Us%)UV`jI74Y!9ujRqwK9D!M)wtNes6lIZnWQA?lt z8E@8K^sM$Yb}K^4s_5}v#&_%CLv252&6HQXw-{NtWOZ9sfyC!8nHjs4p2Q9QifZ|? zA7Xwk>%z9;k*8kEJ$*}MER7%*k3{^&ju;Wl+-pV`J|m@D`Q$0&RIw>DFxoHmFJ(NP(U;=@IB&~*64Javu~o{&m+dG2K9B0s0W0WH|0(FQ=|YG zc%B)GQe0E_Lab8Z&)OIU)`pcmP=?4kiqUvkp5#TjlShyEI)6(>%@%qQ`L$5w$!wH; z`boK+cug`(;{Hsi(1b6ufOZyyrrmmJ^T|khq(B^tC<~)CVQw@m--tal7PeYOs5MqL zot~|))L0w->>sq)^xfkT&Gtg-%@Q#!a+O)gi>>+iwy=1PfOb9Xaqe?;Lu3&vt=596 zt?7M7M!n03GF#*gZ)T%?=tJ#Fc{Yp9QQ^T%5e*DxLc5vy7%|PAqsqI;psk5U(RtUD zM`n=5lst|4Za&h324^sGga+@!VgTxu7J7TY^EG*>nc+(vt7cIPv%=Qo>3dm6UMO3K zdj_hC9A%fDG%D#?plBSSB8x_(EdDp*2dRo2YYwB@aakE3Cwv%zbH|0#<@}KWsWO5f zjo@Q}IF)~7y)5F9ew>ZM%{c<;`GbCy9Ubls)^q1IB*fQSfGtkcrr=pt9Kwt%q`pQ}!+ znvpB@vb;nYIn2gBDJ+x$h>n#zmC?KSc8=rVHay~aFdUS5EAP#19WDL zs3N~(mf8n}h5VQWf3bR6Bj{0aXy+4vsO`b1IG%zW}TQ;PIAX+)n9d>E11XFYC5C-0X+pxg*@qKJ(u z`j(&YUkJsRFpBt(R0bLSkWf*J3ZLwO1nQPhp$@wNmEUIk<{%~b$O?@t3RjoDP5Et* zapoT4S>J)^Dmuvf^6l&&9jiWvuc@|VSuCMe>xS=_6cN4RKBrFaE}rRN*8C=KhKP%& z-?fOqetG(|jC#K($`e#(!5ffrIqL}}WTfE)I z)0^xAeY?I7>l>@rjn#0=xYt-Mzp>oUSTgdeDG#@w^+u-j+wz;#v)#&`e#48C@f&&> zJzi^-VU?wXj2wL8jkM1VLuV-&~eb!`0{e8&_KJ8Zi>^J_>8z-x{m48}#cJV6$ ziCFCAk)4vYC$ethQ2B;+#|{@<%ITxRuRMp(;a8BlPeqG-fOyy%>MNS^ mJ+G}^OAEg&;#at{|4OG`_Q^c4ocu*l>)T^x8mp7PD*gjeos}p6 literal 0 HcmV?d00001 diff --git a/image/assets/lang/Deutsch.json b/image/assets/lang/Deutsch.json index e8cda6a1b00e3df64e03a7c5465ee0bc312479c5..c20494f3cb2e94b84dd4b762bf361209f1c73b7d 100644 --- a/image/assets/lang/Deutsch.json +++ b/image/assets/lang/Deutsch.json @@ -15,6 +15,7 @@ "common_mute": "MUTE", "common_switch": "SWITCH", "common_options": "OPTIONS", + "common_abort": "ABORT", "common_monday": "Monday", "common_tuesday": "Tuesday", "common_wednesday": "Wednesday", @@ -159,6 +160,10 @@ "app_phonebook_check": "CHECK", "app_phonebook_uncheck": "UNCHECK", "app_meditation_title_main": "Meditation", + "app_desktop_update_preparing": "Preparing MuditaOS update ver.", + "app_desktop_update_muditaos": "MuditaOS update", + "app_desktop_update_in_progress": "Update in progress...", + "app_desktop_update_ready_for_reset": "Ready for reset...", "sms_call_text": "Call: ", "sms_contact_details": "Contact details", "sms_delete_conversation": "Delete conversation", diff --git a/image/assets/lang/English.json b/image/assets/lang/English.json index 9ff45cb1da1873bac3220262cecf3c7afeb1a5b6..1f7b45a1bebad14e0468b336b4fdb8ee7d474804 100644 --- a/image/assets/lang/English.json +++ b/image/assets/lang/English.json @@ -24,6 +24,7 @@ "common_resume": "RESUME", "common_pause": "PAUSE", "common_retry": "TRY AGAIN", + "common_abort": "ABORT", "common_mo": "MO", "common_tu": "TU", "common_we": "WE", @@ -511,5 +512,9 @@ "app_desktop_update_size": "size", "app_desktop_update_bytes": "bytes", "app_desktop_update_unpacking": "Unpacking", + "app_desktop_update_preparing": "Preparing MuditaOS update ver.", + "app_desktop_update_muditaos": "MuditaOS update", + "app_desktop_update_in_progress": "Update in progress...", + "app_desktop_update_ready_for_reset": "Ready for reset...", "app_call_private_number": "Private number" } diff --git a/image/assets/lang/Espanol.json b/image/assets/lang/Espanol.json index 3bc51a2d6ad79a069b7098145e84e5f2084a92a2..f19faebb54097ff7b4d695db1d5af147936fe36e 100644 --- a/image/assets/lang/Espanol.json +++ b/image/assets/lang/Espanol.json @@ -15,6 +15,7 @@ "common_mute": "MUTE", "common_switch": "CAMBIAR", "common_options": "OPCIONES", + "common_abort": "ABORT", "common_monday": "Lunes", "common_tuesday": "Martes", "common_wednesday": "Miércoles", @@ -164,6 +165,10 @@ "app_phonebook_check": "CHECK", "app_phonebook_uncheck": "UNCHECK", "app_meditation_title_main": "Meditation", + "app_desktop_update_preparing": "Preparing MuditaOS update ver.", + "app_desktop_update_muditaos": "MuditaOS update", + "app_desktop_update_in_progress": "Update in progress...", + "app_desktop_update_ready_for_reset": "Ready for reset...", "sms_call_text": "Llamado: ", "sms_contact_details": "Detales de contacto: ", "sms_delete_conversation": "Eliminar conversación", diff --git a/image/assets/lang/Francais.json b/image/assets/lang/Francais.json index e8cda6a1b00e3df64e03a7c5465ee0bc312479c5..c20494f3cb2e94b84dd4b762bf361209f1c73b7d 100644 --- a/image/assets/lang/Francais.json +++ b/image/assets/lang/Francais.json @@ -15,6 +15,7 @@ "common_mute": "MUTE", "common_switch": "SWITCH", "common_options": "OPTIONS", + "common_abort": "ABORT", "common_monday": "Monday", "common_tuesday": "Tuesday", "common_wednesday": "Wednesday", @@ -159,6 +160,10 @@ "app_phonebook_check": "CHECK", "app_phonebook_uncheck": "UNCHECK", "app_meditation_title_main": "Meditation", + "app_desktop_update_preparing": "Preparing MuditaOS update ver.", + "app_desktop_update_muditaos": "MuditaOS update", + "app_desktop_update_in_progress": "Update in progress...", + "app_desktop_update_ready_for_reset": "Ready for reset...", "sms_call_text": "Call: ", "sms_contact_details": "Contact details", "sms_delete_conversation": "Delete conversation", diff --git a/image/assets/lang/Polski.json b/image/assets/lang/Polski.json index 4936072c9bdb911055d5004b02c5c0cbf817bfdf..0838d042d1a4b0c628be554d1aadbb3134d2bbc8 100644 --- a/image/assets/lang/Polski.json +++ b/image/assets/lang/Polski.json @@ -15,6 +15,7 @@ "common_mute": "WYCISZ", "common_switch": "ZMIEŃ", "common_options": "OPCJE", + "common_abort": "PRZERWIJ", "common_monday": "poniedziałek", "common_tuesday": "wtorek", "common_wednesday": "środa", @@ -161,6 +162,10 @@ "app_phonebook_check": "ZAZNACZ", "app_phonebook_uncheck": "ODZNACZ", "app_meditation_title_main": "Medytacja", + "app_desktop_update_preparing": "Przygotowanie aktualizacji MuditaOS wer.", + "app_desktop_update_muditaos": "Aktualizacja MuditaOS", + "app_desktop_update_in_progress": "Aktualizacja w toku...", + "app_desktop_update_ready_for_reset": "Gotowy do restartu...", "sms_call_text": "Call: ", "sms_contact_details": "Contact details", "sms_delete_conversation": "Delete conversation", diff --git a/module-apps/CMakeLists.txt b/module-apps/CMakeLists.txt index c453d93add930f26d3a5cf6a036cbaf72d9e5699..d9a0b2fdc2ea43d22a41d21bc4b22f92e42d0ef2 100644 --- a/module-apps/CMakeLists.txt +++ b/module-apps/CMakeLists.txt @@ -46,7 +46,7 @@ set( SOURCES "options/type/OptionSetting.cpp" "options/type/OptionChangePin.cpp" "options/type/OptionWithActiveIcons.cpp" - ) + "application-desktop/windows/UpdateProgress.cpp") add_library(${PROJECT_NAME} STATIC ${SOURCES} ${BOARD_SOURCES}) diff --git a/module-apps/application-desktop/ApplicationDesktop.cpp b/module-apps/application-desktop/ApplicationDesktop.cpp index 42ec56e98ff299627d1326e19d437068b8cd6b7e..3fd9eb23f814990858689f0013f18fa95f84f549 100644 --- a/module-apps/application-desktop/ApplicationDesktop.cpp +++ b/module-apps/application-desktop/ApplicationDesktop.cpp @@ -12,6 +12,7 @@ #include "windows/LockedInfoWindow.hpp" #include "windows/Reboot.hpp" #include "windows/Update.hpp" +#include "windows/UpdateProgress.hpp" #include "windows/MmiPullWindow.hpp" #include "windows/MmiPushWindow.hpp" #include "windows/MmiInternalMsgWindow.hpp" @@ -315,11 +316,15 @@ namespace app if (getWindow(app::window::name::desktop_update)) { std::unique_ptr data = std::make_unique(updateMsg); - switchWindow(app::window::name::desktop_update, gui::ShowMode::GUI_SHOW_INIT, std::move(data)); } } + if (updateMsg != nullptr && updateMsg->messageType == updateos::UpdateMessageType::UpdateNow) { + auto data = std::make_unique(updateMsg); + switchWindow(app::window::name::desktop_update_progress, gui::ShowMode::GUI_SHOW_INIT, std::move(data)); + } + if (updateMsg != nullptr && updateMsg->messageType == updateos::UpdateMessageType::UpdateInform) { if (getWindow(app::window::name::desktop_update)) { std::unique_ptr data = std::make_unique(updateMsg); @@ -380,6 +385,9 @@ namespace app windowsFactory.attach(desktop_update, [](Application *app, const std::string newname) { return std::make_unique(app); }); + windowsFactory.attach(desktop_update_progress, [](Application *app, const std::string newname) { + return std::make_unique(app); + }); windowsFactory.attach(desktop_mmi_pull, [](Application *app, const std::string newname) { return std::make_unique(app, desktop_mmi_pull); }); diff --git a/module-apps/application-desktop/CMakeLists.txt b/module-apps/application-desktop/CMakeLists.txt index 883041172a2cacc3907ab239089ee1029fc9e7e1..0389e21b98465d6a788afeea1a9f50b0286b232b 100644 --- a/module-apps/application-desktop/CMakeLists.txt +++ b/module-apps/application-desktop/CMakeLists.txt @@ -31,6 +31,7 @@ target_sources( ${PROJECT_NAME} "${CMAKE_CURRENT_LIST_DIR}/windows/LockedInfoWindow.cpp" "${CMAKE_CURRENT_LIST_DIR}/windows/Reboot.cpp" "${CMAKE_CURRENT_LIST_DIR}/windows/Update.cpp" + "${CMAKE_CURRENT_LIST_DIR}/windows/UpdateProgress.cpp" "${CMAKE_CURRENT_LIST_DIR}/windows/MmiPullWindow.cpp" "${CMAKE_CURRENT_LIST_DIR}/windows/MmiPushWindow.cpp" "${CMAKE_CURRENT_LIST_DIR}/windows/MmiInternalMsgWindow.cpp" @@ -58,6 +59,7 @@ target_sources( ${PROJECT_NAME} "${CMAKE_CURRENT_LIST_DIR}/windows/LockedInfoWindow.hpp" "${CMAKE_CURRENT_LIST_DIR}/windows/Reboot.hpp" "${CMAKE_CURRENT_LIST_DIR}/windows/Update.hpp" + "${CMAKE_CURRENT_LIST_DIR}/windows/UpdateProgress.hpp" "${CMAKE_CURRENT_LIST_DIR}/windows/Names.hpp" "${CMAKE_CURRENT_LIST_DIR}/windows/MmiPullWindow.hpp" "${CMAKE_CURRENT_LIST_DIR}/windows/MmiPushWindow.hpp" diff --git a/module-apps/application-desktop/data/LockPhoneData.hpp b/module-apps/application-desktop/data/LockPhoneData.hpp index 3e76a672a6dc1f60e5474c75642c980854349cbd..fbfd5ca07f6f67b946c154c17ae1fa2a0f255d5b 100644 --- a/module-apps/application-desktop/data/LockPhoneData.hpp +++ b/module-apps/application-desktop/data/LockPhoneData.hpp @@ -48,6 +48,7 @@ namespace gui public: UpdateSwitchData(sdesktop::UpdateOsMessage *messageToCopyFrom) : updateOsMessage(*messageToCopyFrom) {} + const sdesktop::UpdateOsMessage &getUpdateOsMessage() { return updateOsMessage; diff --git a/module-apps/application-desktop/windows/Names.hpp b/module-apps/application-desktop/windows/Names.hpp index bb9887f4afd688dde32fa4059f0b853bf750edad..793c7f2a22c03c7460a0e38624a5c4c5d4d97c60 100644 --- a/module-apps/application-desktop/windows/Names.hpp +++ b/module-apps/application-desktop/windows/Names.hpp @@ -7,14 +7,15 @@ namespace app::window::name { inline constexpr auto desktop_main_window = gui::name::window::main_window; - inline constexpr auto desktop_menu = "MenuWindow"; - inline constexpr auto desktop_reboot = "Reboot"; - inline constexpr auto desktop_poweroff = "PowerOffWindow"; - inline constexpr auto dead_battery = "DeadBatteryWindow"; - inline constexpr auto desktop_pin_lock = "PinLockWindow"; - inline constexpr auto desktop_locked = "LockedInfoWindow"; - inline constexpr auto desktop_update = "Update"; - inline constexpr auto desktop_mmi_pull = "MmiPullWindow"; - inline constexpr auto desktop_mmi_push = "MmiPushWindow"; - inline constexpr auto desktop_mmi_internal = "MmiInternalMsgWindow"; + inline constexpr auto desktop_menu = "MenuWindow"; + inline constexpr auto desktop_reboot = "Reboot"; + inline constexpr auto desktop_poweroff = "PowerOffWindow"; + inline constexpr auto dead_battery = "DeadBatteryWindow"; + inline constexpr auto desktop_pin_lock = "PinLockWindow"; + inline constexpr auto desktop_locked = "LockedInfoWindow"; + inline constexpr auto desktop_update = "Update"; + inline constexpr auto desktop_update_progress = "UpdateProgress"; + inline constexpr auto desktop_mmi_pull = "MmiPullWindow"; + inline constexpr auto desktop_mmi_push = "MmiPushWindow"; + inline constexpr auto desktop_mmi_internal = "MmiInternalMsgWindow"; }; // namespace app::window::name diff --git a/module-apps/application-desktop/windows/UpdateProgress.cpp b/module-apps/application-desktop/windows/UpdateProgress.cpp new file mode 100644 index 0000000000000000000000000000000000000000..71ef761136dd820e7e6adb8a398188b06f9c8518 --- /dev/null +++ b/module-apps/application-desktop/windows/UpdateProgress.cpp @@ -0,0 +1,181 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include +#include +#include +#include +#include + +// module-utils +#include + +#include + +// services +#include + +#include +#include + +#include "UpdateProgress.hpp" + +namespace style +{ + namespace image + { + constexpr uint32_t x = 176; + constexpr uint32_t y = 132; + } // namespace image + + namespace text + { + constexpr uint32_t x = 120; + constexpr uint32_t y = 250; + constexpr uint32_t w = 250; + constexpr uint32_t h = 100; + } // namespace text + + namespace percentlabel + { + constexpr uint32_t x = 0; + constexpr uint32_t y = 450; + constexpr uint32_t w = 500; + constexpr uint32_t h = 100; + } // namespace percentlabel + + namespace progressbar + { + constexpr uint32_t x = 100; + constexpr uint32_t y = 400; + } // namespace progressbar + +} // namespace style +namespace gui +{ + + UpdateProgressWindow::UpdateProgressWindow(app::Application *app) + : AppWindow(app, app::window::name::desktop_update_progress) + { + buildInterface(); + } + + void UpdateProgressWindow::rebuild() + { + destroyInterface(); + buildInterface(); + } + + void UpdateProgressWindow::buildInterface() + { + AppWindow::buildInterface(); + + setTitle(utils::localize.get("app_desktop_update_muditaos")); + + icon = new Image(this, style::image::x, style::image::y, "circle_update"); + + text = new Text(this, style::text::x, style::text::y, style::text::w, style::text::h); + text->setTextType(TextType::MultiLine); + text->setEditMode(EditMode::Browse); + text->setEdges(RectangleEdge::None); + text->setFont(style::window::font::biglight); + text->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center)); + + percentLabel = new gui::Label( + this, style::percentlabel::x, style::percentlabel::y, style::percentlabel::w, style::percentlabel::h); + percentLabel->setFilled(false); + percentLabel->setBorderColor(gui::ColorNoColor); + percentLabel->setFont(style::window::font::biglight); + percentLabel->setAlignment( + gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center)); + percentLabel->setVisible(true); + + updateProgress = new ProgressBar(this, + style::progressbar::x, + style::progressbar::y, + style::window_width - 2 * style::progressbar::x, + style::window::label::default_h); + updateProgress->setMaximum(100); + updateProgress->setValue(0); + updateProgress->setVisible(true); + } + + void UpdateProgressWindow::destroyInterface() + { + erase(); + } + + void UpdateProgressWindow::onBeforeShow(ShowMode mode, SwitchData *data) + { + if (data == nullptr) { + LOG_ERROR("Received null pointer"); + } + else { + auto *item = dynamic_cast(data); + if (item != nullptr) { + auto msg = item->getUpdateOsMessage(); + updateFile = msg.updateStats.updateFile; + auto updateVersion = + msg.updateStats.versionInformation[boot::json::os_version][boot::json::version_string] + .string_value(); + text->setRichText(utils::localize.get("app_desktop_update_preparing") + " " + updateVersion); + } + } + state = State::Return; + } + + bool UpdateProgressWindow::handleSwitchData(SwitchData *data) + { + auto *item = dynamic_cast(data); + if (item != nullptr) { + auto status = static_cast(item->getUpdateOsMessage().updateStats.status); + + switch (status) { + case updateos::UpdateState::Initial: + text->setRichText(text->getText()); + progressPercent = 10; + break; + case updateos::UpdateState::UpdateFileSet: + text->setRichText(text->getText()); + progressPercent = 20; + break; + case updateos::UpdateState::CreatingDirectories: + text->setRichText(text->getText()); + progressPercent = 30; + break; + case updateos::UpdateState::ExtractingFiles: + text->setRichText(utils::localize.get("app_desktop_update_in_progress")); + progressPercent = 40; + break; + case updateos::UpdateState::ChecksumVerification: + text->setRichText(text->getText()); + progressPercent = 70; + break; + case updateos::UpdateState::VersionVerificiation: + text->setRichText(text->getText()); + progressPercent = 90; + break; + case updateos::UpdateState::UpdatingBootloader: + text->setRichText(text->getText()); + progressPercent = 99; + break; + case updateos::UpdateState::ReadyForReset: + text->setRichText(utils::localize.get("app_desktop_update_ready_for_reset")); + progressPercent = 100; + break; + default: + if (item->getUpdateOsMessage().updateStats.messageText != "") { + percentLabel->setText(item->getUpdateOsMessage().updateStats.messageText); + } + } + + percentLabel->setVisible(true); + percentLabel->setText(std::to_string(progressPercent) + " %"); + updateProgress->setVisible(true); + updateProgress->setFocus(true); + updateProgress->setValue(progressPercent); + text->setVisible(true); + } + return true; + } +} /* namespace gui */ diff --git a/module-apps/application-desktop/windows/UpdateProgress.hpp b/module-apps/application-desktop/windows/UpdateProgress.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d0a7b61b088ec8ec395a0507e304895a91c61993 --- /dev/null +++ b/module-apps/application-desktop/windows/UpdateProgress.hpp @@ -0,0 +1,47 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include +#include "AppWindow.hpp" +#include "Dialog.hpp" +#include "gui/widgets/Label.hpp" +#include "gui/widgets/TextFixedSize.hpp" +#include "gui/widgets/Image.hpp" +#include "gui/widgets/BottomBar.hpp" +#include "gui/widgets/ProgressBar.hpp" +namespace gui +{ + + class UpdateProgressWindow : public AppWindow + { + + enum class State + { + UpdateNow, + Return, + }; + + unsigned int progressPercent = 0; + + gui::Label *percentLabel = nullptr; + ProgressBar *updateProgress = nullptr; + + State state = State::Return; + fs::path updateFile; + + protected: + Text *text = nullptr; + Image *icon = nullptr; + + public: + UpdateProgressWindow(app::Application *app); + void onBeforeShow(ShowMode mode, SwitchData *data) override; + bool handleSwitchData(SwitchData *data) override; + void rebuild() override; + void buildInterface() override; + void destroyInterface() override; + }; + +} /* namespace gui */ diff --git a/module-gui/gui/widgets/Style.hpp b/module-gui/gui/widgets/Style.hpp index fa1131682fba80ede483f7343259ae0f9f079c2c..7547263c25e4099e00d647d806398c9964c2bb2a 100644 --- a/module-gui/gui/widgets/Style.hpp +++ b/module-gui/gui/widgets/Style.hpp @@ -153,7 +153,7 @@ namespace style inline constexpr auto pause = "common_pause"; inline constexpr auto accept = "common_accept"; inline constexpr auto retry = "common_retry"; - + inline constexpr auto abort = "common_abort"; // days inline constexpr auto Monday = "common_monday"; inline constexpr auto Tuesday = "common_tuesday"; diff --git a/module-services/service-desktop/ServiceDesktop.cpp b/module-services/service-desktop/ServiceDesktop.cpp index 7424f99460079888b24615b02e6a8d2b88e46540..6d4b60b792918b383ad0fc68dc4955aa53479d93 100644 --- a/module-services/service-desktop/ServiceDesktop.cpp +++ b/module-services/service-desktop/ServiceDesktop.cpp @@ -158,6 +158,7 @@ sys::ReturnCodes ServiceDesktop::InitHandler() updateOS->runUpdate(); } } + return std::make_shared(); }); diff --git a/module-services/service-desktop/endpoints/update/UpdateMuditaOS.cpp b/module-services/service-desktop/endpoints/update/UpdateMuditaOS.cpp index bb6e5583a01deecf564b7a9690831ee6bb1f4c25..39525cfbc13649e1d959205b0920c4c1de3b9606 100644 --- a/module-services/service-desktop/endpoints/update/UpdateMuditaOS.cpp +++ b/module-services/service-desktop/endpoints/update/UpdateMuditaOS.cpp @@ -58,8 +58,12 @@ updateos::UpdateError UpdateMuditaOS::setUpdateFile(const std::filesystem::path { if (isUpdateToBeAborted()) { setUpdateAbortFlag(false); + sys::SystemManager::Reboot(owner); return informError(updateos::UpdateError::UpdateAborted, "update aborted"); } + else { + informUpdateWindow(); + } updateFile = purefs::dir::getUpdatesOSPath() / updateFileToUse; if (std::filesystem::exists(updateFile.c_str())) { @@ -80,6 +84,9 @@ updateos::UpdateError UpdateMuditaOS::setUpdateFile(const std::filesystem::path } status = updateos::UpdateState::UpdateFileSet; + + informUpdateWindow(); + return updateos::UpdateError::NoError; } @@ -166,13 +173,25 @@ updateos::UpdateError UpdateMuditaOS::runUpdate() updateos::UpdateError UpdateMuditaOS::unpackUpdate() { + status = updateos::UpdateState::ExtractingFiles; + + if (isUpdateToBeAborted()) { + setUpdateAbortFlag(false); + sys::SystemManager::Reboot(owner); + return updateos::UpdateError::UpdateAborted; + } + else { + informUpdateWindow(); + } + mtar_header_t tarHeader; filesInUpdatePackage.clear(); - status = updateos::UpdateState::ExtractingFiles; + std::rewind(updateTar.stream); while ((mtar_read_header(&updateTar, &tarHeader)) != MTAR_ENULLRECORD) { if (isUpdateToBeAborted()) { setUpdateAbortFlag(false); + sys::SystemManager::Reboot(owner); return updateos::UpdateError::UpdateAborted; } if (std::string(tarHeader.name) == "./") { @@ -226,12 +245,16 @@ std::string UpdateMuditaOS::readContent(const char *filename) noexcept updateos::UpdateError UpdateMuditaOS::verifyChecksums() { + status = updateos::UpdateState::ChecksumVerification; + if (isUpdateToBeAborted()) { setUpdateAbortFlag(false); - return informError(updateos::UpdateError::UpdateAborted, "update aborted"); + sys::SystemManager::Reboot(owner); + return updateos::UpdateError::UpdateAborted; + } + else { + informUpdateWindow(); } - - status = updateos::UpdateState::ChecksumVerification; auto lineBuff = std::make_unique( boot::consts::tar_buf); // max line should be freertos max path + checksum, so this is enough @@ -272,6 +295,15 @@ updateos::UpdateError UpdateMuditaOS::verifyVersion() { status = updateos::UpdateState::VersionVerificiation; + if (isUpdateToBeAborted()) { + setUpdateAbortFlag(false); + sys::SystemManager::Reboot(owner); + return updateos::UpdateError::UpdateAborted; + } + else { + informUpdateWindow(); + } + if (!std::filesystem::exists(getUpdateTmpChild(updateos::file::version).c_str())) { return informError(updateos::UpdateError::VerifyVersionFailure, "verifyVersion %s does not exist", @@ -298,6 +330,17 @@ updateos::UpdateError UpdateMuditaOS::verifyVersion() updateos::UpdateError UpdateMuditaOS::updateBootloader() { informDebug("updateBootloader"); + status = updateos::UpdateState::UpdatingBootloader; + + if (isUpdateToBeAborted()) { + setUpdateAbortFlag(false); + sys::SystemManager::Reboot(owner); + return updateos::UpdateError::UpdateAborted; + } + else { + informUpdateWindow(); + } + if (targetVersionInfo[boot::json::bootloader][parserFSM::json::fileName].is_string()) { fs::path bootloaderFile = getUpdateTmpChild(targetVersionInfo[boot::json::bootloader][parserFSM::json::fileName].string_value()); @@ -338,6 +381,7 @@ updateos::UpdateError UpdateMuditaOS::prepareRoot() informDebug("prepareRoot()"); // basic needed dirs + status = updateos::UpdateState::VersionVerificiation; const auto previousOSPath = purefs::dir::getPreviousOSPath(); const auto currentOSPath = purefs::dir::getCurrentOSPath(); const auto userDiskPath = purefs::dir::getUserDiskPath(); @@ -508,6 +552,9 @@ updateos::UpdateError UpdateMuditaOS::cleanupAfterUpdate() } status = updateos::UpdateState::ReadyForReset; + + informUpdateWindow(); + return updateos::UpdateError::NoError; } @@ -522,12 +569,16 @@ const fs::path UpdateMuditaOS::getUpdateTmpChild(const fs::path &childPath) updateos::UpdateError UpdateMuditaOS::prepareTempDirForUpdate(const std::filesystem::path &temporaryPath, const std::filesystem::path &updatesOSPath) { + status = updateos::UpdateState::CreatingDirectories; + if (isUpdateToBeAborted()) { setUpdateAbortFlag(false); + sys::SystemManager::Reboot(owner); return updateos::UpdateError::UpdateAborted; } - - status = updateos::UpdateState::CreatingDirectories; + else { + informUpdateWindow(); + } updateTempDirectory = temporaryPath / utils::filesystem::generateRandomId(updateos::prefix_len); @@ -806,6 +857,14 @@ void UpdateMuditaOS::setInitialHistory(const std::string &initialHistory) updateHistory = json11::Json(); } } +void UpdateMuditaOS::informUpdateWindow() +{ + fs::path file = UpdateMuditaOS::checkForUpdate(); + auto msgToSend = std::make_shared(updateos::UpdateMessageType::UpdateNow, file); + msgToSend->updateStats.versionInformation = UpdateMuditaOS::getVersionInfoFromFile(file); + msgToSend->updateStats.status = status; + owner->bus.sendUnicast(msgToSend, app::name_desktop); +} void UpdateMuditaOS::storeRunStatusInDB() { diff --git a/module-services/service-desktop/endpoints/update/UpdateMuditaOS.hpp b/module-services/service-desktop/endpoints/update/UpdateMuditaOS.hpp index b9a709983a0d2ade38c25a4ca89336baa900a314..548a08bebee6092e9054458c0d1023b343611577 100644 --- a/module-services/service-desktop/endpoints/update/UpdateMuditaOS.hpp +++ b/module-services/service-desktop/endpoints/update/UpdateMuditaOS.hpp @@ -171,6 +171,7 @@ class UpdateMuditaOS : public updateos::UpdateStats static const fs::path checkForUpdate(); void historyValueChanged(const std::string &value); void setInitialHistory(const std::string &initialHistory); + void informUpdateWindow(); json11::Json getUpdateHistory() const { return updateHistory; diff --git a/module-sys/SystemManager/SystemManager.cpp b/module-sys/SystemManager/SystemManager.cpp index a99da5f405972a7922873acfe44490c9fd4aa93f..e75c4f8b57e34152ef68080a34f3c4a15c0af3aa 100644 --- a/module-sys/SystemManager/SystemManager.cpp +++ b/module-sys/SystemManager/SystemManager.cpp @@ -458,6 +458,16 @@ namespace sys continue; } + if (service->GetName() == service::name::gui) { + LOG_DEBUG("Delay closing %s", service::name::gui); + continue; + } + + if (service->GetName() == service::name::eink) { + LOG_DEBUG("Delay closing %s", service::name::eink); + continue; + } + if (service->GetName() == app::manager::ApplicationManager::ServiceName) { LOG_DEBUG("Delay closing %s", app::manager::ApplicationManager::ServiceName); continue;