12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- //
- // ConverFilePlugin.swift
- // Runner
- //
- // Created by Xiaolong Liu on 2023/2/27.
- //
- import Foundation
- import ComPDFKit_Conversion
- class ConverFilePlugin{
-
- init(messenger : FlutterBinaryMessenger){
- let channel = FlutterEventChannel(name: "com.compdfkit.conversion.flutter.convert", binaryMessenger: messenger)
- channel.setStreamHandler(SwiftStreamHandler())
- }
-
- }
- class SwiftStreamHandler: NSObject, FlutterStreamHandler {
-
-
- public func onListen(withArguments arguments: Any?, eventSink events: @escaping FlutterEventSink) -> FlutterError? {
-
- var convertData = arguments as! [String: String];
- var filePath = convertData["filePath"] ?? "";
- let convertType = convertData["convertType"]!;
- let dataTag = String(convertData["dataTag"]!);
- let queue = DispatchQueue(label: "com.compdfkit.conversion.flutter")
- queue.async {
-
- // var index = 0
- // while index < 100
- // {
- // index += 1;
- // events(["progress": index, "dataTag" : dataTag, "status" : 1])
- // Thread.sleep(forTimeInterval: 0.1)
- // if(index == 100){
- // events(["progress": index, "dataTag" : dataTag, "status" : 2])
- // }
- // }
- let util = ConvertUtil()
- let options = util.getConvertOptions(withArguments: arguments)
- util.convert(options: options, filePath: filePath, convertType: convertType) { progress, status, outputPath in
- events(["progress": progress, "dataTag" : dataTag, "status" : status])
-
- }
-
- }
- return nil
- }
- public func onCancel(withArguments arguments: Any?) -> FlutterError? {
- return nil
- }
-
- }
|