1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00

keep screen on

This commit is contained in:
Laserlicht
2025-08-31 14:02:19 +02:00
parent 759f207d8a
commit 2048806753
4 changed files with 35 additions and 0 deletions

View File

@@ -443,10 +443,12 @@ void FirstLaunchView::extractGogDataAsync(QString filePathBin, QString filePathE
if(errorText.isEmpty())
{
logGlobal->info("Performing extraction using innoextract...");
Helper::keepScreenOn(true);
errorText = Innoextract::extract(tmpFileExe, tempDir.path(), [this](float progress) {
ui->progressBarGog->setValue(progress * 100);
qApp->processEvents();
});
Helper::keepScreenOn(false);
logGlobal->info("Extraction done!");
}

View File

@@ -22,6 +22,7 @@
#ifdef VCMI_ANDROID
#include <QAndroidJniObject>
#include <QtAndroid>
#include <QAndroidJniEnvironment>
#endif
#ifdef VCMI_IOS
@@ -114,4 +115,32 @@ MainWindow * getMainWindow()
return mainWin;
return nullptr;
}
void keepScreenOn(bool on)
{
#if defined(VCMI_ANDROID)
// based on https://stackoverflow.com/a/38846485
QtAndroid::runOnAndroidThread([on]
{
QAndroidJniObject activity = QtAndroid::androidActivity();
if(activity.isValid())
{
QAndroidJniObject window = activity.callObjectMethod("getWindow", "()Landroid/view/Window;");
if(window.isValid())
{
const int FLAG_KEEP_SCREEN_ON = 128;
if(on)
window.callMethod<void>("addFlags", "(I)V", FLAG_KEEP_SCREEN_ON);
else
window.callMethod<void>("clearFlags", "(I)V", FLAG_KEEP_SCREEN_ON);
}
}
QAndroidJniEnvironment env;
if (env->ExceptionCheck())
env->ExceptionClear();
});
#endif
}
}

View File

@@ -23,4 +23,5 @@ QString getRealPath(QString path);
void performNativeCopy(QString src, QString dst);
void revealDirectoryInFileBrowser(QString path);
MainWindow * getMainWindow();
void keepScreenOn(bool on);
}

View File

@@ -798,6 +798,7 @@ void CModListView::downloadFile(QString file, QUrl url, QString description, qin
void CModListView::downloadProgress(qint64 current, qint64 max)
{
Helper::keepScreenOn(true);
// display progress, in megabytes
ui->progressBar->setVisible(true);
ui->progressBar->setMaximum(max / (1024 * 1024));
@@ -806,6 +807,7 @@ void CModListView::downloadProgress(qint64 current, qint64 max)
void CModListView::extractionProgress(qint64 current, qint64 max)
{
Helper::keepScreenOn(true);
// display progress, in extracted files
ui->progressBar->setVisible(true);
ui->progressBar->setMaximum(max);
@@ -857,6 +859,7 @@ void CModListView::downloadFinished(QStringList savedFiles, QStringList failedFi
void CModListView::hideProgressBar()
{
Helper::keepScreenOn(false);
if(dlManager == nullptr) // it was not recreated meanwhile
{
ui->progressWidget->setVisible(false);