Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions packages/devtools_app_shared/example/service_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ void main() async {
);

/// Example: Get a service extension state.
final performanceOverlayEnabled =
serviceManager.serviceExtensionManager.getServiceExtensionState(
extensions.performanceOverlay.extension,
);
final performanceOverlayEnabled = serviceManager.serviceExtensionManager
.getServiceExtensionState(extensions.performanceOverlay.extension);

// Example: Set a service extension state.
await serviceManager.serviceExtensionManager.setServiceExtensionState(
Expand Down
21 changes: 4 additions & 17 deletions packages/devtools_app_shared/example/ui/split_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ class SplitExample extends StatelessWidget {
axis: Axis.horizontal,
initialFractions: const [0.3, 0.7],
minSizes: const [50.0, 100.0],
children: const [
Text('Left side'),
Text('Right side'),
],
children: const [Text('Left side'), Text('Right side')],
);
}
}
Expand All @@ -42,15 +39,8 @@ class MultiSplitExample extends StatelessWidget {
axis: Axis.vertical,
initialFractions: const [0.3, 0.3, 0.4],
minSizes: const [50.0, 50.0, 100.0],
splitters: const [
CustomSplitter(),
CustomSplitter(),
],
children: const [
Text('Top'),
Text('Middle'),
Text('Bottom'),
],
splitters: const [CustomSplitter(), CustomSplitter()],
children: const [Text('Top'), Text('Middle'), Text('Bottom')],
);
}
}
Expand All @@ -62,10 +52,7 @@ class CustomSplitter extends StatelessWidget implements PreferredSizeWidget {

@override
Widget build(BuildContext context) {
return const SizedBox(
height: _size,
child: Icon(Icons.front_hand),
);
return const SizedBox(height: _size, child: Icon(Icons.front_hand));
}

@override
Expand Down
27 changes: 14 additions & 13 deletions packages/devtools_app_shared/lib/src/service/connected_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class ConnectedApp {
String? _operatingSystem;

// TODO(kenz): investigate if we can use `libraryUriAvailableNow` instead.
Future<bool> get isFlutterApp async => _isFlutterApp ??=
await serviceManager!.libraryUriAvailable(flutterLibraryUri);
Future<bool> get isFlutterApp async => _isFlutterApp ??= await serviceManager!
.libraryUriAvailable(flutterLibraryUri);

bool? get isFlutterAppNow {
assert(_isFlutterApp != null);
Expand Down Expand Up @@ -85,8 +85,8 @@ class ConnectedApp {
bool? _isProfileBuild;

// TODO(kenz): investigate if we can use `libraryUriAvailableNow` instead.
Future<bool> get isDartWebApp async => _isDartWebApp ??=
await serviceManager!.libraryUriAvailable(dartHtmlLibraryUri);
Future<bool> get isDartWebApp async => _isDartWebApp ??= await serviceManager!
.libraryUriAvailable(dartHtmlLibraryUri);

bool? get isDartWebAppNow {
assert(_isDartWebApp != null);
Expand Down Expand Up @@ -189,14 +189,14 @@ class ConnectedApp {
}

Map<String, Object?> toJson() => {
isFlutterAppKey: isFlutterAppNow,
isProfileBuildKey: isProfileBuildNow,
isDartWebAppKey: isDartWebAppNow,
isRunningOnDartVMKey: isRunningOnDartVM,
operatingSystemKey: operatingSystem,
if (flutterVersionNow != null && !flutterVersionNow!.unknown)
flutterVersionKey: flutterVersionNow!.version,
};
isFlutterAppKey: isFlutterAppNow,
isProfileBuildKey: isProfileBuildNow,
isDartWebAppKey: isDartWebAppNow,
isRunningOnDartVMKey: isRunningOnDartVM,
operatingSystemKey: operatingSystem,
if (flutterVersionNow != null && !flutterVersionNow!.unknown)
flutterVersionKey: flutterVersionNow!.version,
};
}

final class OfflineConnectedApp extends ConnectedApp {
Expand All @@ -215,7 +215,8 @@ final class OfflineConnectedApp extends ConnectedApp {
isProfileBuildNow: json[ConnectedApp.isProfileBuildKey] as bool?,
isDartWebAppNow: json[ConnectedApp.isDartWebAppKey] as bool?,
isRunningOnDartVM: json[ConnectedApp.isRunningOnDartVMKey] as bool?,
operatingSystem: (json[ConnectedApp.operatingSystemKey] as String?) ??
operatingSystem:
(json[ConnectedApp.operatingSystemKey] as String?) ??
ConnectedApp.unknownOS,
);
}
Expand Down
52 changes: 31 additions & 21 deletions packages/devtools_app_shared/lib/src/service/dtd_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ class DTDManager {

/// The current state of the connection.
ValueListenable<DTDConnectionState> get connectionState => _connectionState;
final _connectionState =
ValueNotifier<DTDConnectionState>(NotConnectedDTDState());
final _connectionState = ValueNotifier<DTDConnectionState>(
NotConnectedDTDState(),
);

/// The URI of the current DTD connection.
Uri? get uri => _uri;
Expand Down Expand Up @@ -77,13 +78,15 @@ class DTDManager {
//
// If this happens, just disconnect (without disabling reconnect) so the
// done event fires and then the usual handling occurs.
_periodicConnectionCheck =
Timer.periodic(_periodicConnectionCheckInterval, (timer) async {
if (_dtd.isClosed) {
_log.warning('The DTD connection has dropped');
await disconnectImpl(allowReconnect: true);
}
});
_periodicConnectionCheck = Timer.periodic(
_periodicConnectionCheckInterval,
(timer) async {
if (_dtd.isClosed) {
_log.warning('The DTD connection has dropped');
await disconnectImpl(allowReconnect: true);
}
},
);

return dtd;
}
Expand Down Expand Up @@ -182,12 +185,16 @@ class DTDManager {
// If a connection drops (and we hadn't disabled auto-reconnect, such
// as by explicitly calling disconnect/dispose), we should attempt to
// reconnect.
unawaited(connection.done
.then((_) => _reconnectAfterDroppedConnection(uri, onError: onError))
.catchError((_) {
// TODO(dantup): Create a devtools_app_shared version of safeUnawaited.
// https://github.com/flutter/devtools/pull/9587#discussion_r2624306047
}));
unawaited(
connection.done
.then(
(_) => _reconnectAfterDroppedConnection(uri, onError: onError),
)
.catchError((_) {
// TODO(dantup): Create a devtools_app_shared version of safeUnawaited.
// https://github.com/flutter/devtools/pull/9587#discussion_r2624306047
}),
);
} catch (e, st) {
onError?.call(e, st);
}
Expand Down Expand Up @@ -229,8 +236,8 @@ class DTDManager {
}) {
// On explicit connections, we capture the connect function so that we
// can call it again if [reconnect()] is called.
final connectFunc = _lastConnectFunc =
() => _connectImpl(uri, onError: onError, maxRetries: maxRetries);
final connectFunc = _lastConnectFunc = () =>
_connectImpl(uri, onError: onError, maxRetries: maxRetries);
return connectFunc();
}

Expand Down Expand Up @@ -284,15 +291,18 @@ class DTDManager {

/// Listens for service registration events on the [dtd] connection.
Future<void> _listenForServiceRegistrationEvents(
DartToolingDaemon dtd) async {
DartToolingDaemon dtd,
) async {
// We immediately begin listening for service registration events on the new
// DTD connection before canceling the previous subscription. This
// guarantees that we don't miss any events across reconnects.
// ignore: cancel_subscriptions, false positive, it is canceled below.
final nextServiceRegistrationSubscription = dtd
.onEvent(CoreDtdServiceConstants.servicesStreamId)
.listen(_forwardServiceRegistrationEvents,
onError: _logServiceStreamError);
.listen(
_forwardServiceRegistrationEvents,
onError: _logServiceStreamError,
);
await dtd.streamListen(CoreDtdServiceConstants.servicesStreamId);

// Cancel the previous subscription.
Expand All @@ -307,7 +317,7 @@ class DTDManager {
final kind = event.kind;
final isRegistrationEvent =
kind == CoreDtdServiceConstants.serviceRegisteredKind ||
kind == CoreDtdServiceConstants.serviceUnregisteredKind;
kind == CoreDtdServiceConstants.serviceUnregisteredKind;

if (isRegistrationEvent) {
_serviceRegistrationController.add(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ class EvalOnDartLibrary extends DisposableController
}

try {
final isolate =
await serviceManager.isolateManager.isolateState(isolateRef).isolate;
final isolate = await serviceManager.isolateManager
.isolateState(isolateRef)
.isolate;
if (_currentRequestId != requestId) {
// The initialize request is obsolete.
return;
Expand Down Expand Up @@ -150,11 +151,7 @@ class EvalOnDartLibrary extends DisposableController
}
return await addRequest<InstanceRef?>(
isAlive,
() => _eval(
expression,
scope: scope,
shouldLogError: shouldLogError,
),
() => _eval(expression, scope: scope, shouldLogError: shouldLogError),
);
}

Expand Down Expand Up @@ -626,12 +623,14 @@ class EvalOnDartLibrary extends DisposableController
int? count,
}) {
return addRequest<T>(isAlive, () async {
final T value = await service.getObject(
_isolateRef!.id!,
instance.id!,
offset: offset,
count: count,
) as T;
final T value =
await service.getObject(
_isolateRef!.id!,
instance.id!,
offset: offset,
count: count,
)
as T;
return value;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ final class FlutterVersion extends SemanticVersion {

@override
int get hashCode => Object.hash(
version,
channel,
repositoryUrl,
frameworkRevision,
frameworkCommitDate,
engineRevision,
dartSdkVersion,
);
version,
channel,
repositoryUrl,
frameworkRevision,
frameworkCommitDate,
engineRevision,
dartSdkVersion,
);

static final _stableVersionRegex = RegExp(r'^\d+\.\d+\.\d+$');
static final _isNumericRegex = RegExp(r'\d');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class IsolateState {
void handleIsolateLoad(Isolate isolate) {
_isolateNow = isolate;

_isPaused.value = isolate.pauseEvent != null &&
_isPaused.value =
isolate.pauseEvent != null &&
isolate.pauseEvent!.kind != EventKind.kResume;

rootInfo = RootInfo(_isolateNow!.rootLib?.uri);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ final class ResolvedUriManager {
Future<void> fetchPackageUris(String isolateId, List<String> uris) async {
if (uris.isEmpty) return;
if (_packagePathMappings != null) {
final packageUris =
(await _service!.lookupPackageUris(isolateId, uris)).uris;
final packageUris = (await _service!.lookupPackageUris(
isolateId,
uris,
)).uris;

if (packageUris != null) {
_packagePathMappings!.addMappings(
Expand All @@ -54,9 +56,10 @@ final class ResolvedUriManager {
/// * [packageUris] - List of URIs to fetch full file paths for.
Future<void> fetchFileUris(String isolateId, List<String> packageUris) async {
if (_packagePathMappings != null) {
final fileUris =
(await _service!.lookupResolvedPackageUris(isolateId, packageUris))
.uris;
final fileUris = (await _service!.lookupResolvedPackageUris(
isolateId,
packageUris,
)).uris;

// [_packagePathMappings] could have been set to null during the async gap
// so check that it is non-null again here.
Expand Down Expand Up @@ -95,15 +98,11 @@ class _PackagePathMappings {
String? lookupPackageToFullPathMapping(
String isolateId,
String packagePath,
) =>
_isolatePackageToFullPathMappings[isolateId]?[packagePath];
) => _isolatePackageToFullPathMappings[isolateId]?[packagePath];

/// Returns the full path to package path mapping if it has already
/// been fetched.
String? lookupFullPathToPackageMapping(
String isolateId,
String fullPath,
) =>
String? lookupFullPathToPackageMapping(String isolateId, String fullPath) =>
_isolateFullPathToPackageMappings[isolateId]?[fullPath];

/// Saves the mappings of [fullPaths] to [packagePaths].
Expand All @@ -118,16 +117,10 @@ class _PackagePathMappings {
required List<String?> packagePaths,
}) {
assert(fullPaths.length == packagePaths.length);
final fullPathToPackageMappings =
_isolateFullPathToPackageMappings.putIfAbsent(
isolateId,
() => <String, String?>{},
);
final packageToFullPathMappings =
_isolatePackageToFullPathMappings.putIfAbsent(
isolateId,
() => <String, String?>{},
);
final fullPathToPackageMappings = _isolateFullPathToPackageMappings
.putIfAbsent(isolateId, () => <String, String?>{});
final packageToFullPathMappings = _isolatePackageToFullPathMappings
.putIfAbsent(isolateId, () => <String, String?>{});

assert(fullPaths.length == packagePaths.length);

Expand Down
Loading
Loading