- Add Proof of Concept (PoC) for executing JavaScript scripts fetched remotely. - Integrate `Black::GetProfileInfoScript` logic into a JS version with fallback to C++ on errors. - Extend `ScreenXmlParser` with additional JS-to-C++ bridge methods. - Update `config.ini` for scripting configuration. - Ensure scripts are securely fetched with SHA-256 validation and use an atomic caching mechanism. - Add developer tools for debugging JS scripts and enable easier script updates without app re-deployment.
60 lines
1.5 KiB
C++
60 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include <QObject>
|
|
#include <QString>
|
|
|
|
class QNetworkAccessManager;
|
|
class QNetworkReply;
|
|
|
|
namespace Scripting {
|
|
|
|
// Опрашивает /scripts/manifest, скачивает обновлённые скрипты,
|
|
// сверяет SHA-256 и кладёт их в ScriptCache (атомарно).
|
|
//
|
|
// Manifest формат (JSON):
|
|
// {
|
|
// "scripts": [
|
|
// { "bank": "black", "script": "get_profile_info",
|
|
// "version": "1.0.0", "url": "...", "sha256": "<hex>" },
|
|
// ...
|
|
// ]
|
|
// }
|
|
//
|
|
// Поведение fallback: если что-то пошло не так (сеть, hash mismatch),
|
|
// в кэше остаётся ПРЕДЫДУЩИЙ скрипт; если кэш пуст — runtime возьмёт bundled.
|
|
class ScriptUpdater final : public QObject {
|
|
Q_OBJECT
|
|
public:
|
|
explicit ScriptUpdater(QObject *parent = nullptr);
|
|
~ScriptUpdater() override;
|
|
|
|
public slots:
|
|
// Запускает разовое обновление. Вызывать после успешной авторизации.
|
|
void start();
|
|
|
|
signals:
|
|
void finished();
|
|
|
|
private slots:
|
|
void onManifestReply();
|
|
void onScriptReply();
|
|
|
|
private:
|
|
void downloadNext();
|
|
void scheduleFinish();
|
|
|
|
struct ScriptItem {
|
|
QString bank;
|
|
QString script;
|
|
QString version;
|
|
QString url;
|
|
QString sha256;
|
|
};
|
|
|
|
QNetworkAccessManager *m_net;
|
|
QList<ScriptItem> m_queue;
|
|
int m_inFlight = 0;
|
|
};
|
|
|
|
} // namespace Scripting
|