Add about menu service boundary

This commit is contained in:
2026-06-03 12:47:15 +02:00
parent fb111dcdc9
commit b67f3d63cf
5 changed files with 219 additions and 46 deletions

View File

@@ -309,6 +309,73 @@ private:
App& app_;
};
class LegacyAboutMenuServices final : public pp::app::AboutMenuServices {
public:
explicit LegacyAboutMenuServices(App& app) noexcept
: app_(app)
{
}
void show_user_manual() override
{
app_.dialog_usermanual();
}
void show_about_dialog() override
{
app_.dialog_about();
}
void show_whats_new_dialog() override
{
app_.dialog_whatsnew(true);
}
void trigger_crash_test() override
{
LOG("crashing");
app_.crash_test();
}
void run_performance_test(const pp::app::AboutMenuPlan& plan) override
{
if (!Canvas::I)
return;
LOG("perf");
std::string message;
const int performance_iterations = plan.performance_iterations;
app_.render_task([&]
{
auto start = std::chrono::high_resolution_clock::now();
Canvas::I->stroke_start({ 0, 0, 0 }, 0.9f);
for (int i = 0; i < performance_iterations; i++)
{
Canvas::I->stroke_update({ 100, 100, 0 }, 0.9f);
Canvas::I->stroke_update({ 200, 200, 0 }, 0.9f);
Canvas::I->stroke_update({ 200, 100, 0 }, 0.9f);
Canvas::I->stroke_update({ 100, 200, 0 }, 0.9f);
Canvas::I->stroke_update({ 300, 300, 0 }, 0.9f);
Canvas::I->stroke_update({ 200, 500, 0 }, 0.9f);
Canvas::I->stroke_update({ 500, 500, 0 }, 0.9f);
Canvas::I->stroke_update({ 400, 400, 0 }, 0.9f);
Canvas::I->stroke_update({ 0, 200, 0 }, 0.9f);
Canvas::I->stroke_update({ 200, 0, 0 }, 0.9f);
Canvas::I->stroke_draw();
}
Canvas::I->stroke_end();
auto diff = std::chrono::high_resolution_clock::now() - start;
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(diff).count();
LOG("%lld ms", ms);
message = "Time " + std::to_string(ms) + " ms";
});
app_.message_box("Performance test", message);
}
private:
App& app_;
};
void execute_main_toolbar_plan(App& app, const pp::app::MainToolbarPlan& plan)
{
LegacyMainToolbarServices services(app);
@@ -317,6 +384,14 @@ void execute_main_toolbar_plan(App& app, const pp::app::MainToolbarPlan& plan)
LOG("Main toolbar action failed: %s", status.message);
}
void execute_about_menu_plan(App& app, const pp::app::AboutMenuPlan& plan)
{
LegacyAboutMenuServices services(app);
const auto status = pp::app::execute_about_menu_plan(plan, services);
if (!status.ok())
LOG("About menu action failed: %s", status.message);
}
} // namespace
void App::title_update()
@@ -1583,8 +1658,7 @@ void App::init_menu_about()
g_version_major,
g_version_minor,
g_version_fix);
if (plan.action == pp::app::AboutMenuAction::show_about_dialog)
dialog_about();
execute_about_menu_plan(*this, plan);
if (plan.closes_root_popup)
{
popup->mouse_release();
@@ -1600,8 +1674,7 @@ void App::init_menu_about()
g_version_major,
g_version_minor,
g_version_fix);
if (plan.action == pp::app::AboutMenuAction::show_user_manual)
dialog_usermanual();
execute_about_menu_plan(*this, plan);
if (plan.closes_root_popup)
{
popup->mouse_release();
@@ -1626,8 +1699,7 @@ void App::init_menu_about()
g_version_major,
g_version_minor,
g_version_fix);
if (plan.action == pp::app::AboutMenuAction::show_whats_new_dialog)
dialog_whatsnew(true);
execute_about_menu_plan(*this, plan);
if (plan.closes_root_popup)
{
popup->mouse_release();
@@ -1644,11 +1716,7 @@ void App::init_menu_about()
g_version_major,
g_version_minor,
g_version_fix);
if (plan.action == pp::app::AboutMenuAction::trigger_crash_test)
{
LOG("crashing");
crash_test();
}
execute_about_menu_plan(*this, plan);
if (plan.closes_root_popup)
{
popup->mouse_release();
@@ -1667,37 +1735,7 @@ void App::init_menu_about()
g_version_fix,
true,
Canvas::I != nullptr);
if (plan.action == pp::app::AboutMenuAction::run_performance_test)
{
LOG("perf");
std::string message;
const int performance_iterations = plan.performance_iterations;
render_task([&]
{
auto start = std::chrono::high_resolution_clock::now();
Canvas::I->stroke_start({ 0, 0, 0 }, 0.9f);
for (int i = 0; i < performance_iterations; i++)
{
Canvas::I->stroke_update({ 100, 100, 0 }, 0.9f);
Canvas::I->stroke_update({ 200, 200, 0 }, 0.9f);
Canvas::I->stroke_update({ 200, 100, 0 }, 0.9f);
Canvas::I->stroke_update({ 100, 200, 0 }, 0.9f);
Canvas::I->stroke_update({ 300, 300, 0 }, 0.9f);
Canvas::I->stroke_update({ 200, 500, 0 }, 0.9f);
Canvas::I->stroke_update({ 500, 500, 0 }, 0.9f);
Canvas::I->stroke_update({ 400, 400, 0 }, 0.9f);
Canvas::I->stroke_update({ 0, 200, 0 }, 0.9f);
Canvas::I->stroke_update({ 200, 0, 0 }, 0.9f);
Canvas::I->stroke_draw();
}
Canvas::I->stroke_end();
auto diff = std::chrono::high_resolution_clock::now() - start;
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(diff).count();
LOG("%lld ms", ms);
message = "Time " + std::to_string(ms) + " ms";
});
message_box("Performance test", message);
}
execute_about_menu_plan(*this, plan);
if (plan.closes_root_popup)
{
popup->mouse_release();