Skip to content

Commit

Permalink
[Improve] rename flutterHotRestart to flutterRestart to be more clear
Browse files Browse the repository at this point in the history
  • Loading branch information
chipweinberger committed Apr 23, 2024
1 parent 9dbf29b commit b7c3101
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ This release simplifies BluetoothDevice construction.

## 1.15.10
* **[Fix]** iOS: `localName` does not match Android (bug in original `flutter_blue`)
* **[Fix]** flutterHotRestart: error was thrown if device did not have bluetooth adapter (regression in 1.14.19)
* **[Fix]** flutterRestart: error was thrown if device did not have bluetooth adapter (regression in 1.14.19)

## 1.15.9
* **[Fix]** iOS: adapter turnOff: edge case when adapter is turned off while scanning (bug in original `flutter_blue`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public void onMethodCall(@NonNull MethodCall call,
// check that we have an adapter, except for
// the functions that do not need it
if(mBluetoothAdapter == null &&
"flutterHotRestart".equals(call.method) == false &&
"flutterRestart".equals(call.method) == false &&
"connectedCount".equals(call.method) == false &&
"setLogLevel".equals(call.method) == false &&
"isSupported".equals(call.method) == false &&
Expand All @@ -294,7 +294,7 @@ public void onMethodCall(@NonNull MethodCall call,

switch (call.method) {

case "flutterHotRestart":
case "flutterRestart":
{
// no adapter?
if (mBluetoothAdapter == null) {
Expand All @@ -309,7 +309,9 @@ public void onMethodCall(@NonNull MethodCall call,
mIsScanning = false;
}

disconnectAllDevices("flutterHotRestart");
// all dart state is reset after flutter restart
// (i.e. Hot Restart) so also reset native state
disconnectAllDevices("flutterRestart");

log(LogLevel.DEBUG, "connectedPeripherals: " + mConnectedDevices.size());

Expand Down
10 changes: 6 additions & 4 deletions ios/Classes/FlutterBluePlusPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
// check that we have an adapter, except for the
// functions that don't need it
if (self.centralManager == nil &&
[@"flutterHotRestart" isEqualToString:call.method] == false &&
[@"flutterRestart" isEqualToString:call.method] == false &&
[@"connectedCount" isEqualToString:call.method] == false &&
[@"setLogLevel" isEqualToString:call.method] == false &&
[@"isSupported" isEqualToString:call.method] == false &&
Expand All @@ -150,7 +150,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
return;
}

if ([@"flutterHotRestart" isEqualToString:call.method])
if ([@"flutterRestart" isEqualToString:call.method])
{
// no adapter?
if (self.centralManager == nil) {
Expand All @@ -162,7 +162,9 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
[self.centralManager stopScan];
}

[self disconnectAllDevices:@"flutterHotRestart"];
// all dart state is reset after flutter restart
// (i.e. Hot Restart) so also reset native state
[self disconnectAllDevices:@"flutterRestart"];

Log(LDEBUG, @"connectedPeripherals: %lu", self.connectedPeripherals.count);

Expand Down Expand Up @@ -936,7 +938,7 @@ - (void)disconnectAllDevices:(NSString*)func
[self.methodChannel invokeMethod:@"OnConnectionStateChanged" arguments:result];
}

if ([func isEqualToString:@"flutterHotRestart"] && [self isAdapterOn]) {
if ([func isEqualToString:@"flutterRestart"] && [self isAdapterOn]) {
// request disconnection
[self.centralManager cancelPeripheralConnection:peripheral];
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/bluetooth_device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class BluetoothDevice {
}

/// Register a subscription to be canceled when the device is disconnected.
/// This function simplifies cleanup, to prevent creating duplicate stream subscriptions.
/// This function simplifies cleanup, so you can prevent creating duplicate stream subscriptions.
/// - this is an optional convenience function
/// - prevents accidentally creating duplicate subscriptions on each reconnection.
/// - [next] if true, the the stream will be canceled only on the *next* disconnection.
Expand Down
6 changes: 3 additions & 3 deletions lib/src/flutter_blue_plus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ class FlutterBluePlus {
}

/// Register a subscription to be canceled when scanning is complete.
/// This function simplifies cleanup, to prevent creating duplicate stream subscriptions.
/// This function simplifies cleanup, so you can prevent creating duplicate stream subscriptions.
/// - this is an optional convenience function
/// - prevents accidentally creating duplicate subscriptions before each scan
static void cancelWhenScanComplete(StreamSubscription subscription) {
Expand Down Expand Up @@ -412,8 +412,8 @@ class FlutterBluePlus {
// set platform method handler
_methodChannel.setMethodCallHandler(_methodCallHandler);

// hot restart
if ((await _methodChannel.invokeMethod('flutterHotRestart')) != 0) {
// flutter restart - wait for all devices to disconnect
if ((await _methodChannel.invokeMethod('flutterRestart')) != 0) {
await Future.delayed(Duration(milliseconds: 50));
while ((await _methodChannel.invokeMethod('connectedCount')) != 0) {
await Future.delayed(Duration(milliseconds: 50));
Expand Down

0 comments on commit b7c3101

Please sign in to comment.