Skip to content

Commit 26627a0

Browse files
committed
Ui: Add telemetry code
1 parent a48c25a commit 26627a0

File tree

10 files changed

+292
-150
lines changed

10 files changed

+292
-150
lines changed

QUsb2snes.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ DEFINES += GIT_TAG_VERSION=\\\"$$GIT_TAG_VERSION\\\"
1515
UISOURCES = ui/appui.cpp \
1616
ui/appuimenu.cpp \
1717
ui/appuipoptracker.cpp \
18+
ui/appuiupdate.cpp \
1819
ui/diagnosticdialog.cpp \
1920
ui/systraywidget.cpp \
2021
ui/wizard/deviceselectorpage.cpp \

QUsb2snes.qbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Project {
1919
"ui/appuimenu.cpp",
2020
"ui/appui.h",
2121
"ui/appuipoptracker.cpp",
22+
"ui/appuiupdate.cpp",
2223
"ui/systraywidget.cpp",
2324
"ui/systraywidget.h",
2425
"ui/systraywidget.ui",

ui/appui.cpp

Lines changed: 5 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ void AppUi::init()
186186
emuNWAccessAction->setChecked(true);
187187
onEmuNWAccessTriggered(true);
188188
}
189+
if (wiz.sendTelemetry())
190+
{
191+
postTelemetryData();
192+
}
193+
globalSettings->setValue("telemetrydatahandled", true);
189194
}
190195
}
191196
setMenu();
@@ -281,14 +286,6 @@ void AppUi::startWServer()
281286
}
282287

283288

284-
void AppUi::updated(QString fromVersion)
285-
{
286-
QMessageBox::about(nullptr, tr("QUsb2Snes updated succesfully"),
287-
QString(tr("QUsb2Snes successfully updated from %1 to version %2")).arg(fromVersion).arg(qApp->applicationVersion()));
288-
}
289-
290-
291-
292289
AppUi::ApplicationInfo AppUi::parseJsonAppInfo(QString fileName)
293290
{
294291
ApplicationInfo info;
@@ -323,70 +320,6 @@ AppUi::ApplicationInfo AppUi::parseJsonAppInfo(QString fileName)
323320
return info;
324321
}
325322

326-
void AppUi::checkForNewVersion(bool manual)
327-
{
328-
sInfo() << "Checking for new version - SSL support is : " << QSslSocket::supportsSsl() << QSslSocket::sslLibraryBuildVersionString();
329-
if (!QSslSocket::supportsSsl())
330-
return;
331-
QNetworkAccessManager* manager = new QNetworkAccessManager();
332-
QObject::connect(manager, &QNetworkAccessManager::finished, this, [=](QNetworkReply* reply)
333-
{
334-
sDebug() << "Finished" << reply->size();
335-
QByteArray data = reply->readAll();
336-
QJsonDocument doc = QJsonDocument::fromJson(data);
337-
QJsonArray jArr = doc.array();
338-
QString lastTag = jArr.at(0).toObject().value("tag_name").toString();
339-
QString body = jArr.at(0).toObject().value("body").toString();
340-
QString name = jArr.at(0).toObject().value("name").toString();
341-
sInfo() << "Latest release is " << lastTag;
342-
sDebug() << body;
343-
body.replace('\n', "<br/>");
344-
body.replace('\r', "");
345-
346-
if (QVersionNumber::fromString(qApp->applicationVersion()) < QVersionNumber::fromString(lastTag.remove(0, 1)))
347-
{
348-
QMessageBox msg;
349-
msg.setText(QString(tr("A new version of QUsb2Snes is available : QUsb2Snes %1\nDo you want to upgrade to it?")).arg(lastTag));
350-
msg.setWindowTitle(tr("New version of QUsb2Snes available"));
351-
msg.setInformativeText(QString("<b>%1</b><p>%2</p>").arg(name).arg(body));
352-
msg.addButton(QMessageBox::Yes);
353-
msg.addButton(QMessageBox::No);
354-
msg.setDefaultButton(QMessageBox::No);
355-
int but = msg.exec();
356-
if (but == QMessageBox::Yes)
357-
{
358-
if (dlManager == nullptr)
359-
{
360-
dlManager = new QNetworkAccessManager();
361-
dlManager->setRedirectPolicy(QNetworkRequest::NoLessSafeRedirectPolicy);
362-
QObject::connect(dlManager, &QNetworkAccessManager::finished, this, &AppUi::DLManagerRequestFinished);
363-
dlLabel = new QLabel();
364-
dlProgressBar = new QProgressBar();
365-
dlProgressBar->setTextVisible(false);
366-
dlLabel->setText(tr("Downloading the Windows Updater"));
367-
dlWindow = new QWidget();
368-
QVBoxLayout* layout = new QVBoxLayout();
369-
dlWindow->setWindowTitle("Updating Updater");
370-
dlWindow->setWindowIcon(QIcon(":/icon64x64.ico"));
371-
dlWindow->setLayout(layout);
372-
layout->addWidget(dlLabel);
373-
layout->addWidget(dlProgressBar);
374-
}
375-
dlWindow->show();
376-
dlManager->get(QNetworkRequest(QUrl("https://api.github.com/repos/Skarsnik/QUsb2Snes/releases")));
377-
//QString upExe(qApp->applicationDirPath() + "/WinUpdater.exe");
378-
//(int)::ShellExecute(0, reinterpret_cast<const WCHAR*>("runas"), reinterpret_cast<const WCHAR*>(upExe.utf16()), 0, 0, SW_SHOWNORMAL);
379-
//QProcess::startDetached(upExe);
380-
//qApp->exit(0);
381-
}
382-
} else {
383-
if (manual)
384-
QMessageBox::information(nullptr, tr("No new version of QUsb2Snes available"), tr("No new version of QUsb2Snes available"));
385-
}
386-
});
387-
manager->get(QNetworkRequest(QUrl("https://api.github.com/repos/Skarsnik/QUsb2snes/releases")));
388-
sDebug() << "Get";
389-
}
390323

391324
void AppUi::checkForApplications()
392325
{
@@ -610,67 +543,6 @@ void AppUi::onEmuNWAccessTriggered(bool checked)
610543

611544

612545

613-
// Code to download the updater
614-
615-
void AppUi::DLManagerRequestFinished(QNetworkReply* reply)
616-
{
617-
static int step = 0;
618-
619-
QByteArray data = reply->readAll();
620-
qDebug() << reply->error();
621-
if (step == 0)
622-
{
623-
QJsonDocument doc = QJsonDocument::fromJson(data);
624-
QJsonArray jArr = doc.array();
625-
QJsonArray assets = jArr.at(0).toObject().value("assets").toArray();
626-
foreach(const QJsonValue& value, assets)
627-
{
628-
if (value.toObject().value("name").toString() == "WinUpdater.exe")
629-
{
630-
sDebug() << "Downloading " << value.toObject().value("browser_download_url").toString();
631-
dlLabel->setText(QString(QObject::tr("Downloading new WinUpdater %1")).arg(
632-
jArr.at(0).toObject().value("tag_name").toString()));
633-
QNetworkRequest req(QUrl(value.toObject().value("browser_download_url").toString()));
634-
req.setRawHeader("Accept", "application/octet-stream");
635-
QNetworkReply* dlReply = dlManager->get(req);
636-
QObject::connect(dlReply, &QNetworkReply::redirected, [=] {
637-
sDebug() << "DL reply redirected";
638-
});
639-
QObject::connect(dlReply, &QNetworkReply::downloadProgress, this, [=](qint64 bytesRcv, qint64 bytesTotal)
640-
{
641-
qDebug() << 20 + (bytesRcv / bytesTotal) * 80;
642-
dlProgressBar->setValue(20 + (bytesRcv / bytesTotal) * 80);
643-
});
644-
sDebug() << "Found WinUpdater.exe asset";
645-
step = 1;
646-
return ;
647-
}
648-
}
649-
qApp->exit(1);
650-
}
651-
if (step == 1)
652-
{
653-
QFile file(qApp->applicationDirPath() + "/WinUpdater.exe");
654-
655-
step = 0;
656-
dlProgressBar->setValue(100);
657-
dlLabel->setText(QObject::tr("Writing WinUpdater.exe"));
658-
if (file.open(QIODevice::WriteOnly))
659-
{
660-
sDebug() << data.size();
661-
file.write(data);
662-
sDebug() << "WinUpdater written";
663-
file.flush();
664-
file.close();
665-
dlLabel->setText(QObject::tr("Starting the Windows Updater"));
666-
QProcess::startDetached(qApp->applicationDirPath() + "/WinUpdater.exe");
667-
QTimer::singleShot(200, this, [=] {qApp->exit(0);});
668-
} else {
669-
dlWindow->hide();
670-
QMessageBox::warning(nullptr, tr("Error downloading the updater"), tr("There was an error downloading or writing the updater file, please try to download it manually on the release page"));
671-
}
672-
}
673-
}
674546

675547

676548

ui/appui.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ private slots:
126126
void addDevicesInfo(DeviceFactory *devFact);
127127
ApplicationInfo parseJsonAppInfo(QString fileName);
128128
void checkForNewVersion(bool manual = false);
129+
void postTelemetryData();
129130
void startWServer();
130131
void addSD2SnesFactory();
131132
void addRetroarchFactory();
@@ -135,9 +136,11 @@ private slots:
135136
void setLinuxDeviceMenu();
136137
void setMenu();
137138
void setDeviceEntry(const QString str);
139+
138140
QList<PopTrackerPackInfo> poptrackerScanPack();
139141
bool checkPopTracker();
140142
void addPopTrackerMenu();
143+
void initDLManager();
141144
};
142145

143146
#endif // APPUI_H

0 commit comments

Comments
 (0)