remove outdated resource loader methods for iOS/macOS/Android

This commit is contained in:
Nick Fisher
2025-04-16 14:01:47 +08:00
parent dfda0eb476
commit 85a0451f1b
3 changed files with 0 additions and 114 deletions

View File

@@ -209,10 +209,6 @@ class ThermionFlutterPlugin: FlutterPlugin, MethodCallHandler, ActivityAware, Lo
result.error("TEXTURE_NOT_FOUND", "Texture with id $textureId not found", null)
}
}
"getResourceLoaderWrapper" -> {
val resourceLoader = _lib.make_resource_loader_wrapper_android(loadResourceWrapper, freeResourceWrapper, Pointer(0))
result.success(Pointer.nativeValue(resourceLoader))
}
"getDriverPlatform" -> {
result.success(null)
}

View File

@@ -13,108 +13,6 @@ public class SwiftThermionFlutterPlugin: NSObject, FlutterPlugin {
var resources:NSMutableDictionary = [:]
static var messenger : FlutterBinaryMessenger? = nil;
var loadResource : @convention(c) (UnsafePointer<Int8>?, UnsafeMutableRawPointer?) -> ResourceBuffer = { uri, resourcesPtr in
let instance:SwiftThermionFlutterPlugin = Unmanaged<SwiftThermionFlutterPlugin>.fromOpaque(resourcesPtr!).takeUnretainedValue()
let uriString = String(cString:uri!)
var path:String? = nil
// check for hot-reloaded asset
var found : URL? = nil
if(uriString.hasPrefix("asset://")) {
let assetPath = String(uriString.dropFirst(8))
print("Searching for hot reloaded asset under path : \(assetPath)")
let appFolder = Bundle.main.resourceURL
let dirPaths = NSSearchPathForDirectoriesInDomains(.applicationDirectory,
.userDomainMask, true)
let supportDirPaths = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory,
.userDomainMask, true)
let devFsPath = URL(fileURLWithPath: supportDirPaths.first!, isDirectory:true).deletingLastPathComponent().deletingLastPathComponent().appendingPathComponent("tmp")
let orderedURLs = try? FileManager.default.enumerator(at: devFsPath, includingPropertiesForKeys: [ .pathKey, .creationDateKey], options: .skipsHiddenFiles)
for case let fileURL as URL in orderedURLs! {
if !(fileURL.path.hasSuffix(assetPath)) {
continue
}
print("Found hot reloaded asset : \(fileURL)")
if found == nil {
found = fileURL
} else {
do {
let c1 = try found!.resourceValues(forKeys: [.creationDateKey]).creationDate
let c2 = try fileURL.resourceValues(forKeys: [.creationDateKey]).creationDate
if c1! < c2! {
found = fileURL
print("\(fileURL) is newer, replacing")
} else {
print("Ignoring older asset")
}
} catch {
}
}
}
}
do {
if let cd = try found?.resourceValues(forKeys:[.creationDateKey]).creationDate {
if cd > instance.createdAt {
print("Using hot reloaded asset : \(found)")
path = found!.path
}
}
} catch {
}
if path == nil {
if(uriString.hasPrefix("file://")) {
path = String(uriString.dropFirst(7))
} else if(uriString.hasPrefix("asset://")) {
let key = instance.registrar.lookupKey(forAsset:String(uriString.dropFirst(8)))
path = Bundle.main.path(forResource: key, ofType:nil)
print("Found path \(path) for uri \(uriString)")
guard path != nil else {
print("File not present in bundle : \(uri)")
return ResourceBuffer()
}
} else {
let key = instance.registrar.lookupKey(forAsset:uriString)
path = Bundle.main.path(forResource: key, ofType:nil)
print("Found path \(path) for uri \(uriString)")
guard path != nil else {
print("File not present in bundle : \(uri)")
return ResourceBuffer()
}
}
}
do {
let data = try Data(contentsOf: URL(fileURLWithPath:path!))
let resId = instance.resources.count
let nsData = data as NSData
instance.resources[resId] = nsData
let rawPtr = nsData.bytes
let length = Int32(nsData.count)
print("Opened asset of length \(Int32(length)) at path \(path!)")
return ResourceBuffer(data:rawPtr, size:length, id:Int32(resId))
} catch {
print("Error opening file: \(error)")
}
return ResourceBuffer()
}
var freeResource : @convention(c) (ResourceBuffer,UnsafeMutableRawPointer?) -> () = { rbuf, resourcesPtr in
let instance:SwiftThermionFlutterPlugin = Unmanaged<SwiftThermionFlutterPlugin>.fromOpaque(resourcesPtr!).takeUnretainedValue()
instance.resources.removeObject(forKey:rbuf.id)
}
var markTextureFrameAvailable: @convention(c) (UnsafeMutableRawPointer?) -> () = { instancePtr in
let instance: SwiftThermionFlutterPlugin = Unmanaged<SwiftThermionFlutterPlugin>.fromOpaque(instancePtr!).takeUnretainedValue()
@@ -139,9 +37,6 @@ public class SwiftThermionFlutterPlugin: NSObject, FlutterPlugin {
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
let methodName = call.method;
switch methodName {
case "getResourceLoaderWrapper":
let resourceLoaderWrapper = make_resource_loader(loadResource, freeResource, Unmanaged.passUnretained(self).toOpaque())
result(unsafeBitCast(resourceLoaderWrapper, to:Int64.self))
case "getRenderCallback":
let renderCallback = markTextureFrameAvailable
result([

View File

@@ -83,11 +83,6 @@ public class SwiftThermionFlutterPlugin: NSObject, FlutterPlugin {
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
let methodName = call.method;
switch methodName {
case "getResourceLoaderWrapper":
if(resourceLoaderWrapper == nil) {
resourceLoaderWrapper = make_resource_loader(loadResource, freeResource, Unmanaged.passUnretained(self).toOpaque())
}
result(Int64(Int(bitPattern: resourceLoaderWrapper!)))
case "markTextureFrameAvailable":
let flutterTextureId = call.arguments as! Int64
registry.textureFrameAvailable(flutterTextureId)