mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-08-17 23:55:04 +00:00
Fix Setup
This commit is contained in:
parent
e618086590
commit
884a008333
@ -1,7 +1,9 @@
|
||||
#include <Tactility/app/setup/Setup.h>
|
||||
|
||||
#include <Tactility/StringUtils.h>
|
||||
#include <Tactility/app/timezone/TimeZone.h>
|
||||
#include <Tactility/app/wifimanage/WifiManage.h>
|
||||
#include <Tactility/file/File.h>
|
||||
#include <Tactility/service/wifi/Wifi.h>
|
||||
|
||||
#include <app/event.h>
|
||||
@ -10,8 +12,8 @@
|
||||
|
||||
#include <lvgl_window_manager/window_manager.h>
|
||||
|
||||
#include <tactility/log.h>
|
||||
#include <tactility/paths.h>
|
||||
#include <tactility/preferences.h>
|
||||
|
||||
#include <lvgl/fonts.h>
|
||||
#include <lvgl/lvgl.h>
|
||||
@ -32,17 +34,16 @@ namespace tt::app::setup {
|
||||
|
||||
extern const ::AppManifest manifest;
|
||||
|
||||
constexpr auto* PREFERENCES_NAMESPACE = "setup";
|
||||
constexpr auto* PREFERENCES_KEY_COMPLETED = "completed";
|
||||
constexpr auto* TAG = "setup";
|
||||
|
||||
namespace {
|
||||
|
||||
bool getPreferencesPath(std::string& outPath) {
|
||||
bool getCompletedMarkerPath(std::string& outPath) {
|
||||
char root[128];
|
||||
if (paths_get_user_data_path(root, sizeof(root)) != ERROR_NONE) {
|
||||
return false;
|
||||
}
|
||||
outPath = std::string(root) + "/" + PREFERENCES_NAMESPACE + ".properties";
|
||||
outPath = std::string(root) + "/.setup_complete";
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -50,32 +51,23 @@ bool getPreferencesPath(std::string& outPath) {
|
||||
|
||||
bool isCompleted() {
|
||||
std::string path;
|
||||
if (!getPreferencesPath(path)) {
|
||||
if (!getCompletedMarkerPath(path)) {
|
||||
LOG_E(TAG, "Setup path not found");
|
||||
return false;
|
||||
}
|
||||
Preferences* preferences = preferences_open(path.c_str());
|
||||
if (preferences == nullptr) {
|
||||
return false;
|
||||
}
|
||||
bool completed = false;
|
||||
preferences_opt_bool(preferences, PREFERENCES_KEY_COMPLETED, &completed);
|
||||
preferences_close(preferences);
|
||||
return completed;
|
||||
file::FileMutexGuard guard(path);
|
||||
return file::isFile(path);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
void markCompleted() {
|
||||
std::string path;
|
||||
if (!getPreferencesPath(path)) {
|
||||
if (!getCompletedMarkerPath(path)) {
|
||||
return;
|
||||
}
|
||||
Preferences* preferences = preferences_open(path.c_str());
|
||||
if (preferences == nullptr) {
|
||||
return;
|
||||
}
|
||||
preferences_put_bool(preferences, PREFERENCES_KEY_COMPLETED, true);
|
||||
preferences_close(preferences);
|
||||
file::FileMutexGuard guard(path);
|
||||
file::writeString(path, "");
|
||||
}
|
||||
|
||||
enum class Phase {
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#include <tactility/preferences.h>
|
||||
#include <tactility/properties_file.h>
|
||||
|
||||
#include <tactility/log.h>
|
||||
#include <tactility/paths.h>
|
||||
#include <tactility/properties_file.h>
|
||||
|
||||
#include <cerrno>
|
||||
#include <cinttypes>
|
||||
@ -15,6 +17,8 @@
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr auto* TAG = "preferences";
|
||||
|
||||
// Escapes '\\' and '\n' so a string value can never break properties_file's one-entry-per-line
|
||||
// on-disk format, regardless of its content.
|
||||
std::string escape(const std::string& value) {
|
||||
@ -176,16 +180,19 @@ extern "C" {
|
||||
Preferences* preferences_open(const char* path) {
|
||||
std::string directory = parent_directory(path);
|
||||
if (!directory.empty() && !ensure_directory_recursive(directory)) {
|
||||
LOG_E(TAG, "Directory not found: %s", directory.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PropertiesFile* file = properties_file_open(path);
|
||||
if (file == nullptr) {
|
||||
LOG_E(TAG, "Failed to open %s", path);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto* preferences = new (std::nothrow) Preferences { file };
|
||||
if (preferences == nullptr) {
|
||||
LOG_E(TAG, "Out of memory");
|
||||
properties_file_close(file);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user