mirror of
https://github.com/m5stack/StackChan.git
synced 2026-04-27 19:12:40 +00:00
100 lines
2.3 KiB
C++
100 lines
2.3 KiB
C++
/*
|
|
* SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
#include "app_launcher.h"
|
|
#include <hal/hal.h>
|
|
#include <mooncake.h>
|
|
#include <mooncake_log.h>
|
|
#include <stackchan/stackchan.h>
|
|
#include <cstdint>
|
|
|
|
using namespace mooncake;
|
|
|
|
void AppLauncher::onLauncherCreate()
|
|
{
|
|
mclog::tagInfo(getAppInfo().name, "on create");
|
|
|
|
// 打开自己
|
|
open();
|
|
}
|
|
|
|
void AppLauncher::onLauncherOpen()
|
|
{
|
|
mclog::tagInfo(getAppInfo().name, "on open");
|
|
|
|
LvglLockGuard lock;
|
|
|
|
if (!_startup_checked && !GetHAL().isAppConfiged()) {
|
|
mclog::tagInfo(getAppInfo().name, "app not configured, start startup worker");
|
|
_startup_worker = std::make_unique<setup_workers::StartupWorker>();
|
|
} else {
|
|
create_launcher_view();
|
|
}
|
|
}
|
|
|
|
void AppLauncher::onLauncherRunning()
|
|
{
|
|
LvglLockGuard lock;
|
|
|
|
if (_startup_worker) {
|
|
_startup_worker->update();
|
|
if (_startup_worker->isDone()) {
|
|
_startup_worker.reset();
|
|
_startup_checked = true;
|
|
create_launcher_view();
|
|
}
|
|
} else {
|
|
_view->update();
|
|
screensaver_update();
|
|
}
|
|
|
|
GetStackChan().update();
|
|
}
|
|
|
|
void AppLauncher::onLauncherClose()
|
|
{
|
|
mclog::tagInfo(getAppInfo().name, "on close");
|
|
|
|
LvglLockGuard lock;
|
|
|
|
_view.reset();
|
|
}
|
|
|
|
void AppLauncher::onLauncherDestroy()
|
|
{
|
|
mclog::tagInfo(getAppInfo().name, "on close");
|
|
}
|
|
|
|
void AppLauncher::create_launcher_view()
|
|
{
|
|
_view = std::make_unique<view::LauncherView>();
|
|
_view->init(getAppProps());
|
|
_view->onAppClicked = [&](int appID) {
|
|
mclog::tagInfo(getAppInfo().name, "handle open app, app id: {}", appID);
|
|
openApp(appID);
|
|
};
|
|
}
|
|
|
|
void AppLauncher::screensaver_update()
|
|
{
|
|
const uint32_t SCREENSAVER_TIMEOUT_MS = 30000;
|
|
|
|
uint32_t idle_time = lv_display_get_inactive_time(NULL);
|
|
if (idle_time >= SCREENSAVER_TIMEOUT_MS) {
|
|
if (!_screensaver) {
|
|
_screensaver = std::make_unique<view::Screensaver>();
|
|
_screensaver->init();
|
|
}
|
|
} else if (_screensaver) {
|
|
_screensaver.reset();
|
|
}
|
|
|
|
// Update in 30ms interval
|
|
if (_screensaver && GetHAL().millis() - _screensaver_timecount > 30) {
|
|
_screensaver_timecount = GetHAL().millis();
|
|
_screensaver->update();
|
|
}
|
|
}
|