mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 07:47:24 +00:00
initial commit
This commit is contained in:
80
ios/Runner/AppDelegate.swift
Normal file
80
ios/Runner/AppDelegate.swift
Normal file
@@ -0,0 +1,80 @@
|
||||
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)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user