mirror of
https://github.com/RPCSX/ELP-Launcher.git
synced 2024-11-26 21:10:31 +00:00
fix error dialog
fix passing params more informative alternative selector dialog fix alternative selection
This commit is contained in:
parent
d433f5a199
commit
e9e53ec777
@ -62,10 +62,10 @@ std::error_code AlternativeGroup::activate(Context &context) {
|
||||
}
|
||||
|
||||
MethodCallResult resolverResponse;
|
||||
if (context.showView("alternative-resolver",
|
||||
{{"alternatives", alternatives}}, &resolverResponse,
|
||||
false)) {
|
||||
return std::make_error_code(std::errc::no_such_file_or_directory);
|
||||
if (auto ec = context.showView("alternative-resolver",
|
||||
{{"alternatives", alternatives}},
|
||||
&resolverResponse, false)) {
|
||||
return ec;
|
||||
}
|
||||
|
||||
selected = candidates[resolverResponse.get<std::size_t>()];
|
||||
|
@ -85,6 +85,7 @@ std::shared_ptr<Alternative> AlternativeStorage::findAlternativeOrResolve(
|
||||
{"alternatives", alternatives},
|
||||
{"requirements", requirements},
|
||||
{"groupId", name},
|
||||
{"kind", kind},
|
||||
},
|
||||
&response, false)) {
|
||||
return {};
|
||||
@ -92,12 +93,16 @@ std::shared_ptr<Alternative> AlternativeStorage::findAlternativeOrResolve(
|
||||
|
||||
if (response.is_number_integer()) {
|
||||
auto index = response.get<int>();
|
||||
if (index >= 0 && index < result.size()) {
|
||||
return result[index];
|
||||
}
|
||||
}
|
||||
if (index >= 0) {
|
||||
if (index < result.size()) {
|
||||
return result[index];
|
||||
}
|
||||
|
||||
return findAlternative(name, requirements);
|
||||
return findAlternativeOrResolve(context, name, requirements);
|
||||
}
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
if (context.showView("packages",
|
||||
@ -110,7 +115,7 @@ std::shared_ptr<Alternative> AlternativeStorage::findAlternativeOrResolve(
|
||||
return {};
|
||||
}
|
||||
|
||||
return findAlternative(name, requirements);
|
||||
return findAlternativeOrResolve(context, name, requirements);
|
||||
}
|
||||
|
||||
std::shared_ptr<Alternative>
|
||||
|
@ -10,6 +10,8 @@
|
||||
#include <vector>
|
||||
|
||||
struct AlternativeStorage {
|
||||
std::string kind;
|
||||
|
||||
std::map<std::string, std::shared_ptr<AlternativeGroup>, std::less<>>
|
||||
alternativeGroups;
|
||||
|
||||
|
@ -25,6 +25,12 @@ splitOnce(std::string_view string, char separator) {
|
||||
return {string.substr(0, pos), string.substr(pos + 1)};
|
||||
}
|
||||
|
||||
Context::Context() {
|
||||
kind = "components";
|
||||
views.kind = "views";
|
||||
methods.kind = "methods";
|
||||
}
|
||||
|
||||
void Context::addAlternative(std::shared_ptr<Alternative> alternative) {
|
||||
auto altId = alternative->manifest().id();
|
||||
if (auto [it, inserted] = allAlternatives.try_emplace(altId, alternative);
|
||||
@ -46,8 +52,8 @@ void Context::addAlternative(std::shared_ptr<Alternative> alternative) {
|
||||
}
|
||||
|
||||
for (auto &ext : alternative->manifest().contributes.methods) {
|
||||
methodHandlers.addAlternativeGroup(ext, "");
|
||||
methodHandlers.addAlternativeToGroup(ext, alternative);
|
||||
methods.addAlternativeGroup(ext, "");
|
||||
methods.addAlternativeToGroup(ext, alternative);
|
||||
}
|
||||
|
||||
for (auto &ext : alternative->manifest().contributes.views) {
|
||||
@ -56,6 +62,22 @@ void Context::addAlternative(std::shared_ptr<Alternative> alternative) {
|
||||
}
|
||||
}
|
||||
|
||||
void Context::selectAlternative(std::string_view kind, std::string_view groupId, std::shared_ptr<Alternative> alternative) {
|
||||
if (kind == this->kind) {
|
||||
AlternativeStorage::selectAlternative(groupId, std::move(alternative));
|
||||
return;
|
||||
}
|
||||
if (kind == views.kind) {
|
||||
views.selectAlternative(groupId, std::move(alternative));
|
||||
return;
|
||||
}
|
||||
if (kind == methods.kind) {
|
||||
methods.selectAlternative(groupId, std::move(alternative));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::error_code Context::showView(std::string_view name, MethodCallArgs args,
|
||||
MethodCallResult *response, bool tryResolve) {
|
||||
std::shared_ptr<Alternative> alt;
|
||||
@ -73,8 +95,12 @@ std::error_code Context::showView(std::string_view name, MethodCallArgs args,
|
||||
}
|
||||
|
||||
alt->callMethod(*this, "view/show",
|
||||
{{"id", name}, {"args", std::move(args)}},
|
||||
createShowErrorFn());
|
||||
{{"id", name}, {"params", std::move(args)}},
|
||||
createShowErrorFn([=](const MethodCallResult &result) {
|
||||
if (response != nullptr) {
|
||||
*response = result;
|
||||
}
|
||||
}));
|
||||
return {};
|
||||
}
|
||||
|
||||
@ -120,7 +146,7 @@ void Context::callMethod(
|
||||
std::string_view name, const AlternativeRequirements &requirements,
|
||||
const MethodCallArgs &args,
|
||||
std::move_only_function<void(const MethodCallResult &)> responseHandler) {
|
||||
if (auto alternative = methodHandlers.findAlternative(name, requirements)) {
|
||||
if (auto alternative = methods.findAlternative(name, requirements)) {
|
||||
alternative->callMethod(*this, name, args, std::move(responseHandler));
|
||||
} else {
|
||||
responseHandler({{"error", elp::ErrorCode::MethodNotFound}});
|
||||
|
@ -39,7 +39,7 @@ struct Context : AlternativeStorage {
|
||||
Settings settings;
|
||||
std::mutex mutex;
|
||||
|
||||
AlternativeStorage methodHandlers;
|
||||
AlternativeStorage methods;
|
||||
AlternativeStorage views;
|
||||
|
||||
std::set<std::shared_ptr<Alternative>> activeList;
|
||||
@ -49,7 +49,11 @@ struct Context : AlternativeStorage {
|
||||
std::less<>>
|
||||
notificationHandlers;
|
||||
|
||||
Context();
|
||||
|
||||
void addAlternative(std::shared_ptr<Alternative> alternative);
|
||||
void selectAlternative(std::string_view kind, std::string_view groupId,
|
||||
std::shared_ptr<Alternative> alternative);
|
||||
|
||||
std::error_code showView(std::string_view name, MethodCallArgs args = {},
|
||||
MethodCallResult *response = nullptr,
|
||||
|
24
src/main.cpp
24
src/main.cpp
@ -191,7 +191,6 @@ static void showAlternativeResolverDialog(
|
||||
|
||||
auto dialog = new QDialog(nullptr);
|
||||
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||
dialog->setWindowTitle(QString::fromStdString("Select alternative"));
|
||||
dialog->setLayout(new QVBoxLayout(dialog));
|
||||
dialog->layout()->setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
||||
auto list = new QListView(dialog);
|
||||
@ -206,6 +205,11 @@ static void showAlternativeResolverDialog(
|
||||
|
||||
if (!args.contains("groupId")) {
|
||||
alwaysUse->hide();
|
||||
dialog->setWindowTitle(QString::fromStdString("Select alternative"));
|
||||
} else {
|
||||
dialog->setWindowTitle(QString::fromStdString(
|
||||
"Select alternative for " + args["kind"].get<std::string>() +
|
||||
"::" + args["groupId"].get<std::string>()));
|
||||
}
|
||||
|
||||
auto requirements = args["requirements"].get<AlternativeRequirements>();
|
||||
@ -230,6 +234,7 @@ static void showAlternativeResolverDialog(
|
||||
|
||||
if (alwaysUse->isChecked()) {
|
||||
context.selectAlternative(
|
||||
args["kind"].get<std::string>(),
|
||||
args["groupId"].get<std::string>(),
|
||||
context.findAlternative(alternatives[index.row()].id()));
|
||||
}
|
||||
@ -733,19 +738,17 @@ static QWidget *createMainWidget(Context &context) {
|
||||
widget->resize(800, 600);
|
||||
widget->hide();
|
||||
|
||||
widget->show();
|
||||
widget->setFocus();
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
struct BuiltinAlternatives final : public Alternative {
|
||||
QWidget *mainWidget;
|
||||
BuiltinAlternatives(Context &context)
|
||||
: Alternative(Manifest{.name = "Built-in alternatives",
|
||||
.contributes{.views = {"main", "package-sources",
|
||||
"alternative-resolver",
|
||||
"packages", "devices"}}}) {}
|
||||
: Alternative(
|
||||
Manifest{.name = "Built-in alternatives",
|
||||
.contributes{.views = {"main", "package-sources",
|
||||
"alternative-resolver", "packages",
|
||||
"devices", "error"}}}) {}
|
||||
|
||||
std::error_code activate(Context &context) override {
|
||||
mainWidget = createMainWidget(context);
|
||||
@ -795,6 +798,11 @@ struct BuiltinAlternatives final : public Alternative {
|
||||
return;
|
||||
}
|
||||
|
||||
if (id == "error") {
|
||||
showErrorDialog(context, args["params"], std::move(responseHandler));
|
||||
return;
|
||||
}
|
||||
|
||||
responseHandler({{"error", elp::ErrorCode::InvalidParam}});
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user