feat: function to check if the app is active and make the app active are added

This commit is contained in:
Sale Djenic 2022-02-21 18:05:51 +01:00 committed by Michał
parent 3d08d2536e
commit 84de33af4b
2 changed files with 41 additions and 0 deletions

View File

@ -1039,6 +1039,9 @@ DOS_API char *dos_to_local_file(const char* fileUrl);
DOS_API char *dos_from_local_file(const char* filePath);
DOS_API bool dos_app_is_active(DosQQmlApplicationEngine* vptr);
DOS_API void dos_app_make_it_active(DosQQmlApplicationEngine* vptr);
#ifdef __cplusplus
}
#endif

View File

@ -1505,3 +1505,41 @@ char* dos_from_local_file(const char* filePath)
{
return convert_to_cstring(QUrl::fromLocalFile(QString::fromUtf8(filePath)).toString());
}
bool dos_app_is_active(::DosQQmlApplicationEngine* vptr)
{
auto engine = static_cast<QQmlApplicationEngine*>(vptr);
if(!engine)
return false;
QObject* topLevelObj = engine->rootObjects().value(0);
if(topLevelObj && topLevelObj->objectName() == "mainWindow")
{
QQuickWindow* window = qobject_cast<QQuickWindow *>(topLevelObj);
if(window)
{
return window->isActive();
}
}
return false;
}
void dos_app_make_it_active(::DosQQmlApplicationEngine* vptr)
{
auto engine = static_cast<QQmlApplicationEngine*>(vptr);
if(!engine)
return;
QObject* topLevelObj = engine->rootObjects().value(0);
if(topLevelObj && topLevelObj->objectName() == "mainWindow")
{
QQuickWindow* window = qobject_cast<QQuickWindow *>(topLevelObj);
if(window)
{
window->show();
window->raise();
window->requestActivate();
}
}
}