mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
keep screen on
This commit is contained in:
@@ -443,10 +443,12 @@ void FirstLaunchView::extractGogDataAsync(QString filePathBin, QString filePathE
|
|||||||
if(errorText.isEmpty())
|
if(errorText.isEmpty())
|
||||||
{
|
{
|
||||||
logGlobal->info("Performing extraction using innoextract...");
|
logGlobal->info("Performing extraction using innoextract...");
|
||||||
|
Helper::keepScreenOn(true);
|
||||||
errorText = Innoextract::extract(tmpFileExe, tempDir.path(), [this](float progress) {
|
errorText = Innoextract::extract(tmpFileExe, tempDir.path(), [this](float progress) {
|
||||||
ui->progressBarGog->setValue(progress * 100);
|
ui->progressBarGog->setValue(progress * 100);
|
||||||
qApp->processEvents();
|
qApp->processEvents();
|
||||||
});
|
});
|
||||||
|
Helper::keepScreenOn(false);
|
||||||
logGlobal->info("Extraction done!");
|
logGlobal->info("Extraction done!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#ifdef VCMI_ANDROID
|
#ifdef VCMI_ANDROID
|
||||||
#include <QAndroidJniObject>
|
#include <QAndroidJniObject>
|
||||||
#include <QtAndroid>
|
#include <QtAndroid>
|
||||||
|
#include <QAndroidJniEnvironment>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef VCMI_IOS
|
#ifdef VCMI_IOS
|
||||||
@@ -114,4 +115,32 @@ MainWindow * getMainWindow()
|
|||||||
return mainWin;
|
return mainWin;
|
||||||
return nullptr;
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,4 +23,5 @@ QString getRealPath(QString path);
|
|||||||
void performNativeCopy(QString src, QString dst);
|
void performNativeCopy(QString src, QString dst);
|
||||||
void revealDirectoryInFileBrowser(QString path);
|
void revealDirectoryInFileBrowser(QString path);
|
||||||
MainWindow * getMainWindow();
|
MainWindow * getMainWindow();
|
||||||
|
void keepScreenOn(bool on);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -798,6 +798,7 @@ void CModListView::downloadFile(QString file, QUrl url, QString description, qin
|
|||||||
|
|
||||||
void CModListView::downloadProgress(qint64 current, qint64 max)
|
void CModListView::downloadProgress(qint64 current, qint64 max)
|
||||||
{
|
{
|
||||||
|
Helper::keepScreenOn(true);
|
||||||
// display progress, in megabytes
|
// display progress, in megabytes
|
||||||
ui->progressBar->setVisible(true);
|
ui->progressBar->setVisible(true);
|
||||||
ui->progressBar->setMaximum(max / (1024 * 1024));
|
ui->progressBar->setMaximum(max / (1024 * 1024));
|
||||||
@@ -806,6 +807,7 @@ void CModListView::downloadProgress(qint64 current, qint64 max)
|
|||||||
|
|
||||||
void CModListView::extractionProgress(qint64 current, qint64 max)
|
void CModListView::extractionProgress(qint64 current, qint64 max)
|
||||||
{
|
{
|
||||||
|
Helper::keepScreenOn(true);
|
||||||
// display progress, in extracted files
|
// display progress, in extracted files
|
||||||
ui->progressBar->setVisible(true);
|
ui->progressBar->setVisible(true);
|
||||||
ui->progressBar->setMaximum(max);
|
ui->progressBar->setMaximum(max);
|
||||||
@@ -857,6 +859,7 @@ void CModListView::downloadFinished(QStringList savedFiles, QStringList failedFi
|
|||||||
|
|
||||||
void CModListView::hideProgressBar()
|
void CModListView::hideProgressBar()
|
||||||
{
|
{
|
||||||
|
Helper::keepScreenOn(false);
|
||||||
if(dlManager == nullptr) // it was not recreated meanwhile
|
if(dlManager == nullptr) // it was not recreated meanwhile
|
||||||
{
|
{
|
||||||
ui->progressWidget->setVisible(false);
|
ui->progressWidget->setVisible(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user