OmerAti adlı üyeden alıntı: mesajı görüntüle
TunnelService.kt:
  • İşlev stopRunner(), VPN hizmetini durdurmaktan soruml
  • Uygulama, VPN bağlantısının kesilmesini istediğinde çağrılır.
  • Ayrıca, VPN bağlantısı başlatılamadığında da çağrılır.
AppModel.dart:
  • İşlev togglePowerButton(), VPN bağlantısını değiştirmekten sorumludur.
  • Mevcut VPN durumunu kontrol ediyor ve bağlanıp bağlanmamaya karar veriyor
class TunnelService : VpnService() {
    override fun onRevoke() {
        stopRunner(true) // Revoke the VPN connection and restart the service if needed
    }

    private fun stopRunner(restart: Boolean = false, msg: String? = null) {
        if (data.state == VpnState.State.Stopping) return
            data.changeState(VpnState.State.Stopping)
        GlobalScope.launch(Dispatchers.Main.immediate) {
            data.connectingJob?.cancelAndJoin() // Ensure stop connecting first
            coroutineScope {
                killProcesses(this)
            }
            data.changeState(VpnState.State.Stopped, msg)
            if (restart) startRunner() else {
                stopSelf()
            }
        }
    }

    private fun killProcesses(scope: CoroutineScope) {
        data.proxy?.run {
            shutdown(scope)
            data.proxy = null
        }
        data.localDns?.shutdown(scope)
        data.localDns = null

        active = false
        scope.launch { DefaultNetworkListener.stop(this) }
        pfd?.close()
        pfd = null
    }
}
class AppModel extends BaseModel {

    void togglePowerButton() async {
        if (vpnStatus == VpnStatus.connecting) {
            Fluttertoast.showToast(
                msg: "Bağlanıyor, lütfen bekleyin...",
                toastLength: Toast.LENGTH_SHORT,
                gravity: ToastGravity.CENTER,
                timeInSecForIosWeb: 2,
                textColor: Colors.white,
                fontSize: 14.0,
            );
            return;
        }

        if (vpnStatus == VpnStatus.disconnecting) {
            Fluttertoast.showToast(
                msg: "Bağlantı kesiliyor, lütfen bekleyin...",
                toastLength: Toast.LENGTH_SHORT,
                gravity: ToastGravity.CENTER,
                timeInSecForIosWeb: 2,
                textColor: Colors.white,
                fontSize: 14.0,
            );
            return;
        }

        if (vpnStatus == VpnStatus.connected) {
            vpnStatus = VpnStatus.disconnecting;
        } else if (vpnStatus == VpnStatus.disconnected) {
            vpnStatus = VpnStatus.connecting;
        }

        await vpnManager.toggle();

        notifyListeners();
    }

}
kodunuzda ufak bir güncelleme yaptim gerektigi gibi degiştirin istediginiz sonucu alabilirsiniz
Öncelikle yardımınız için çok teşekkür ederim. kodları ilgili yere tam uyarlayamadım sanırım. size gönderdiğim kodlar üzerinden revize edip yollamanız mümkün mü acaba.