From f8b2cce618d7b56d78ffd367fb17f5b9573152a6 Mon Sep 17 00:00:00 2001 From: Igor Sorokin Date: Thu, 29 Feb 2024 08:36:56 +0300 Subject: [PATCH] Fix adding config from bot --- client/main.cpp | 4 --- client/platforms/ios/QtAppDelegate.h | 5 ++- client/platforms/ios/QtAppDelegate.mm | 48 ++++++++++----------------- 3 files changed, 21 insertions(+), 36 deletions(-) diff --git a/client/main.cpp b/client/main.cpp index bf861dc2..2b0e264b 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -48,10 +48,6 @@ int main(int argc, char *argv[]) AllowSetForegroundWindow(0); #endif -#if defined(Q_OS_IOS) - QtAppDelegateInitialize(); -#endif - app.registerTypes(); app.setApplicationName(APPLICATION_NAME); diff --git a/client/platforms/ios/QtAppDelegate.h b/client/platforms/ios/QtAppDelegate.h index 5148c2ca..c2c1d2d3 100644 --- a/client/platforms/ios/QtAppDelegate.h +++ b/client/platforms/ios/QtAppDelegate.h @@ -1,4 +1,7 @@ #import -@interface QtAppDelegate : UIResponder +@interface QIOSApplicationDelegate +@end + +@interface QIOSApplicationDelegate (AmneziaVPNDelegate) @end diff --git a/client/platforms/ios/QtAppDelegate.mm b/client/platforms/ios/QtAppDelegate.mm index 48cef914..70e54400 100644 --- a/client/platforms/ios/QtAppDelegate.mm +++ b/client/platforms/ios/QtAppDelegate.mm @@ -3,25 +3,15 @@ #include -@implementation QtAppDelegate { - UIView *_screen; -} - -+(QtAppDelegate *)sharedQtAppDelegate { - static dispatch_once_t pred; - static QtAppDelegate *shared = nil; - dispatch_once(&pred, ^{ - shared = [[super alloc] init]; - }); - return shared; -} +UIView *_screen; +@implementation QIOSApplicationDelegate (AmneziaVPNDelegate) - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [application setMinimumBackgroundFetchInterval: UIApplicationBackgroundFetchIntervalMinimum]; // Override point for customization after application launch. - NSLog(@"Did this launch option happen"); + NSLog(@"Application didFinishLaunchingWithOptions"); return YES; } @@ -70,31 +60,27 @@ - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options { - - NSLog(@"Application openURL: %@", url); if (url.fileURL) { QString filePath(url.path.UTF8String); if (filePath.isEmpty()) return NO; - if (filePath.contains("backup")) { - IosController::Instance()->importBackupFromOutside(filePath); - } else { - QFile file(filePath); - bool isOpenFile = file.open(QIODevice::ReadOnly); - QByteArray data = file.readAll(); - - IosController::Instance()->importConfigFromOutside(QString(data)); - } + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ + NSLog(@"Application openURL: %@", url); + + if (filePath.contains("backup")) { + IosController::Instance()->importBackupFromOutside(filePath); + } else { + QFile file(filePath); + bool isOpenFile = file.open(QIODevice::ReadOnly); + QByteArray data = file.readAll(); + + IosController::Instance()->importConfigFromOutside(QString(data)); + } + }); + return YES; } return NO; } - -void QtAppDelegateInitialize() -{ - [[UIApplication sharedApplication] setDelegate: [QtAppDelegate sharedQtAppDelegate]]; - NSLog(@"Created a new AppDelegate"); -} - @end