Rename variables
This commit is contained in:
parent
04233c8f1a
commit
3af9e768ae
|
@ -87,26 +87,26 @@ class MyForm extends StatefulWidget {
|
|||
|
||||
class MyFormState extends State<MyForm> {
|
||||
static final key = new GlobalKey<FormState>();
|
||||
StreamSubscription<bool> _statusEventSubscription;
|
||||
StreamSubscription<bool> _isConnectedEventSubscription;
|
||||
|
||||
@override
|
||||
initState() {
|
||||
super.initState();
|
||||
_statusEventSubscription =
|
||||
LokinetLib.statusEventStream.listen((bool status) => setState(() {}));
|
||||
_isConnectedEventSubscription = LokinetLib.isConnectedEventStream
|
||||
.listen((bool isConnected) => setState(() {}));
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
_statusEventSubscription?.cancel();
|
||||
_isConnectedEventSubscription?.cancel();
|
||||
}
|
||||
|
||||
Future toggleLokinet() async {
|
||||
if (!key.currentState.validate()) {
|
||||
return;
|
||||
}
|
||||
if (LokinetLib.status) {
|
||||
if (LokinetLib.isConnected) {
|
||||
await LokinetLib.disconnectFromLokinet();
|
||||
} else {
|
||||
//Save the exit node and upstream dns
|
||||
|
@ -185,13 +185,13 @@ class MyFormState extends State<MyForm> {
|
|||
Padding(
|
||||
padding: EdgeInsets.all(20),
|
||||
child: Text(
|
||||
LokinetLib.status ? "Connected" : "Not Connected",
|
||||
LokinetLib.isConnected ? "Connected" : "Not Connected",
|
||||
style: TextStyle(color: color),
|
||||
),
|
||||
),
|
||||
// TextButton(
|
||||
// onPressed: () async {
|
||||
// log((await LokinetLib.info).toString());
|
||||
// log((await LokinetLib.status).toString());
|
||||
// },
|
||||
// child: Text("Test"))
|
||||
],
|
||||
|
|
|
@ -53,22 +53,22 @@ public class LokinetDaemon extends VpnService {
|
|||
int m_FD = -1;
|
||||
int m_UDPSocket = -1;
|
||||
|
||||
private Timer mStatusCheckTimer;
|
||||
private MutableLiveData<Boolean> mStatus = new MutableLiveData<Boolean>();
|
||||
private Timer mUpdateIsConnectedTimer;
|
||||
private MutableLiveData<Boolean> isConnected = new MutableLiveData<Boolean>();
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
mStatus.postValue(false);
|
||||
mStatusCheckTimer = new Timer();
|
||||
mStatusCheckTimer.schedule(new CheckStatus(), 0, 500);
|
||||
isConnected.postValue(false);
|
||||
mUpdateIsConnectedTimer = new Timer();
|
||||
mUpdateIsConnectedTimer.schedule(new UpdateIsConnectedTask(), 0, 500);
|
||||
super.onCreate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
if (mStatusCheckTimer != null) {
|
||||
mStatusCheckTimer.cancel();
|
||||
mStatusCheckTimer = null;
|
||||
if (mUpdateIsConnectedTimer != null) {
|
||||
mUpdateIsConnectedTimer.cancel();
|
||||
mUpdateIsConnectedTimer = null;
|
||||
}
|
||||
|
||||
super.onDestroy();
|
||||
|
@ -117,7 +117,7 @@ public class LokinetDaemon extends VpnService {
|
|||
|
||||
@Override
|
||||
public void onRevoke() {
|
||||
mStatus.postValue(false);
|
||||
isConnected.postValue(false);
|
||||
super.onRevoke();
|
||||
}
|
||||
|
||||
|
@ -229,7 +229,7 @@ public class LokinetDaemon extends VpnService {
|
|||
} else {
|
||||
Log.d(LOG_TAG, "already running");
|
||||
}
|
||||
updateStatus();
|
||||
updateIsConnected();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -241,15 +241,15 @@ public class LokinetDaemon extends VpnService {
|
|||
// Free(impl);
|
||||
// impl = null;
|
||||
// }
|
||||
updateStatus();
|
||||
updateIsConnected();
|
||||
}
|
||||
|
||||
public MutableLiveData<Boolean> getStatus() {
|
||||
return mStatus;
|
||||
public MutableLiveData<Boolean> isConnected() {
|
||||
return isConnected;
|
||||
}
|
||||
|
||||
private void updateStatus() {
|
||||
mStatus.postValue(IsRunning() && VpnService.prepare(LokinetDaemon.this) == null);
|
||||
private void updateIsConnected() {
|
||||
isConnected.postValue(IsRunning() && VpnService.prepare(LokinetDaemon.this) == null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -269,9 +269,9 @@ public class LokinetDaemon extends VpnService {
|
|||
|
||||
private final IBinder mBinder = new LocalBinder();
|
||||
|
||||
private class CheckStatus extends TimerTask {
|
||||
private class UpdateIsConnectedTask extends TimerTask {
|
||||
public void run() {
|
||||
updateStatus();
|
||||
updateIsConnected();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -35,13 +35,13 @@ class LokinetLibPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
|
|||
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
|
||||
/// when the Flutter Engine is detached from the Activity
|
||||
private lateinit var mMethodChannel: MethodChannel
|
||||
private lateinit var mStatusEventChannel: EventChannel
|
||||
private lateinit var mIsConnectedEventChannel: EventChannel
|
||||
private var mEventSink: EventChannel.EventSink? = null
|
||||
|
||||
private var mStatusObserver =
|
||||
Observer<Boolean> { newStatus ->
|
||||
private var mIsConnectedObserver =
|
||||
Observer<Boolean> { newIsConnected ->
|
||||
// Propagate to the dart package.
|
||||
mEventSink?.success(newStatus)
|
||||
mEventSink?.success(newIsConnected)
|
||||
}
|
||||
|
||||
private var mLifecycleOwner =
|
||||
|
@ -57,9 +57,9 @@ class LokinetLibPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
|
|||
mMethodChannel = MethodChannel(binding.binaryMessenger, "lokinet_lib_method_channel")
|
||||
mMethodChannel.setMethodCallHandler(this)
|
||||
|
||||
mStatusEventChannel =
|
||||
EventChannel(binding.binaryMessenger, "lokinet_lib_status_event_channel")
|
||||
mStatusEventChannel.setStreamHandler(
|
||||
mIsConnectedEventChannel =
|
||||
EventChannel(binding.binaryMessenger, "lokinet_lib_is_connected_event_channel")
|
||||
mIsConnectedEventChannel.setStreamHandler(
|
||||
object : EventChannel.StreamHandler {
|
||||
override fun onListen(arguments: Any?, events: EventChannel.EventSink?) {
|
||||
mEventSink = events
|
||||
|
@ -150,7 +150,7 @@ class LokinetLibPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
|
|||
result.success(false)
|
||||
}
|
||||
}
|
||||
"getInfo" -> {
|
||||
"getStatus" -> {
|
||||
if (mBoundService != null) {
|
||||
result.success(mBoundService!!.DumpStatus())
|
||||
} else {
|
||||
|
@ -178,7 +178,7 @@ class LokinetLibPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
|
|||
override fun onServiceConnected(className: ComponentName, service: IBinder) {
|
||||
mBoundService = (service as LokinetDaemon.LocalBinder).getService()
|
||||
|
||||
mBoundService?.getStatus()?.observe(mLifecycleOwner, mStatusObserver)
|
||||
mBoundService?.isConnected()?.observe(mLifecycleOwner, mIsConnectedObserver)
|
||||
}
|
||||
|
||||
override fun onServiceDisconnected(className: ComponentName) {
|
||||
|
|
|
@ -9,19 +9,19 @@ class LokinetLib {
|
|||
static const MethodChannel _methodChannel =
|
||||
const MethodChannel('lokinet_lib_method_channel');
|
||||
|
||||
static const EventChannel _statusEventChannel =
|
||||
const EventChannel('lokinet_lib_status_event_channel');
|
||||
static const EventChannel _isConnectedEventChannel =
|
||||
const EventChannel('lokinet_lib_is_connected_event_channel');
|
||||
|
||||
static bool _status = false;
|
||||
static bool _isConnected = false;
|
||||
|
||||
static bool get status => _status;
|
||||
static bool get isConnected => _isConnected;
|
||||
|
||||
static Stream<bool> _statusEventStream = _statusEventChannel
|
||||
static Stream<bool> _isConnectedEventStream = _isConnectedEventChannel
|
||||
.receiveBroadcastStream()
|
||||
.cast<bool>()
|
||||
..listen((dynamic newStatus) => _status = newStatus);
|
||||
..listen((dynamic newIsConnected) => _isConnected = newIsConnected);
|
||||
|
||||
static Stream<bool> get statusEventStream => _statusEventStream;
|
||||
static Stream<bool> get isConnectedEventStream => _isConnectedEventStream;
|
||||
|
||||
static Future bootstrapLokinet() async {
|
||||
final request = await HttpClient()
|
||||
|
@ -72,7 +72,7 @@ class LokinetLib {
|
|||
}
|
||||
|
||||
static Future<dynamic> get info async {
|
||||
var status = await _methodChannel.invokeMethod('getInfo') as String;
|
||||
var status = await _methodChannel.invokeMethod('getStatus') as String;
|
||||
if (status.isNotEmpty) return jsonDecode(status);
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue