initial commit

This commit is contained in:
nyne
2024-09-29 16:17:03 +08:00
commit f08c5cccb9
196 changed files with 16761 additions and 0 deletions

View 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)
}
}