~aleteoryx/muditaos

ref: 4c661d4f2c736d3cbc13614864511873efc48678 muditaos/module-apps/apps-common/popups/WindowWithTimer.hpp -rw-r--r-- 1.1 KiB
4c661d4f — Lukasz Mastalerz [BH-1412] Improve system shutdown procedure 2 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
// 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 "AppWindow.hpp"
#include <Timers/TimerHandle.hpp>

namespace gui
{
    inline constexpr auto defautTimeout   = std::chrono::seconds{3};
    inline constexpr auto noTimeoutChange = std::chrono::seconds::zero();
    class WindowWithTimer : public gui::AppWindow
    {
      private:
        sys::TimerHandle popupTimer;
        std::chrono::milliseconds timeout;

      public:
        explicit WindowWithTimer(app::ApplicationCommon *app,
                                 const std::string &name,
                                 const std::chrono::milliseconds timeout = defautTimeout);
        void destroyInterface() override;
        ~WindowWithTimer() override;
        void onBeforeShow(ShowMode mode, SwitchData *data) override;
        void onClose(CloseReason reason) override;
        bool onInput(const gui::InputEvent &inputEvent) override;

      protected:
        void detachTimerIfExists();
        void resetTimer(const std::chrono::seconds newTimeout = noTimeoutChange);
    };
} // namespace gui