From 9ed16b81e84c491e17d8f935835ef858bdfe3bce Mon Sep 17 00:00:00 2001 From: eugenyorbitsoftcom Date: Mon, 11 Jul 2022 16:08:57 +0600 Subject: [PATCH] read imported file configuration --- client/client.pro | 7 +- client/main.cpp | 13 ++- .../platforms/ios/QtAppDelegate-C-Interface.h | 9 ++ client/platforms/ios/QtAppDelegate.h | 9 ++ client/platforms/ios/QtAppDelegate.mm | 91 +++++++++++++++++++ 5 files changed, 126 insertions(+), 3 deletions(-) create mode 100644 client/platforms/ios/QtAppDelegate-C-Interface.h create mode 100644 client/platforms/ios/QtAppDelegate.h create mode 100644 client/platforms/ios/QtAppDelegate.mm diff --git a/client/client.pro b/client/client.pro index 316730f93..8127c415b 100644 --- a/client/client.pro +++ b/client/client.pro @@ -300,7 +300,9 @@ ios { platforms/ios/bigint.h \ platforms/ios/bigintipv6addr.h \ platforms/ios/ipaddress.h \ - platforms/ios/ipaddressrange.h + platforms/ios/ipaddressrange.h \ + platforms/ios/QtAppDelegate.h \ + platforms/ios/QtAppDelegate-C-Interface.h SOURCES -= \ platforms/ios/QRCodeReader.cpp @@ -312,7 +314,8 @@ ios { platforms/ios/iosglue.mm \ platforms/ios/ipaddress.cpp \ platforms/ios/ipaddressrange.cpp \ - platforms/ios/QRCodeReader.mm + platforms/ios/QRCodeReader.mm \ + platforms/ios/QtAppDelegate.mm Q_ENABLE_BITCODE.value = NO Q_ENABLE_BITCODE.name = ENABLE_BITCODE diff --git a/client/main.cpp b/client/main.cpp index b1419f183..2aa35a39a 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -57,6 +57,10 @@ #include "native.h" #endif +#if defined(Q_OS_IOS) +#include "QtAppDelegate-C-Interface.h" +#endif + static void loadTranslator() { QTranslator* translator = new QTranslator; @@ -88,7 +92,6 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); #endif - #ifdef Q_OS_WIN AllowSetForegroundWindow(0); #endif @@ -97,6 +100,10 @@ int main(int argc, char *argv[]) NativeHelpers::registerApplicationInstance(&app); #endif +#if defined(Q_OS_IOS) + QtAppDelegateInitialize(); +#endif + loadTranslator(); QFontDatabase::addApplicationFont(":/fonts/Lato-Black.ttf"); @@ -203,6 +210,10 @@ int main(int argc, char *argv[]) engine->rootContext()->setContextProperty("VpnLogic", uiLogic->vpnLogic()); engine->rootContext()->setContextProperty("WizardLogic", uiLogic->wizardLogic()); +#if defined(Q_OS_IOS) + setStartPageLogic(uiLogic->startPageLogic()); +#endif + engine->load(url); QObject::connect(&app, &QCoreApplication::aboutToQuit, uiLogic, [&engine, uiLogic](){ diff --git a/client/platforms/ios/QtAppDelegate-C-Interface.h b/client/platforms/ios/QtAppDelegate-C-Interface.h new file mode 100644 index 000000000..afd31e7d8 --- /dev/null +++ b/client/platforms/ios/QtAppDelegate-C-Interface.h @@ -0,0 +1,9 @@ +#ifndef QTAPPDELEGATECINTERFACE_H +#define QTAPPDELEGATECINTERFACE_H + +#include "ui/pages_logic/StartPageLogic.h" + +void QtAppDelegateInitialize(); +void setStartPageLogic(StartPageLogic*); + +#endif // QTAPPDELEGATECINTERFACE_H diff --git a/client/platforms/ios/QtAppDelegate.h b/client/platforms/ios/QtAppDelegate.h new file mode 100644 index 000000000..1e0dc4121 --- /dev/null +++ b/client/platforms/ios/QtAppDelegate.h @@ -0,0 +1,9 @@ +#import +#import "QtAppDelegate-C-Interface.h" + +#include "ui/pages_logic/StartPageLogic.h" + +@interface QtAppDelegate : UIResponder ++(QtAppDelegate *)sharedQtAppDelegate; +@property (nonatomic) StartPageLogic* startPageLogic; +@end diff --git a/client/platforms/ios/QtAppDelegate.mm b/client/platforms/ios/QtAppDelegate.mm new file mode 100644 index 000000000..f63bea358 --- /dev/null +++ b/client/platforms/ios/QtAppDelegate.mm @@ -0,0 +1,91 @@ +#import "QtAppDelegate.h" + +#include + +@implementation QtAppDelegate + ++(QtAppDelegate *)sharedQtAppDelegate { + static dispatch_once_t pred; + static QtAppDelegate *shared = nil; + dispatch_once(&pred, ^{ + shared = [[super alloc] init]; + }); + return shared; +} + + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions +{ + [application setMinimumBackgroundFetchInterval: UIApplicationBackgroundFetchIntervalMinimum]; + // Override point for customization after application launch. + NSLog(@"Did this launch option happen"); + return YES; +} + +- (void)applicationWillResignActive:(UIApplication *)application +{ + // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. +} + +- (void)applicationDidEnterBackground:(UIApplication *)application +{ + // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. + NSLog(@"In the background"); +} + +- (void)applicationWillEnterForeground:(UIApplication *)application +{ + // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. + NSLog(@"In the foreground"); +} + +- (void)applicationDidBecomeActive:(UIApplication *)application +{ + // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. +} + +- (void)applicationWillTerminate:(UIApplication *)application +{ + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. +} + +-(void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { + // We will add content here soon. + NSLog(@"In the completionHandler"); +} + +- (BOOL)application:(UIApplication *)app + openURL:(NSURL *)url + options:(NSDictionary *)options { + + NSLog(@"Application openURL: %@", url); + if (url.fileURL) { + QString filePath(url.path.UTF8String); + qDebug() << "filePath:" << filePath; + if (filePath.isEmpty()) return NO; + + QFile file(filePath); + bool isOpenFile = file.open(QIODevice::ReadOnly); + qDebug() << "isOpenFile:" << isOpenFile; + QByteArray data = file.readAll(); + + [QtAppDelegate sharedQtAppDelegate].startPageLogic->importConnectionFromCode(QString(data)); + return YES; + } + return NO; +} + + +void QtAppDelegateInitialize() +{ + [[UIApplication sharedApplication] setDelegate: [QtAppDelegate sharedQtAppDelegate]]; + NSLog(@"Created a new AppDelegate"); +} + +void setStartPageLogic(StartPageLogic* startPage) { + [QtAppDelegate sharedQtAppDelegate].startPageLogic = startPage; +} + +@end