main: fix style and cleanup #includes

Signed-off-by: Jared Van Bortel <jared@nomic.ai>
This commit is contained in:
Jared Van Bortel 2024-08-30 11:55:27 -04:00
parent edccc5b2f1
commit a9d9d282d7

View File

@ -12,14 +12,11 @@
#include <singleapplication.h>
#include <QCoreApplication>
#include <QGuiApplication>
#include <QObject>
#include <QQmlApplicationEngine>
#include <QQmlEngine>
#include <QQuickWindow>
#include <QSettings>
#include <QString>
#include <QTranslator>
#include <QUrl>
#include <Qt>
@ -31,16 +28,19 @@
# include <windows.h>
#endif
void raiseWindow(QWindow* window) {
using namespace Qt::Literals::StringLiterals;
static void raiseWindow(QWindow *window)
{
#ifdef Q_OS_WINDOWS
HWND hwnd = (HWND)window->winId();
HWND hwnd = HWND(window->winId());
// check if window is minimized to Windows task bar
if (::IsIconic(hwnd)) {
::ShowWindow(hwnd, SW_RESTORE);
}
if (IsIconic(hwnd))
ShowWindow(hwnd, SW_RESTORE);
::SetForegroundWindow(hwnd);
SetForegroundWindow(hwnd);
#else
window->show();
window->raise();
@ -61,7 +61,7 @@ int main(int argc, char *argv[])
SingleApplication app(argc, argv, true /*allowSecondary*/);
if (app.isSecondary()) {
#ifdef Q_OS_WINDOWS
AllowSetForegroundWindow( DWORD( app.primaryPid() ) );
AllowSetForegroundWindow(DWORD(app.primaryPid()));
#endif
app.sendMessage("RAISE_WINDOW");
return 0;
@ -107,7 +107,7 @@ int main(int argc, char *argv[])
qmlRegisterSingletonInstance("localdocs", 1, 0, "LocalDocs", LocalDocs::globalInstance());
qmlRegisterUncreatableMetaObject(MySettingsEnums::staticMetaObject, "mysettingsenums", 1, 0, "MySettingsEnums", "Error: only enums");
const QUrl url(u"qrc:/gpt4all/main.qml"_qs);
const QUrl url(u"qrc:/gpt4all/main.qml"_s);
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
@ -117,7 +117,7 @@ int main(int argc, char *argv[])
engine.load(url);
QObject *rootObject = engine.rootObjects().first();
QQuickWindow *windowObject = qobject_cast<QQuickWindow*>(rootObject);
QQuickWindow *windowObject = qobject_cast<QQuickWindow *>(rootObject);
QObject::connect(&app, &SingleApplication::receivedMessage,
windowObject, [windowObject] () { raiseWindow(windowObject); } );