Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hot reload and hot restart buttons to the simulated devtools environment #6275

Merged
merged 3 commits into from
Aug 29, 2023
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
3 changes: 3 additions & 0 deletions packages/devtools_extensions/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.0.3-wip
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not dev? What is the difference?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe wip indicates a package that is not yet published, but I don't think it is enforced.
@jonasfj are there official pub guidelines around how you should version an unpublished package?

Copy link
Member

@jonasfj jonasfj Aug 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not from pub, there are no guidelines.

For external package maintenance the Dart team generally follows:
https://github.com/dart-lang/sdk/wiki/External-Package-Maintenance#publishing-a-package

I didn't write it, and I'll admit I sometimes fail to follow it, but I like the idea of using a -wip to denote the fact that the version haven't been published yet.


From a pub-perspective, if a package isn't intended to be published, then please add:

publish_to: none  # Do not publish this package, because: ...

If you know that you intend to publish this package soon, but isn't ready yet, please consider publishing a dummy package as version 0.0.1, don't care if it's empty and ugly -- just reserve the package name. It's a mess if someone sees the package you're developing, can't wait to try it and decides to publish it for you -- this happens when people are experimenting 🤣

* Add hot reload and hot restart actions to the simulated DevTools environment.

## 0.0.2
* Add a simulated DevTools environment that for easier development.
* Add a `build_and_copy` command to build a devtools extension and copy the output to the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class _SimulatedDevToolsController extends DisposableController
implements DevToolsExtensionHostInterface {
/// Logs of the post message communication that goes back and forth between
/// the extension and the simulated DevTools environment.
final messageLogs = ListValueNotifier<_PostMessageLogEntry>([]);
final messageLogs = ListValueNotifier<_MessageLogEntry>([]);

void init() {
html.window.addEventListener('message', _handleMessage);
Expand Down Expand Up @@ -65,8 +65,8 @@ class _SimulatedDevToolsController extends DisposableController
void Function()? onUnknownEvent,
}) {
messageLogs.add(
_PostMessageLogEntry(
source: _PostMessageSource.extension,
_MessageLogEntry(
source: _MessageSource.extension,
data: event.toJson(),
),
);
Expand All @@ -82,26 +82,48 @@ class _SimulatedDevToolsController extends DisposableController
html.window.origin!,
);
messageLogs.add(
_PostMessageLogEntry(
source: _PostMessageSource.devtools,
_MessageLogEntry(
source: _MessageSource.devtools,
data: eventJson,
),
);
}

Future<void> hotReloadConnectedApp() async {
await serviceManager.performHotReload();
messageLogs.add(
_MessageLogEntry(
source: _MessageSource.info,
message: 'Hot reload performed on connected app',
),
);
}

Future<void> hotRestartConnectedApp() async {
await serviceManager.performHotRestart();
messageLogs.add(
_MessageLogEntry(
source: _MessageSource.info,
message: 'Hot restart performed on connected app',
),
);
}
}

class _PostMessageLogEntry {
_PostMessageLogEntry({required this.source, required this.data})
class _MessageLogEntry {
_MessageLogEntry({required this.source, this.data, this.message})
: timestamp = DateTime.now();

final _PostMessageSource source;
final Map<String, Object?> data;
final _MessageSource source;
final Map<String, Object?>? data;
final String? message;
final DateTime timestamp;
}

enum _PostMessageSource {
enum _MessageSource {
devtools,
extension;
extension,
info;

String get display {
return name.toUpperCase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,35 @@ class _SimulatedApi extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
return Column(
children: [
DevToolsButton(
label: 'PING',
onPressed: simController.ping,
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
DevToolsButton(
label: 'PING',
onPressed: simController.ping,
),
// TODO(kenz): add buttons for other simulated events as the extension
// API expands.
],
),
const SizedBox(height: defaultSpacing),
Row(
children: [
DevToolsButton(
icon: Icons.bolt,
tooltip: 'Hot reload connected app',
onPressed: simController.hotReloadConnectedApp,
),
const SizedBox(width: denseSpacing),
DevToolsButton(
icon: Icons.replay,
tooltip: 'Hot restart connected app',
onPressed: simController.hotRestartConnectedApp,
),
],
),
// TODO(kenz): add buttons for other simulated events as the extension
// API expands.
],
);
}
Expand Down Expand Up @@ -205,9 +225,11 @@ class _LogMessagesState extends State<_LogMessages> {
'[${log.timestamp.toString()}] from ${log.source.display}',
style: theme.fixedFontStyle,
),
FormattedJson(
json: log.data,
),
if (log.message != null) Text(log.message!),
if (log.data != null)
FormattedJson(
json: log.data,
),
],
),
);
Expand Down
2 changes: 1 addition & 1 deletion packages/devtools_extensions/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: devtools_extensions
description: A package for building and supporting extensions for Dart DevTools.
version: 0.0.2
version: 0.0.3-wip
repository: https://github.com/flutter/devtools/tree/master/packages/devtools_extensions

environment:
Expand Down