mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 15:57:25 +00:00
81 lines
2.7 KiB
Swift
81 lines
2.7 KiB
Swift
import Flutter
|
|
import UIKit
|
|
import UniformTypeIdentifiers
|
|
|
|
@UIApplicationMain
|
|
@objc class AppDelegate: FlutterAppDelegate {
|
|
var flutterResult: FlutterResult?
|
|
var directoryPath: URL!
|
|
|
|
override func application(
|
|
_ application: UIApplication,
|
|
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
|
|
) -> Bool {
|
|
GeneratedPluginRegistrant.register(with: self)
|
|
|
|
let methodChannel = FlutterMethodChannel(name: "venera/method_channel", binaryMessenger: controller.binaryMessenger)
|
|
methodChannel.setMethodCallHandler { (call, result) in
|
|
if call.method == "getProxy" {
|
|
if let proxySettings = CFNetworkCopySystemProxySettings()?.takeUnretainedValue() as NSDictionary?,
|
|
let dict = proxySettings.object(forKey: kCFNetworkProxiesHTTPProxy) as? NSDictionary,
|
|
let host = dict.object(forKey: kCFNetworkProxiesHTTPProxy) as? String,
|
|
let port = dict.object(forKey: kCFNetworkProxiesHTTPPort) as? Int {
|
|
let proxyConfig = "\(host):\(port)"
|
|
result(proxyConfig)
|
|
} else {
|
|
result("")
|
|
}
|
|
} else if call.method == "setScreenOn" {
|
|
if let arguments = call.arguments as? Bool {
|
|
let screenOn = arguments
|
|
UIApplication.shared.isIdleTimerDisabled = screenOn
|
|
}
|
|
result(nil)
|
|
} else if call.method == "getDirectoryPath" {
|
|
self.flutterResult = result
|
|
self.getDirectoryPath()
|
|
} else if call.method == "stopAccessingSecurityScopedResource" {
|
|
self.directoryPath?.stopAccessingSecurityScopedResource()
|
|
self.directoryPath = nil
|
|
result(nil)
|
|
} else {
|
|
result(FlutterMethodNotImplemented)
|
|
}
|
|
}
|
|
|
|
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
|
|
}
|
|
|
|
func getDirectoryPath() {
|
|
let documentPicker = UIDocumentPickerViewController(forOpeningContentTypes: [UTType.folder], asCopy: false)
|
|
documentPicker.delegate = self
|
|
documentPicker.allowsMultipleSelection = false
|
|
documentPicker.directoryURL = nil
|
|
documentPicker.modalPresentationStyle = .formSheet
|
|
|
|
if let rootViewController = window?.rootViewController {
|
|
rootViewController.present(documentPicker, animated: true, completion: nil)
|
|
}
|
|
}
|
|
|
|
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
|
|
self.directoryPath = urls.first
|
|
if self.directoryPath == nil {
|
|
flutterResult?(nil)
|
|
return
|
|
}
|
|
|
|
let success = self.directoryPath.startAccessingSecurityScopedResource()
|
|
|
|
if success {
|
|
flutterResult?(self.directoryPath.path)
|
|
} else {
|
|
flutterResult?(nil)
|
|
}
|
|
}
|
|
|
|
func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
|
|
flutterResult?(nil)
|
|
}
|
|
}
|