Merge pull request #83 from amnezia-vpn/open-config-in-app
iOS features : Open config in app, share configs
This commit is contained in:
commit
df94a87a51
12 changed files with 262 additions and 19 deletions
|
|
@ -38,6 +38,7 @@ HEADERS += \
|
|||
debug.h \
|
||||
defines.h \
|
||||
managementserver.h \
|
||||
platforms/ios/MobileUtils.h \
|
||||
platforms/linux/leakdetector.h \
|
||||
protocols/protocols_defs.h \
|
||||
settings.h \
|
||||
|
|
@ -95,6 +96,7 @@ SOURCES += \
|
|||
debug.cpp \
|
||||
main.cpp \
|
||||
managementserver.cpp \
|
||||
platforms/ios/MobileUtils.cpp \
|
||||
platforms/linux/leakdetector.cpp \
|
||||
protocols/protocols_defs.cpp \
|
||||
settings.cpp \
|
||||
|
|
@ -300,10 +302,13 @@ 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
|
||||
platforms/ios/QRCodeReader.cpp \
|
||||
platforms/ios/MobileUtils.cpp
|
||||
|
||||
SOURCES += \
|
||||
protocols/ios_vpnprotocol.mm \
|
||||
|
|
@ -313,6 +318,8 @@ ios {
|
|||
platforms/ios/ipaddress.cpp \
|
||||
platforms/ios/ipaddressrange.cpp \
|
||||
platforms/ios/QRCodeReaderBase.mm
|
||||
platforms/ios/QtAppDelegate.mm \
|
||||
platforms/ios/MobileUtils.mm
|
||||
|
||||
Q_ENABLE_BITCODE.value = NO
|
||||
Q_ENABLE_BITCODE.name = ENABLE_BITCODE
|
||||
|
|
|
|||
|
|
@ -8,6 +8,19 @@
|
|||
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
||||
<key>CFBundleDisplayName</key>
|
||||
<string>AmneziaVPN</string>
|
||||
<key>CFBundleDocumentTypes</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>CFBundleTypeName</key>
|
||||
<string>Amnezia VPN config</string>
|
||||
<key>LSHandlerRank</key>
|
||||
<string>Alternate</string>
|
||||
<key>LSItemContentTypes</key>
|
||||
<array>
|
||||
<string>org.amnezia.AmneziaVPN.amnezia-config</string>
|
||||
</array>
|
||||
</dict>
|
||||
</array>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIcons</key>
|
||||
|
|
@ -47,5 +60,31 @@
|
|||
<array/>
|
||||
<key>UIUserInterfaceStyle</key>
|
||||
<string>Light</string>
|
||||
<key>UTImportedTypeDeclarations</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>UTTypeConformsTo</key>
|
||||
<array>
|
||||
<string>public.data</string>
|
||||
</array>
|
||||
<key>UTTypeDescription</key>
|
||||
<string>Amnezia VPN config</string>
|
||||
<key>UTTypeIconFiles</key>
|
||||
<array/>
|
||||
<key>UTTypeIdentifier</key>
|
||||
<string>org.amnezia.AmneziaVPN.amnezia-config</string>
|
||||
<key>UTTypeTagSpecification</key>
|
||||
<dict>
|
||||
<key>public.filename-extension</key>
|
||||
<array>
|
||||
<string>vpn</string>
|
||||
</array>
|
||||
<key>public.mime-type</key>
|
||||
<array>
|
||||
<string>text/plain</string>
|
||||
</array>
|
||||
</dict>
|
||||
</dict>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
|
|||
|
|
@ -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](){
|
||||
|
|
|
|||
10
client/platforms/ios/MobileUtils.cpp
Normal file
10
client/platforms/ios/MobileUtils.cpp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#include "MobileUtils.h"
|
||||
|
||||
MobileUtils::MobileUtils()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MobileUtils::shareText(const QStringList& filesToSend) {
|
||||
|
||||
}
|
||||
17
client/platforms/ios/MobileUtils.h
Normal file
17
client/platforms/ios/MobileUtils.h
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#ifndef MOBILEUTILS_H
|
||||
#define MOBILEUTILS_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
|
||||
class MobileUtils : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MobileUtils() = delete;
|
||||
|
||||
public slots:
|
||||
static void shareText(const QStringList& filesToSend);
|
||||
};
|
||||
|
||||
#endif // MOBILEUTILS_H
|
||||
33
client/platforms/ios/MobileUtils.mm
Normal file
33
client/platforms/ios/MobileUtils.mm
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#include "MobileUtils.h"
|
||||
|
||||
#include <UIKit/UIKit.h>
|
||||
|
||||
static UIViewController* getViewController() {
|
||||
NSArray *windows = [[UIApplication sharedApplication]windows];
|
||||
for (UIWindow *window in windows) {
|
||||
if (window.isKeyWindow) {
|
||||
return window.rootViewController;
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
void MobileUtils::shareText(const QStringList& filesToSend) {
|
||||
NSMutableArray *sharingItems = [NSMutableArray new];
|
||||
|
||||
for (int i = 0; i < filesToSend.size(); i++) {
|
||||
NSURL *logFileUrl = [[NSURL alloc] initFileURLWithPath:filesToSend[i].toNSString()];
|
||||
[sharingItems addObject:logFileUrl];
|
||||
}
|
||||
|
||||
UIViewController *qtController = getViewController();
|
||||
if (!qtController) return;
|
||||
|
||||
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil];
|
||||
|
||||
[qtController presentViewController:activityController animated:YES completion:nil];
|
||||
UIPopoverPresentationController *popController = activityController.popoverPresentationController;
|
||||
if (popController) {
|
||||
popController.sourceView = qtController.view;
|
||||
}
|
||||
}
|
||||
9
client/platforms/ios/QtAppDelegate-C-Interface.h
Normal file
9
client/platforms/ios/QtAppDelegate-C-Interface.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef QTAPPDELEGATECINTERFACE_H
|
||||
#define QTAPPDELEGATECINTERFACE_H
|
||||
|
||||
#include "ui/pages_logic/StartPageLogic.h"
|
||||
|
||||
void QtAppDelegateInitialize();
|
||||
void setStartPageLogic(StartPageLogic*);
|
||||
|
||||
#endif // QTAPPDELEGATECINTERFACE_H
|
||||
9
client/platforms/ios/QtAppDelegate.h
Normal file
9
client/platforms/ios/QtAppDelegate.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#import <UIKit/UIKit.h>
|
||||
#import "QtAppDelegate-C-Interface.h"
|
||||
|
||||
#include "ui/pages_logic/StartPageLogic.h"
|
||||
|
||||
@interface QtAppDelegate : UIResponder <UIApplicationDelegate>
|
||||
+(QtAppDelegate *)sharedQtAppDelegate;
|
||||
@property (nonatomic) StartPageLogic* startPageLogic;
|
||||
@end
|
||||
91
client/platforms/ios/QtAppDelegate.mm
Normal file
91
client/platforms/ios/QtAppDelegate.mm
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
#import "QtAppDelegate.h"
|
||||
|
||||
#include <QFile>
|
||||
|
||||
@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<UIApplicationOpenURLOptionsKey, id> *)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
|
||||
|
|
@ -271,7 +271,11 @@ class XCodeprojPatcher
|
|||
@target_extension.build_configurations.each do |config|
|
||||
config.base_configuration_reference = @configFile
|
||||
|
||||
config.build_settings['LD_RUNPATH_SEARCH_PATHS'] ||= '"$(inherited) @executable_path/../Frameworks @executable_path/../../Frameworks"'
|
||||
config.build_settings['LD_RUNPATH_SEARCH_PATHS'] ||= [
|
||||
'$(inherited)',
|
||||
'@executable_path/../Frameworks',
|
||||
'@executable_path/../../Frameworks'
|
||||
]
|
||||
config.build_settings['SWIFT_VERSION'] ||= '5.0'
|
||||
config.build_settings['CLANG_ENABLE_MODULES'] ||= 'YES'
|
||||
config.build_settings['SWIFT_OBJC_BRIDGING_HEADER'] ||= 'macos/networkextension/WireGuardNetworkExtension-Bridging-Header.h'
|
||||
|
|
|
|||
|
|
@ -48,6 +48,8 @@
|
|||
#include "platforms/android/android_controller.h"
|
||||
#endif
|
||||
|
||||
#include "platforms/ios/MobileUtils.h"
|
||||
|
||||
#include "pages_logic/AppSettingsLogic.h"
|
||||
#include "pages_logic/GeneralSettingsLogic.h"
|
||||
#include "pages_logic/NetworkSettingsLogic.h"
|
||||
|
|
@ -612,21 +614,10 @@ PageEnumNS::Page UiLogic::currentPage()
|
|||
|
||||
void UiLogic::saveTextFile(const QString& desc, const QString& suggestedName, QString ext, const QString& data)
|
||||
{
|
||||
// ext.replace("*", "");
|
||||
// QString fileName = QFileDialog::getSaveFileName(nullptr, desc,
|
||||
// QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "*" + ext);
|
||||
|
||||
// if (fileName.isEmpty()) return;
|
||||
// if (!fileName.endsWith(ext)) fileName.append(ext);
|
||||
|
||||
// QFile save(fileName);
|
||||
// save.open(QIODevice::WriteOnly);
|
||||
// save.write(data.toUtf8());
|
||||
// save.close();
|
||||
|
||||
// QFileInfo fi(fileName);
|
||||
// QDesktopServices::openUrl(fi.absoluteDir().absolutePath());
|
||||
|
||||
#ifdef Q_OS_IOS
|
||||
shareTempFile(suggestedName, ext, data);
|
||||
return;
|
||||
#endif
|
||||
|
||||
ext.replace("*", "");
|
||||
QString docDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
|
||||
|
|
@ -681,3 +672,23 @@ void UiLogic::copyToClipboard(const QString &text)
|
|||
{
|
||||
qApp->clipboard()->setText(text);
|
||||
}
|
||||
|
||||
void UiLogic::shareTempFile(const QString &suggestedName, QString ext, const QString& data) {
|
||||
ext.replace("*", "");
|
||||
QString fileName = QDir::tempPath() + "/" + suggestedName;
|
||||
|
||||
if (fileName.isEmpty()) return;
|
||||
if (!fileName.endsWith(ext)) fileName.append(ext);
|
||||
|
||||
QFile::remove(fileName);
|
||||
qDebug() << "UiLogic::shareTempFile" << fileName;
|
||||
|
||||
QFile save(fileName);
|
||||
save.open(QIODevice::WriteOnly);
|
||||
save.write(data.toUtf8());
|
||||
save.close();
|
||||
|
||||
QStringList filesToSend;
|
||||
filesToSend.append(fileName);
|
||||
MobileUtils::shareText(filesToSend);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,6 +104,8 @@ public:
|
|||
Q_INVOKABLE void saveBinaryFile(const QString& desc, QString ext, const QString& data);
|
||||
Q_INVOKABLE void copyToClipboard(const QString& text);
|
||||
|
||||
void shareTempFile(const QString &suggestedName, QString ext, const QString& data);
|
||||
|
||||
QString getDialogConnectErrorText() const;
|
||||
void setDialogConnectErrorText(const QString &dialogConnectErrorText);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue