package com.vinno.flyinsono.next;

import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.BinaryMessenger;

import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import androidx.core.content.FileProvider

class MainActivity: FlutterActivity() {
    private val BackButtonChannelName = "android/back/desktop"

    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)
        // BackButtonChannel(flutterEngine.dartExecutor.binaryMessenger)  // 实例化通道
        MethodChannel(flutterEngine.dartExecutor.binaryMessenger, BackButtonChannelName).setMethodCallHandler { methodCall, result ->
            if (methodCall.method == "backDesktop") {
                result.success(true)
                moveTaskToBack(false)
            }
        }
    }
}
public class InstallerFileProvider : FileProvider() {
}
class BackButtonChannel(flutterEngine: BinaryMessenger): MethodChannel.MethodCallHandler {
    private val BackButtonChannelName = "android/back/desktop"
    private var channel: MethodChannel

    companion object {
        private const val TAG = "BackButtonChannel"
    }

    init {
        channel = MethodChannel(flutterEngine, BackButtonChannelName)
        channel.setMethodCallHandler(this)
    }

    override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
        //Log.d(TAG, "onMethodCall: " + call.method)
        if (call.method == "backDesktop") {
            result.success(true)
            //moveTaskToBack(false)
        } else {
            result.notImplemented()
        }
    }
}