Even more fixes

Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
TheKodeToad 2022-11-02 09:59:52 +00:00
parent a1ed8154f7
commit a29d88c313

View File

@ -254,19 +254,20 @@ void ModPage::openUrl(const QUrl& url)
} }
// detect mod URLs and search instead // detect mod URLs and search instead
int prefixLength; int prefixLength = 0;
const char* page; const char* page;
if ((url.host() == "modrinth.com" || url.host() == "www.modrinth.com") && url.path().startsWith("/mod/")) { if ((url.host() == "modrinth.com" || url.host() == "www.modrinth.com") && url.path().startsWith("/mod/")) {
prefixLength = 5; prefixLength = 5;
page = "modrinth"; page = "modrinth";
} else if (APPLICATION->capabilities() & Application::SupportsFlame && } else if (APPLICATION->capabilities() & Application::SupportsFlame &&
(url.host() == "curseforge.com" || url.host() == "www.curseforge.com") && (url.host() == "curseforge.com" || url.host().endsWith(".curseforge.com"))) {
url.path().toLower().startsWith("/minecraft/mc-mods/")) { if (url.path().toLower().startsWith("/minecraft/mc-mods/"))
prefixLength = 19; prefixLength = 19;
else if (url.path().toLower().startsWith("/projects/"))
prefixLength = 10;
page = "curseforge"; page = "curseforge";
} else }
prefixLength = 0;
if (prefixLength != 0) { if (prefixLength != 0) {
QString slug = url.path().mid(prefixLength); QString slug = url.path().mid(prefixLength);
@ -282,31 +283,36 @@ void ModPage::openUrl(const QUrl& url)
dialog->selectPage(page); dialog->selectPage(page);
ModPage* newPage = dialog->getSelectedPage(); ModPage* newPage = dialog->getSelectedPage();
QLineEdit* searchEdit = newPage->ui->searchEdit; QLineEdit* searchEdit = newPage->ui->searchEdit;
ModPlatform::ListModel* model = newPage->listModel;
QListView* view = newPage->ui->packView;
if (searchEdit->text() != slug) { auto jump = [url, slug, model, view] {
searchEdit->setText(slug); for (int row = 0; row < model->rowCount({}); row++) {
newPage->triggerSearch(); QModelIndex index = model->index(row);
auto pack = model->data(index, Qt::UserRole).value<ModPlatform::IndexedPack>();
ModPlatform::ListModel* model = newPage->listModel; if (pack.slug == slug) {
QListView* view = newPage->ui->packView; view->setCurrentIndex(index);
return;
connect(model->activeJob(), &Task::finished, [url, slug, model, view] {
for (int row = 0; row < model->rowCount({}); row++) {
QModelIndex index = model->index(row);
auto pack = model->data(index, Qt::UserRole).value<ModPlatform::IndexedPack>();
if (pack.slug == slug) {
view->setCurrentIndex(index);
return;
}
} }
}
// The final fallback. // The final fallback.
QDesktopServices::openUrl(url); QDesktopServices::openUrl(url);
}); };
return; searchEdit->setText(slug);
newPage->triggerSearch();
if (!model->activeJob())
jump();
else {
connect(model->activeJob(), &Task::finished, jump);
} }
return;
} }
} }