Merge pull request #653 from amnezia-vpn/fix/config-from-tg

Fix adding config from bot (iOS)
This commit is contained in:
pokamest 2024-02-29 07:05:24 -08:00 committed by GitHub
commit ee762c4cef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 36 deletions

View file

@ -48,10 +48,6 @@ int main(int argc, char *argv[])
AllowSetForegroundWindow(0); AllowSetForegroundWindow(0);
#endif #endif
#if defined(Q_OS_IOS)
QtAppDelegateInitialize();
#endif
app.registerTypes(); app.registerTypes();
app.setApplicationName(APPLICATION_NAME); app.setApplicationName(APPLICATION_NAME);

View file

@ -1,4 +1,7 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
@interface QtAppDelegate : UIResponder <UIApplicationDelegate> @interface QIOSApplicationDelegate
@end
@interface QIOSApplicationDelegate (AmneziaVPNDelegate)
@end @end

View file

@ -3,25 +3,15 @@
#include <QFile> #include <QFile>
@implementation QtAppDelegate { UIView *_screen;
UIView *_screen;
}
+(QtAppDelegate *)sharedQtAppDelegate {
static dispatch_once_t pred;
static QtAppDelegate *shared = nil;
dispatch_once(&pred, ^{
shared = [[super alloc] init];
});
return shared;
}
@implementation QIOSApplicationDelegate (AmneziaVPNDelegate)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{ {
[application setMinimumBackgroundFetchInterval: UIApplicationBackgroundFetchIntervalMinimum]; [application setMinimumBackgroundFetchInterval: UIApplicationBackgroundFetchIntervalMinimum];
// Override point for customization after application launch. // Override point for customization after application launch.
NSLog(@"Did this launch option happen"); NSLog(@"Application didFinishLaunchingWithOptions");
return YES; return YES;
} }
@ -70,31 +60,27 @@
- (BOOL)application:(UIApplication *)app - (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options { options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
NSLog(@"Application openURL: %@", url);
if (url.fileURL) { if (url.fileURL) {
QString filePath(url.path.UTF8String); QString filePath(url.path.UTF8String);
if (filePath.isEmpty()) return NO; if (filePath.isEmpty()) return NO;
if (filePath.contains("backup")) { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
IosController::Instance()->importBackupFromOutside(filePath); NSLog(@"Application openURL: %@", url);
} else {
QFile file(filePath); if (filePath.contains("backup")) {
bool isOpenFile = file.open(QIODevice::ReadOnly); IosController::Instance()->importBackupFromOutside(filePath);
QByteArray data = file.readAll(); } else {
QFile file(filePath);
IosController::Instance()->importConfigFromOutside(QString(data)); bool isOpenFile = file.open(QIODevice::ReadOnly);
} QByteArray data = file.readAll();
IosController::Instance()->importConfigFromOutside(QString(data));
}
});
return YES; return YES;
} }
return NO; return NO;
} }
void QtAppDelegateInitialize()
{
[[UIApplication sharedApplication] setDelegate: [QtAppDelegate sharedQtAppDelegate]];
NSLog(@"Created a new AppDelegate");
}
@end @end