VPN connection moved to separate thread

This commit is contained in:
pokamest 2021-10-26 12:59:20 +03:00
parent 1b1a5be607
commit 44f4d083bf
10 changed files with 166 additions and 104 deletions

View file

@ -117,6 +117,8 @@ int main(int argc, char *argv[])
app.setQuitOnLastWindowClosed(false);
qRegisterMetaType<VpnProtocol::ConnectionState>("VpnProtocol::ConnectionState");
qRegisterMetaType<ServerCredentials>("ServerCredentials");
qRegisterMetaType<DockerContainer>("DockerContainer");
qRegisterMetaType<TransportProto>("TransportProto");
qRegisterMetaType<Protocol>("Protocol");
@ -128,7 +130,7 @@ int main(int argc, char *argv[])
UiLogic *uiLogic = new UiLogic;
QQmlApplicationEngine engine;
QQmlApplicationEngine *engine = new QQmlApplicationEngine;
declareQmlPageEnum();
declareQmlProtocolEnum();
@ -141,29 +143,37 @@ int main(int argc, char *argv[])
qmlRegisterSingletonInstance("ProtocolProps", 1, 0, "ProtocolProps", protocolProps.get());
const QUrl url(QStringLiteral("qrc:/ui/qml/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
QObject::connect(engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.rootContext()->setContextProperty("UiLogic", uiLogic);
engine->rootContext()->setContextProperty("UiLogic", uiLogic);
engine.rootContext()->setContextProperty("AppSettingsLogic", uiLogic->appSettingsLogic());
engine.rootContext()->setContextProperty("GeneralSettingsLogic", uiLogic->generalSettingsLogic());
engine.rootContext()->setContextProperty("NetworkSettingsLogic", uiLogic->networkSettingsLogic());
engine.rootContext()->setContextProperty("ServerConfiguringProgressLogic", uiLogic->serverConfiguringProgressLogic());
engine.rootContext()->setContextProperty("NewServerProtocolsLogic", uiLogic->newServerProtocolsLogic());
engine.rootContext()->setContextProperty("ServerListLogic", uiLogic->serverListLogic());
engine.rootContext()->setContextProperty("ServerSettingsLogic", uiLogic->serverSettingsLogic());
engine.rootContext()->setContextProperty("ServerContainersLogic", uiLogic->serverVpnProtocolsLogic());
engine.rootContext()->setContextProperty("ShareConnectionLogic", uiLogic->shareConnectionLogic());
engine.rootContext()->setContextProperty("SitesLogic", uiLogic->sitesLogic());
engine.rootContext()->setContextProperty("StartPageLogic", uiLogic->startPageLogic());
engine.rootContext()->setContextProperty("VpnLogic", uiLogic->vpnLogic());
engine.rootContext()->setContextProperty("WizardLogic", uiLogic->wizardLogic());
engine->rootContext()->setContextProperty("AppSettingsLogic", uiLogic->appSettingsLogic());
engine->rootContext()->setContextProperty("GeneralSettingsLogic", uiLogic->generalSettingsLogic());
engine->rootContext()->setContextProperty("NetworkSettingsLogic", uiLogic->networkSettingsLogic());
engine->rootContext()->setContextProperty("ServerConfiguringProgressLogic", uiLogic->serverConfiguringProgressLogic());
engine->rootContext()->setContextProperty("NewServerProtocolsLogic", uiLogic->newServerProtocolsLogic());
engine->rootContext()->setContextProperty("ServerListLogic", uiLogic->serverListLogic());
engine->rootContext()->setContextProperty("ServerSettingsLogic", uiLogic->serverSettingsLogic());
engine->rootContext()->setContextProperty("ServerContainersLogic", uiLogic->serverVpnProtocolsLogic());
engine->rootContext()->setContextProperty("ShareConnectionLogic", uiLogic->shareConnectionLogic());
engine->rootContext()->setContextProperty("SitesLogic", uiLogic->sitesLogic());
engine->rootContext()->setContextProperty("StartPageLogic", uiLogic->startPageLogic());
engine->rootContext()->setContextProperty("VpnLogic", uiLogic->vpnLogic());
engine->rootContext()->setContextProperty("WizardLogic", uiLogic->wizardLogic());
engine.load(url);
engine->load(url);
QObject::connect(&app, &QCoreApplication::aboutToQuit, uiLogic, [&engine, uiLogic](){
QObject::disconnect(engine, 0,0,0);
delete engine;
QObject::disconnect(uiLogic, 0,0,0);
delete uiLogic;
});
// TODO - fix
//#ifdef Q_OS_WIN