2023-05-22 16:17:51 +08:00
|
|
|
#include "FluApp.h"
|
2023-02-26 23:47:07 +08:00
|
|
|
|
|
|
|
#include <QQmlEngine>
|
|
|
|
#include <QGuiApplication>
|
|
|
|
#include <QQmlContext>
|
2023-02-27 18:46:39 +08:00
|
|
|
#include <QQuickItem>
|
2023-02-27 23:04:52 +08:00
|
|
|
#include <QTimer>
|
2023-03-30 17:16:57 +08:00
|
|
|
#include <QUuid>
|
2023-04-27 09:38:57 +08:00
|
|
|
#include <QFontDatabase>
|
2023-03-02 12:20:16 +08:00
|
|
|
#include <QClipboard>
|
2023-10-08 18:19:08 +08:00
|
|
|
#include <FramelessHelper/Quick/framelessquickmodule.h>
|
|
|
|
#include <FramelessHelper/Core/private/framelessconfig_p.h>
|
|
|
|
|
|
|
|
FRAMELESSHELPER_USE_NAMESPACE
|
2023-04-27 17:29:39 +08:00
|
|
|
|
2023-09-13 15:11:22 +08:00
|
|
|
FluApp::FluApp(QObject *parent):QObject{parent}{
|
2023-10-15 17:24:33 +08:00
|
|
|
vsync(false);
|
2023-07-20 21:54:45 +08:00
|
|
|
httpInterceptor(nullptr);
|
2023-04-27 17:29:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
FluApp::~FluApp(){
|
2023-02-27 18:46:39 +08:00
|
|
|
}
|
|
|
|
|
2023-04-11 23:12:31 +08:00
|
|
|
void FluApp::init(QQuickWindow *window){
|
2023-09-27 15:18:10 +08:00
|
|
|
this->_application = window;
|
2023-10-08 18:19:08 +08:00
|
|
|
FramelessHelper::Quick::initialize();
|
|
|
|
FramelessConfig::instance()->set(Global::Option::DisableLazyInitializationForMicaMaterial);
|
|
|
|
FramelessConfig::instance()->set(Global::Option::CenterWindowBeforeShow);
|
|
|
|
FramelessConfig::instance()->set(Global::Option::ForceNonNativeBackgroundBlur);
|
|
|
|
FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow);
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow,false);
|
|
|
|
#endif
|
|
|
|
#ifdef Q_OS_MACOS
|
|
|
|
FramelessConfig::instance()->set(Global::Option::ForceNonNativeBackgroundBlur,false);
|
|
|
|
#endif
|
|
|
|
QQmlEngine *engine = qmlEngine(_application);
|
|
|
|
FramelessHelper::Quick::registerTypes(engine);
|
2023-02-26 23:47:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void FluApp::run(){
|
2023-02-27 23:04:52 +08:00
|
|
|
navigate(initialRoute());
|
2023-02-26 23:47:07 +08:00
|
|
|
}
|
|
|
|
|
2023-03-13 21:18:51 +08:00
|
|
|
void FluApp::navigate(const QString& route,const QJsonObject& argument,FluRegister* fluRegister){
|
2023-02-26 23:47:07 +08:00
|
|
|
if(!routes().contains(route)){
|
2023-06-25 23:17:44 +08:00
|
|
|
qCritical()<<"No route found "<<route;
|
2023-02-26 23:47:07 +08:00
|
|
|
return;
|
|
|
|
}
|
2023-09-27 15:18:10 +08:00
|
|
|
QQmlEngine *engine = qmlEngine(_application);
|
2023-04-11 23:12:31 +08:00
|
|
|
QQmlComponent component(engine, routes().value(route).toString());
|
2023-06-18 13:56:30 +08:00
|
|
|
if (component.isError()) {
|
2023-06-25 23:17:44 +08:00
|
|
|
qCritical() << component.errors();
|
2023-06-18 13:56:30 +08:00
|
|
|
return;
|
|
|
|
}
|
2023-04-11 23:12:31 +08:00
|
|
|
QVariantMap properties;
|
2023-08-11 22:47:36 +08:00
|
|
|
properties.insert("_route",route);
|
2023-03-13 21:18:51 +08:00
|
|
|
if(fluRegister){
|
2023-08-11 22:47:36 +08:00
|
|
|
properties.insert("_pageRegister",QVariant::fromValue(fluRegister));
|
2023-03-13 21:18:51 +08:00
|
|
|
}
|
2023-04-11 23:12:31 +08:00
|
|
|
properties.insert("argument",argument);
|
2023-09-27 15:18:10 +08:00
|
|
|
QQuickWindow *win=nullptr;
|
|
|
|
for (const auto& pair : _windows.toStdMap()) {
|
|
|
|
QString r = pair.second->property("_route").toString();
|
2023-05-10 10:32:37 +08:00
|
|
|
if(r == route){
|
2023-09-27 15:18:10 +08:00
|
|
|
win = pair.second;
|
2023-05-10 10:32:37 +08:00
|
|
|
break;
|
2023-04-13 17:41:34 +08:00
|
|
|
}
|
2023-05-10 10:32:37 +08:00
|
|
|
}
|
2023-09-27 15:18:10 +08:00
|
|
|
if(win){
|
|
|
|
int launchMode = win->property("launchMode").toInt();
|
2023-05-10 10:32:37 +08:00
|
|
|
if(launchMode == 1){
|
2023-09-27 15:18:10 +08:00
|
|
|
win->setProperty("argument",argument);
|
|
|
|
win->show();
|
|
|
|
win->raise();
|
|
|
|
win->requestActivate();
|
2023-05-10 10:32:37 +08:00
|
|
|
return;
|
|
|
|
}else if(launchMode == 2){
|
2023-09-27 15:18:10 +08:00
|
|
|
win->close();
|
2023-04-13 17:41:34 +08:00
|
|
|
}
|
|
|
|
}
|
2023-09-27 15:18:10 +08:00
|
|
|
win = qobject_cast<QQuickWindow*>(component.createWithInitialProperties(properties));
|
2023-04-11 23:12:31 +08:00
|
|
|
if(fluRegister){
|
2023-09-27 15:18:10 +08:00
|
|
|
fluRegister->to(win);
|
2023-03-05 23:39:13 +08:00
|
|
|
}
|
2023-09-27 15:18:10 +08:00
|
|
|
win->setColor(QColor(Qt::transparent));
|
2023-02-27 18:46:39 +08:00
|
|
|
}
|
2023-03-02 12:20:16 +08:00
|
|
|
|
2023-09-27 15:18:10 +08:00
|
|
|
void FluApp::exit(int retCode){
|
|
|
|
for (const auto& pair : _windows.toStdMap()) {
|
|
|
|
removeWindow(pair.second);
|
2023-03-02 12:20:16 +08:00
|
|
|
}
|
2023-09-27 15:18:10 +08:00
|
|
|
qApp->exit(retCode);
|
2023-03-02 12:20:16 +08:00
|
|
|
}
|
|
|
|
|
2023-09-27 15:18:10 +08:00
|
|
|
void FluApp::addWindow(QQuickWindow* window){
|
|
|
|
_windows.insert(window->winId(),window);
|
2023-04-19 09:41:08 +08:00
|
|
|
}
|
2023-06-28 02:28:34 +08:00
|
|
|
|
2023-09-27 15:18:10 +08:00
|
|
|
void FluApp::removeWindow(QQuickWindow* window){
|
2023-06-28 13:13:39 +08:00
|
|
|
if(window){
|
2023-09-27 15:18:10 +08:00
|
|
|
_windows.remove(window->winId());
|
2023-06-28 13:13:39 +08:00
|
|
|
window->deleteLater();
|
|
|
|
window = nullptr;
|
|
|
|
}
|
2023-06-28 02:28:34 +08:00
|
|
|
}
|