add pre/post install message options for github json

This commit is contained in:
ITotalJustice
2024-12-31 04:41:19 +00:00
parent e452615c77
commit bc39e668eb
3 changed files with 47 additions and 8 deletions

View File

@@ -11,12 +11,16 @@ namespace sphaira::ui::menu::gh {
struct AssetEntry { struct AssetEntry {
std::string name; std::string name;
std::string path; std::string path;
std::string pre_install_message;
std::string post_install_message;
}; };
struct Entry { struct Entry {
fs::FsPath json_path; fs::FsPath json_path;
std::string owner; std::string owner;
std::string repo; std::string repo;
std::string pre_install_message;
std::string post_install_message;
std::vector<AssetEntry> assets; std::vector<AssetEntry> assets;
}; };

View File

@@ -33,7 +33,7 @@ public:
using Options = std::vector<Option>; using Options = std::vector<Option>;
public: public:
OptionBox(const std::string& message, const Option& a, Callback cb); // confirm OptionBox(const std::string& message, const Option& a, Callback cb = [](auto){}); // confirm
OptionBox(const std::string& message, const Option& a, const Option& b, Callback cb); // yesno OptionBox(const std::string& message, const Option& a, const Option& b, Callback cb); // yesno
OptionBox(const std::string& message, const Option& a, const Option& b, std::size_t index, Callback cb); // yesno OptionBox(const std::string& message, const Option& a, const Option& b, std::size_t index, Callback cb); // yesno
OptionBox(const std::string& message, const Option& a, const Option& b, const Option& c, Callback cb); // tri OptionBox(const std::string& message, const Option& a, const Option& b, const Option& c, Callback cb); // tri

View File

@@ -40,6 +40,8 @@ void from_json(yyjson_val* json, AssetEntry& e) {
JSON_OBJ_ITR( JSON_OBJ_ITR(
JSON_SET_STR(name); JSON_SET_STR(name);
JSON_SET_STR(path); JSON_SET_STR(path);
JSON_SET_STR(pre_install_message);
JSON_SET_STR(post_install_message);
); );
} }
@@ -48,6 +50,8 @@ void from_json(const fs::FsPath& path, Entry& e) {
JSON_OBJ_ITR( JSON_OBJ_ITR(
JSON_SET_STR(owner); JSON_SET_STR(owner);
JSON_SET_STR(repo); JSON_SET_STR(repo);
JSON_SET_STR(pre_install_message);
JSON_SET_STR(post_install_message);
JSON_SET_ARR_OBJ(assets); JSON_SET_ARR_OBJ(assets);
); );
} }
@@ -302,17 +306,44 @@ Menu::Menu() : MenuBase{"GitHub"_i18n} {
const auto index = *op_index; const auto index = *op_index;
const auto& asset_entry = api_assets[index]; const auto& asset_entry = api_assets[index];
const AssetEntry* ptr{}; const AssetEntry* ptr{};
auto pre_install_message = GetEntry().pre_install_message;
if (asset_ptr.size()) { if (asset_ptr.size()) {
ptr = asset_ptr[index]; ptr = asset_ptr[index];
if (!ptr->pre_install_message.empty()) {
pre_install_message = ptr->pre_install_message;
}
} }
const auto func = [this, &asset_entry, ptr](){
App::Push(std::make_shared<ProgressBox>("Downloading "_i18n + GetEntry().repo, [this, &asset_entry, ptr](auto pbox){ App::Push(std::make_shared<ProgressBox>("Downloading "_i18n + GetEntry().repo, [this, &asset_entry, ptr](auto pbox){
return DownloadApp(pbox, asset_entry, ptr); return DownloadApp(pbox, asset_entry, ptr);
}, [this](bool success){ }, [this, ptr](bool success){
if (success) { if (success) {
App::Notify("Downloaded "_i18n + GetEntry().repo); App::Notify("Downloaded "_i18n + GetEntry().repo);
auto post_install_message = GetEntry().post_install_message;
if (ptr && !ptr->post_install_message.empty()) {
post_install_message = ptr->post_install_message;
}
if (!post_install_message.empty()) {
App::Push(std::make_shared<OptionBox>(post_install_message, "OK"_i18n));
}
} }
}, 2)); }, 2));
};
if (!pre_install_message.empty()) {
App::Push(std::make_shared<OptionBox>(
pre_install_message,
"Back"_i18n, "Donwload"_i18n, 1, [this, func](auto op_index){
if (op_index && *op_index) {
func();
}
}
));
} else {
func();
}
})); }));
} }
}, 2)); }, 2));
@@ -464,6 +495,10 @@ void Menu::LoadEntriesFromPath(const fs::FsPath& path) {
continue; continue;
} }
for (auto& p : entry.assets) {
}
entry.json_path = full_path; entry.json_path = full_path;
m_entries.emplace_back(entry); m_entries.emplace_back(entry);
} }