~aleteoryx/muditaos

ref: e841f9af0c00528e776afa9eca8ab6a68e3743ad muditaos/module-apps/application-desktop/windows/UpdateProgress.cpp -rw-r--r-- 6.6 KiB
e841f9af — Pawel.Paprocki [EGD-6351] Add Factory reset window 5 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <log/log.hpp>
#include <gui/widgets/BottomBar.hpp>
#include <gui/widgets/TopBar.hpp>
#include <application-desktop/data/LockPhoneData.hpp>
#include <source/version.hpp>

// module-utils
#include <i18n/i18n.hpp>

#include <application-desktop/ApplicationDesktop.hpp>
#include <application-desktop/data/Style.hpp>

// services
#include <service-appmgr/model/ApplicationManager.hpp>

#include <Style.hpp>
#include <DialogMetadataMessage.hpp>
#include "UpdateProgress.hpp"

namespace gui
{
    UpdateProgressWindow::UpdateProgressWindow(app::Application *app)
        : AppWindow(app, app::window::name::desktop_update_progress)
    {
        buildInterface();
    }

    void UpdateProgressWindow::onBeforeShow(ShowMode mode, SwitchData *data)
    {
        if (data == nullptr) {
            LOG_ERROR("Received null pointer");
        }
        else {
            auto *item = dynamic_cast<gui::UpdateSwitchData *>(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();
                if (text->getText().empty()) {
                    text->setText(utils::localize.get("app_desktop_update_preparing") + " " + updateVersion);
                }
                else {
                    text->setText(textInfo);
                }
            }
            percentLabel->setText(std::to_string(progressPercent) + " %");
            updateProgress->setValue(progressPercent);
        }
        setVisibleState();
    }

    void UpdateProgressWindow::setVisibleState()
    {
        percentLabel->setVisible(true);
        updateProgress->setVisible(true);
        updateProgress->setVisible(true);
        text->setVisible(true);
    }

    void UpdateProgressWindow::rebuild()
    {
        destroyInterface();
        buildInterface();
    }

    top_bar::Configuration UpdateProgressWindow::configureTopBar(top_bar::Configuration appConfiguration)
    {
        appConfiguration.enable(top_bar::Indicator::Time);
        appConfiguration.disable(top_bar::Indicator::Lock);
        appConfiguration.disable(top_bar::Indicator::Battery);
        appConfiguration.disable(top_bar::Indicator::NetworkAccessTechnology);
        appConfiguration.disable(top_bar::Indicator::Signal);
        appConfiguration.disable(top_bar::Indicator::SimCard);
        return appConfiguration;
    }

    void UpdateProgressWindow::buildInterface()
    {
        AppWindow::buildInterface();

        setTitle(utils::localize.get("app_desktop_update_muditaos"));

        icon = new Image(this, style::desktop::image::x, style::desktop::image::y, "circle_update");

        text = new Text(this,
                        style::desktop::textupdate::x,
                        style::desktop::textupdate::y,
                        style::desktop::textupdate::w,
                        style::desktop::textupdate::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::desktop::percentlabel::x,
                                      style::desktop::percentlabel::y,
                                      style::desktop::percentlabel::w,
                                      style::desktop::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));

        updateProgress = new ProgressBar(this,
                                         style::window::progressBar::x,
                                         style::window::progressBar::y,
                                         style::window::progressBar::width,
                                         style::window::progressBar::h);
        updateProgress->setMaximum(100);
        updateProgress->setValue(0);
    }

    void UpdateProgressWindow::destroyInterface()
    {
        erase();
        invalidate();
    }

    void UpdateProgressWindow::invalidate() noexcept
    {
        percentLabel   = nullptr;
        updateProgress = nullptr;
        text           = nullptr;
        icon           = nullptr;
    }

    bool UpdateProgressWindow::handleSwitchData(SwitchData *data)
    {
        auto *item = dynamic_cast<gui::UpdateSwitchData *>(data);
        if (item != nullptr) {
            auto status = static_cast<updateos::UpdateState>(item->getUpdateOsMessage().updateStats.status);
            switch (status) {
            case updateos::UpdateState::Initial:
                textInfo        = text->getText();
                progressPercent = 10;
                break;
            case updateos::UpdateState::UpdateFileSet:
                textInfo        = text->getText();
                progressPercent = 20;
                break;
            case updateos::UpdateState::CreatingDirectories:
                textInfo        = text->getText();
                progressPercent = 30;
                break;
            case updateos::UpdateState::ExtractingFiles:
                textInfo        = utils::localize.get("app_desktop_update_in_progress");
                progressPercent = 40;
                break;
            case updateos::UpdateState::ChecksumVerification:
                textInfo        = text->getText();
                progressPercent = 70;
                break;
            case updateos::UpdateState::VersionVerificiation:
                textInfo        = text->getText();
                progressPercent = 80;
                break;
            case updateos::UpdateState::UpdatingBootloader:
                textInfo        = utils::localize.get("app_desktop_update_ready_for_reset");
                progressPercent = 99;
                break;
            case updateos::UpdateState::ReadyForReset:
                textInfo        = text->getText();
                progressPercent = 100;
                break;
            }
        }
        return true;
    }
} /* namespace gui */