2026-08-27 19:35:11 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "javaruntime.h"
|
|
|
|
|
|
|
|
|
|
#include <QDateTime>
|
|
|
|
|
#include <QHash>
|
|
|
|
|
#include <QList>
|
|
|
|
|
#include <QObject>
|
|
|
|
|
#include <QSet>
|
|
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
|
|
class QNetworkAccessManager;
|
|
|
|
|
|
|
|
|
|
class JavaRuntimeService : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
using Callback = std::function<void(bool ok, const QString &warning)>;
|
|
|
|
|
|
|
|
|
|
explicit JavaRuntimeService(QObject *parent = nullptr);
|
|
|
|
|
|
|
|
|
|
void ensureLoaded(Callback callback, bool forceRefresh = false);
|
|
|
|
|
|
|
|
|
|
QList<JavaRuntimeEntry> entries(JavaRuntimeKind kind) const;
|
|
|
|
|
std::optional<JavaRuntimeEntry> find(const QString &id) const;
|
2026-08-31 00:59:14 +03:00
|
|
|
std::optional<JavaRuntimeEntry> bestFor(int major) const;
|
|
|
|
|
|
2026-08-27 19:35:11 +03:00
|
|
|
bool isRefreshing() const { return m_outstanding > 0; }
|
|
|
|
|
bool hasData() const { return !m_entries.isEmpty(); }
|
|
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
void catalogChanged();
|
|
|
|
|
void refreshingChanged();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void startRefresh();
|
|
|
|
|
void requestAdoptiumReleases();
|
|
|
|
|
void requestFeatureRelease(int major, const QString &architecture, bool allowFallback);
|
|
|
|
|
void requestMojangRuntimes();
|
|
|
|
|
|
|
|
|
|
void requestFinished(const QString &warning);
|
|
|
|
|
void finishRefresh();
|
|
|
|
|
|
|
|
|
|
static QList<JavaRuntimeEntry> parseAdoptium(const QByteArray &payload,
|
|
|
|
|
const QSet<int> <sVersions);
|
|
|
|
|
static QList<JavaRuntimeEntry> parseMojang(const QByteArray &payload);
|
|
|
|
|
|
|
|
|
|
void applyEntries(QList<JavaRuntimeEntry> list);
|
|
|
|
|
bool readCache();
|
|
|
|
|
void writeCache();
|
|
|
|
|
|
|
|
|
|
QNetworkAccessManager *m_network;
|
|
|
|
|
|
|
|
|
|
QList<JavaRuntimeEntry> m_entries;
|
|
|
|
|
QHash<QString, int> m_indexById;
|
|
|
|
|
QDateTime m_fetchedAt;
|
|
|
|
|
bool m_cacheRead = false;
|
|
|
|
|
|
|
|
|
|
QList<JavaRuntimeEntry> m_incoming;
|
|
|
|
|
QStringList m_warnings;
|
|
|
|
|
QSet<int> m_ltsVersions;
|
|
|
|
|
int m_outstanding = 0;
|
|
|
|
|
|
|
|
|
|
QList<Callback> m_pending;
|
|
|
|
|
};
|