Files
radiantwave/src/provisioning.cpp
T
2026-08-18 23:37:44 -04:00

83 lines
2.6 KiB
C++

#include "provisioning.h"
#include "email_address_page.h"
#include "home.h"
#include "license_key_page.h"
#include "logger/logger.h"
#include "wifi_setup_page.h"
namespace radiantwave::provisioning {
// Push the page for a walkthrough step, or Home when the walkthrough is done.
static void pushStep(AppState &state, Step step) {
switch (step) {
// case Step::Internet:
// state.pages.push(state, std::make_unique<WiFiSetupPage>());
// break;
case Step::Email:
state.pages.push(state, std::make_unique<EmailAddressPage>());
break;
case Step::License:
state.pages.push(state, std::make_unique<LicenseKeyPage>());
break;
case Step::Done:
state.provisioningMode = false;
state.pages.push(state, std::make_unique<Home>());
break;
}
}
void begin(AppState &state) {
// Without the database there is nowhere to persist email/license, so the
// walkthrough would trap the user on pages that can never be completed.
if (!state.db.isOpen()) {
state.provisioningMode = false;
state.pages.push(state, std::make_unique<Home>());
return;
}
const bool internetUp = state.network.hasInternet();
const bool hasEmail =
!state.db.getKV(radiantwave::db::KV_EMAIL_ADDRESS).empty();
const bool hasLicense =
!state.db.getKV(radiantwave::db::KV_LICENSE_KEY).empty();
if (indicatesFirstRun(internetUp, hasEmail, hasLicense)) {
// Placeholder: a brand-new device. Later this flag will launch the
// first-run welcome walkthrough (TOS, quick user guide, ...).
state.firstRunWalkthrough = true;
radiantwave::logger::Logger::instance().info(
"Provisioning",
"First-Run detected (no internet, no email, no license); "
"first-run welcome walkthrough is not yet implemented");
}
state.walkthroughInternetUp = internetUp;
state.provisioningMode = true;
pushStep(state, firstMissingStep(internetUp, hasEmail, hasLicense));
}
void advance(AppState &state) {
if (state.pages.depth() > 0) {
state.pages.pop(state);
}
// Internet is the first prerequisite and never gets "un-reached" once
// satisfied, so it is only re-probed when it was still missing (i.e. the
// walkthrough is coming from the WiFi page).
bool internetUp = state.walkthroughInternetUp;
if (!internetUp) {
internetUp = state.network.hasInternet();
state.walkthroughInternetUp = internetUp;
}
const bool hasEmail =
!state.db.getKV(radiantwave::db::KV_EMAIL_ADDRESS).empty();
const bool hasLicense =
!state.db.getKV(radiantwave::db::KV_LICENSE_KEY).empty();
state.provisioningMode = true;
pushStep(state, firstMissingStep(internetUp, hasEmail, hasLicense));
}
} // namespace radiantwave::provisioning