2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-11-30 00:07:47 +00:00

feat: show loading progress in modman

This commit is contained in:
Jan Laupetin
2025-10-14 17:59:34 +01:00
parent 5b3664ad8c
commit 9fa41ca0d3
9 changed files with 134 additions and 12 deletions

View File

@@ -4,6 +4,40 @@
#include "Web/UiCommunication.h"
#include "ZoneLoading.h"
#include <filesystem>
namespace fs = std::filesystem;
namespace
{
constexpr double MIN_PROGRESS_TO_REPORT = 0.005;
class EventProgressReporter : public ProgressCallback
{
public:
explicit EventProgressReporter(std::string zoneName)
: m_zone_name(std::move(zoneName)),
m_last_progress(0)
{
}
void OnProgress(const size_t current, const size_t total) override
{
const double percentage = static_cast<double>(current) / static_cast<double>(total);
if (percentage - m_last_progress >= MIN_PROGRESS_TO_REPORT)
{
m_last_progress = percentage;
ui::NotifyZoneLoadProgress(m_zone_name, percentage);
}
}
private:
std::string m_zone_name;
double m_last_progress;
};
} // namespace
void FastFileContext::Destroy()
{
// Unload all zones
@@ -12,7 +46,7 @@ void FastFileContext::Destroy()
result::Expected<Zone*, std::string> FastFileContext::LoadFastFile(const std::string& path)
{
auto zone = ZoneLoading::LoadZone(path, std::nullopt);
auto zone = ZoneLoading::LoadZone(path, std::make_unique<EventProgressReporter>(fs::path(path).filename().replace_extension().string()));
if (!zone)
return result::Unexpected(std::move(zone.error()));

View File

@@ -7,6 +7,15 @@
namespace
{
class ZoneLoadProgressDto
{
public:
std::string zoneName;
double percentage;
};
NLOHMANN_DEFINE_TYPE_EXTENSION(ZoneLoadProgressDto, zoneName, percentage);
class ZoneLoadedDto
{
public:
@@ -71,6 +80,15 @@ namespace
namespace ui
{
void NotifyZoneLoadProgress(std::string zoneName, const double percentage)
{
const ZoneLoadProgressDto dto{
.zoneName = std::move(zoneName),
.percentage = percentage,
};
Notify(*ModManContext::Get().m_main_webview, "zoneLoadProgress", dto);
}
void NotifyZoneLoaded(std::string zoneName, std::string fastFilePath)
{
const ZoneLoadedDto dto{

View File

@@ -4,6 +4,7 @@
namespace ui
{
void NotifyZoneLoadProgress(std::string zoneName, double percentage);
void NotifyZoneLoaded(std::string zoneName, std::string fastFilePath);
void NotifyZoneUnloaded(std::string zoneName);