package com.example.modifier.utils

import android.content.Context
import android.content.Intent
import com.example.modifier.Utils

fun isClashInstalled(context: Context): Boolean {
    val packageManager = context.packageManager
    return try {
        packageManager.getPackageInfo("com.github.metacubex.clash.meta", 0)
        true
    } catch (e: Exception) {
        false
    }
}

fun stopClash() {
    try {
        val context = getContext()
        val intent = Intent()
        intent.action = "com.github.metacubex.clash.meta.action.STOP_CLASH"
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        context.startActivity(intent)
    } catch (e: Exception) {
        e.printStackTrace()
    }
}

fun changeClashProfile(name: String, base64: String) {
    try {
        val context = getContext()
        val intent = Intent()
        intent.action = "com.github.metacubex.clash.meta.action.USE_PROFILE"
        intent.putExtra("base64", base64)
        intent.putExtra("name", name)
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        context.startActivity(intent)
    } catch (e: Exception) {
        e.printStackTrace()
    }
}