Haiku: native Interface Kit user interface
Same workflow as the GTK interface: vehicle list, adding a vehicle by VIN, available updates, download folder, resumable download with progress, USB stick selection with an erase confirmation, writing, installation guide. Also a Preferences window (folder, language, automatic new-version check), an About window and the manual new-version check. Worker threads post closures to the window through a non-blocking queue (BMessenger with a zero timeout). Translations use gettext with the GTK catalogs; the default language comes from the Locale preferences. The executable gets its signature and version from a generated .rdef. Validated in the Haiku R1/beta6 VM against a mock Majestic server: full flow down to a FAT32 stick with license/, both archives and no UpdateInfo.xml; French interface; GitHub new-version check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WDASLCiN764v685boRVYar
This commit is contained in:
1 parent
e5af8ea27d
commit
155545660e
13 files changed
+2266
-372
No files matched your search
@@ -0,0 +1,32 @@
|
||||
include(GNUInstallDirs)
|
||||
|
||||
add_executable(OpenPU
|
||||
main.cpp
|
||||
main_window.cpp
|
||||
)
|
||||
find_library(INTL_LIBRARY intl)
|
||||
target_link_libraries(OpenPU PRIVATE openpu_core openpu_warnings be tracker shared
|
||||
$<$<BOOL:${INTL_LIBRARY}>:${INTL_LIBRARY}>)
|
||||
target_compile_definitions(OpenPU PRIVATE
|
||||
GETTEXT_PACKAGE="openpu"
|
||||
OPENPU_LOCALEDIR="${CMAKE_INSTALL_FULL_LOCALEDIR}")
|
||||
# BeAPI headers trigger -Wshadow/-Wconversion noise we cannot fix.
|
||||
target_compile_options(OpenPU PRIVATE -Wno-shadow -Wno-conversion)
|
||||
|
||||
# Application resources: signature, version, flags (Haiku rc + xres).
|
||||
configure_file(OpenPU.rdef.in ${CMAKE_CURRENT_BINARY_DIR}/OpenPU.rdef @ONLY)
|
||||
find_program(HAIKU_RC rc)
|
||||
find_program(HAIKU_XRES xres)
|
||||
find_program(HAIKU_MIMESET mimeset)
|
||||
if(HAIKU_RC AND HAIKU_XRES)
|
||||
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/OpenPU.rsrc
|
||||
COMMAND ${HAIKU_RC} -o ${CMAKE_CURRENT_BINARY_DIR}/OpenPU.rsrc ${CMAKE_CURRENT_BINARY_DIR}/OpenPU.rdef
|
||||
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/OpenPU.rdef)
|
||||
add_custom_target(OpenPU_rsrc DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/OpenPU.rsrc)
|
||||
add_dependencies(OpenPU OpenPU_rsrc)
|
||||
add_custom_command(TARGET OpenPU POST_BUILD
|
||||
COMMAND ${HAIKU_XRES} -o $<TARGET_FILE:OpenPU> ${CMAKE_CURRENT_BINARY_DIR}/OpenPU.rsrc
|
||||
COMMAND ${HAIKU_MIMESET} -f $<TARGET_FILE:OpenPU>)
|
||||
endif()
|
||||
|
||||
install(TARGETS OpenPU RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
@@ -0,0 +1,15 @@
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
|
||||
resource app_signature "application/x-vnd.openpu-OpenPU";
|
||||
|
||||
resource app_flags B_SINGLE_LAUNCH;
|
||||
|
||||
resource app_version {
|
||||
major = @PROJECT_VERSION_MAJOR@,
|
||||
middle = @PROJECT_VERSION_MINOR@,
|
||||
minor = @PROJECT_VERSION_PATCH@,
|
||||
variety = B_APPV_FINAL,
|
||||
internal = 0,
|
||||
short_info = "OpenPU @PROJECT_VERSION@",
|
||||
long_info = "OpenPU @PROJECT_VERSION@ - Peugeot head unit updates on a USB stick. MIT license."
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#pragma once
|
||||
|
||||
// gettext, with the same message catalogs as the GTK interface (po/).
|
||||
#include <libintl.h>
|
||||
|
||||
#include <initializer_list>
|
||||
#include <string>
|
||||
|
||||
#define _(text) gettext(text)
|
||||
|
||||
namespace openpu::haiku {
|
||||
|
||||
/// Replaces %1..%9 in `format` (same placeholders as Glib::ustring::compose, so the translations
|
||||
/// are shared with the GTK interface).
|
||||
inline std::string compose(const std::string& format, std::initializer_list<std::string> args)
|
||||
{
|
||||
std::string out;
|
||||
out.reserve(format.size());
|
||||
for (std::size_t i = 0; i < format.size(); ++i) {
|
||||
const char c = format[i];
|
||||
if (c == '%' && i + 1 < format.size() && format[i + 1] >= '1' && format[i + 1] <= '9') {
|
||||
const auto index = static_cast<std::size_t>(format[i + 1] - '1');
|
||||
if (index < args.size())
|
||||
out += *(args.begin() + index);
|
||||
++i;
|
||||
continue;
|
||||
}
|
||||
out.push_back(c);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace openpu::haiku
|
||||
@@ -0,0 +1,75 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#include "main_window.hpp"
|
||||
|
||||
#include "openpu/storage.hpp"
|
||||
|
||||
#include <Application.h>
|
||||
#include <LocaleRoster.h>
|
||||
#include <Message.h>
|
||||
|
||||
#include "i18n.hpp"
|
||||
|
||||
#include <cctype>
|
||||
#include <clocale>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr const char* kSignature = "application/x-vnd.openpu-OpenPU";
|
||||
|
||||
/// First preferred language of the Locale preferences ("fr", "en_US"...), empty if unknown.
|
||||
std::string preferredLanguage()
|
||||
{
|
||||
BMessage languages;
|
||||
if (BLocaleRoster::Default()->GetPreferredLanguages(&languages) != B_OK)
|
||||
return {};
|
||||
const char* language = nullptr;
|
||||
if (languages.FindString("language", 0, &language) != B_OK || language == nullptr)
|
||||
return {};
|
||||
return language;
|
||||
}
|
||||
|
||||
class App : public BApplication {
|
||||
public:
|
||||
explicit App(std::string language) : BApplication(kSignature), language_(std::move(language)) {}
|
||||
|
||||
void ReadyToRun() override { (new openpu::haiku::MainWindow(language_))->Show(); }
|
||||
|
||||
private:
|
||||
std::string language_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
// A language chosen in the settings overrides the one of the Locale preferences.
|
||||
std::string language;
|
||||
try {
|
||||
language = openpu::Settings::load(openpu::paths::configDir() / "config.json").language;
|
||||
} catch (const openpu::StorageError&) {
|
||||
// dismissed: the window reports unreadable settings itself
|
||||
}
|
||||
if (language.empty())
|
||||
language = preferredLanguage();
|
||||
if (language.empty())
|
||||
language = "en";
|
||||
|
||||
// gettext follows LANGUAGE, but only when the message locale is not "C".
|
||||
(void)setenv("LANGUAGE", language.c_str(), 1); // NOLINT(concurrency-mt-unsafe): no thread yet
|
||||
(void)setenv("LC_MESSAGES", "en_US.UTF-8", 0); // NOLINT(concurrency-mt-unsafe)
|
||||
(void)std::setlocale(LC_ALL, ""); // NOLINT(concurrency-mt-unsafe)
|
||||
const char* localeDir = std::getenv("OPENPU_LOCALEDIR"); // NOLINT(concurrency-mt-unsafe): build tree
|
||||
bindtextdomain(GETTEXT_PACKAGE, localeDir != nullptr ? localeDir : OPENPU_LOCALEDIR);
|
||||
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
|
||||
textdomain(GETTEXT_PACKAGE);
|
||||
|
||||
std::string twoLetters;
|
||||
for (char c : language.substr(0, 2))
|
||||
twoLetters.push_back(static_cast<char>(std::tolower(static_cast<unsigned char>(c))));
|
||||
|
||||
App app(twoLetters);
|
||||
app.Run();
|
||||
return 0;
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,167 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#pragma once
|
||||
|
||||
#include "ui_queue.hpp"
|
||||
|
||||
#include "openpu/api_client.hpp"
|
||||
#include "openpu/app_update.hpp"
|
||||
#include "openpu/job.hpp"
|
||||
#include "openpu/storage.hpp"
|
||||
#include "openpu/usb.hpp"
|
||||
|
||||
#include <Messenger.h>
|
||||
#include <Window.h>
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
class BButton;
|
||||
class BCardView;
|
||||
class BCheckBox;
|
||||
class BFilePanel;
|
||||
class BListView;
|
||||
class BMenuField;
|
||||
class BPopUpMenu;
|
||||
class BStatusBar;
|
||||
class BStringView;
|
||||
class BTextControl;
|
||||
class BTextView;
|
||||
class BView;
|
||||
|
||||
namespace openpu::haiku {
|
||||
|
||||
/// Messages shared with the preferences window.
|
||||
enum : uint32 {
|
||||
kMsgChooseFolder = 'chfd', ///< main window: open the folder panel
|
||||
kMsgSetLanguage = 'slng', ///< main window: "language" (string, empty = system)
|
||||
kMsgSetAutoCheck = 'sach', ///< main window: "value" (bool)
|
||||
kMsgFolderChanged = 'fdch',///< preferences window: "path" (string)
|
||||
};
|
||||
|
||||
class MainWindow : public BWindow {
|
||||
public:
|
||||
/// `language`: two-letter language of the interface (for the guide links).
|
||||
explicit MainWindow(std::string language);
|
||||
~MainWindow() override;
|
||||
MainWindow(const MainWindow&) = delete;
|
||||
MainWindow& operator=(const MainWindow&) = delete;
|
||||
|
||||
void MessageReceived(BMessage* message) override;
|
||||
bool QuitRequested() override;
|
||||
|
||||
private:
|
||||
enum Page : int32 { Vehicles, Add, Updates, Download, Usb, Write, Done };
|
||||
|
||||
// pages
|
||||
BView* buildVehiclesPage();
|
||||
BView* buildAddPage();
|
||||
BView* buildUpdatesPage();
|
||||
BView* buildDownloadPage();
|
||||
BView* buildUsbPage();
|
||||
BView* buildWritePage();
|
||||
BView* buildDonePage();
|
||||
void show(Page page);
|
||||
|
||||
// vehicles
|
||||
void refreshVehicles();
|
||||
std::optional<Vehicle> selectedVehicle() const;
|
||||
void onVehicleSelected();
|
||||
void onAddVehicle();
|
||||
void onRemoveVehicle();
|
||||
void onCheckUpdates();
|
||||
|
||||
// updates / download
|
||||
void showUpdates(const AvailableUpdates& updates);
|
||||
void updateDownloadButton();
|
||||
void onChooseFolder();
|
||||
void onFolderChosen(BMessage* message);
|
||||
void onStartDownload();
|
||||
void startDownload(const DownloadPlan& plan);
|
||||
void onDownloadProgress(const JobProgress& p);
|
||||
void onDownloaded(const DownloadedFiles& files);
|
||||
|
||||
// usb
|
||||
void enterUsbPage();
|
||||
void refreshDrives();
|
||||
void onDriveSelected();
|
||||
void onPrepareUsb();
|
||||
void startWrite(const UsbDrive& drive);
|
||||
void onWriteProgress(const UsbProgress& p);
|
||||
void onWritten();
|
||||
|
||||
// helpers
|
||||
template <typename F>
|
||||
void runAsync(F&& work);
|
||||
void joinWorker();
|
||||
void showError(const std::string& title, const std::string& detail);
|
||||
void showAbout();
|
||||
void showPreferences();
|
||||
void openGuide();
|
||||
void checkAppUpdate(bool manual);
|
||||
void offerAppUpdate(const AppRelease& release);
|
||||
void saveVehicles();
|
||||
void saveSettings();
|
||||
void updateDownloadDirLabel();
|
||||
|
||||
UiQueue ui_;
|
||||
std::string language_;
|
||||
std::unique_ptr<Transport> transport_;
|
||||
std::unique_ptr<ApiClient> api_;
|
||||
std::unique_ptr<UsbBackend> usb_;
|
||||
VehicleStore store_;
|
||||
Settings settings_;
|
||||
std::filesystem::path settingsFile_;
|
||||
std::thread worker_;
|
||||
std::thread updateThread_; // OpenPU new-version check, independent of the main flow
|
||||
bool updateCheckRunning_ = false;
|
||||
CancelToken cancel_;
|
||||
BMessenger preferences_;
|
||||
BFilePanel* folderPanel_ = nullptr;
|
||||
|
||||
// flow state
|
||||
std::optional<Vehicle> current_;
|
||||
AvailableUpdates updates_;
|
||||
DownloadedFiles files_;
|
||||
std::vector<UsbDrive> drives_;
|
||||
std::int32_t selectedDrive_ = -1;
|
||||
std::uint64_t payload_ = 0;
|
||||
|
||||
// widgets
|
||||
BCardView* cards_ = nullptr;
|
||||
|
||||
BListView* vehicleList_ = nullptr;
|
||||
BTextView* vehiclesEmpty_ = nullptr;
|
||||
BButton *removeButton_ = nullptr, *checkButton_ = nullptr;
|
||||
|
||||
BTextControl *vinEntry_ = nullptr, *nameEntry_ = nullptr;
|
||||
BStringView* addStatus_ = nullptr;
|
||||
BButton* addConfirm_ = nullptr;
|
||||
|
||||
BStringView* updatesTitle_ = nullptr;
|
||||
BTextView* updatesStatus_ = nullptr;
|
||||
BCheckBox *firmwareCheck_ = nullptr, *mapCheck_ = nullptr;
|
||||
BStringView* downloadDirLabel_ = nullptr;
|
||||
BButton *downloadButton_ = nullptr, *guideButton_ = nullptr;
|
||||
|
||||
BStringView* licenseLabel_ = nullptr;
|
||||
BStatusBar *firmwareBar_ = nullptr, *mapBar_ = nullptr;
|
||||
BStringView* etaLabel_ = nullptr;
|
||||
BButton* cancelDownload_ = nullptr;
|
||||
|
||||
BTextView* usbInfo_ = nullptr;
|
||||
BPopUpMenu* driveMenu_ = nullptr;
|
||||
BMenuField* driveField_ = nullptr;
|
||||
BStringView* usbStatus_ = nullptr;
|
||||
BButton* prepareButton_ = nullptr;
|
||||
|
||||
BStatusBar* writeBar_ = nullptr;
|
||||
BStringView* writeDetail_ = nullptr;
|
||||
BButton* cancelWrite_ = nullptr;
|
||||
|
||||
BButton* doneButton_ = nullptr;
|
||||
};
|
||||
|
||||
} // namespace openpu::haiku
|
||||
@@ -0,0 +1,55 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#pragma once
|
||||
|
||||
#include <Messenger.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <deque>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
|
||||
namespace openpu::haiku {
|
||||
|
||||
/// Runs closures posted from worker threads on a window's thread.
|
||||
/// post() never blocks: a single kMessage is in flight at a time and drain() runs everything queued.
|
||||
class UiQueue {
|
||||
public:
|
||||
static constexpr uint32 kMessage = 'uiqd';
|
||||
|
||||
void setTarget(const BMessenger& target) { target_ = target; }
|
||||
|
||||
void post(std::function<void()> fn)
|
||||
{
|
||||
{
|
||||
std::scoped_lock lock(mutex_);
|
||||
queue_.push_back(std::move(fn));
|
||||
}
|
||||
if (!pending_.exchange(true)) {
|
||||
BMessage message(kMessage);
|
||||
// Zero timeout: a worker must never wait for the window (it may be joining the worker).
|
||||
if (target_.SendMessage(&message, static_cast<BHandler*>(nullptr), 0) != B_OK)
|
||||
pending_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Called by the target window when it receives kMessage.
|
||||
void drain()
|
||||
{
|
||||
pending_ = false;
|
||||
std::deque<std::function<void()>> local;
|
||||
{
|
||||
std::scoped_lock lock(mutex_);
|
||||
local.swap(queue_);
|
||||
}
|
||||
for (auto& fn : local)
|
||||
fn();
|
||||
}
|
||||
|
||||
private:
|
||||
BMessenger target_;
|
||||
std::atomic<bool> pending_{false};
|
||||
std::mutex mutex_;
|
||||
std::deque<std::function<void()>> queue_;
|
||||
};
|
||||
|
||||
} // namespace openpu::haiku
|
||||
Reference in new issue
Block a user