Add enableHotkeys + prompt
This commit is contained in:
parent
e6e0eae332
commit
8cbfb713bd
2 changed files with 26 additions and 2 deletions
|
@ -14,7 +14,8 @@ import 'dart:io'
|
||||||
Link,
|
Link,
|
||||||
Platform,
|
Platform,
|
||||||
exit,
|
exit,
|
||||||
stderr;
|
stderr,
|
||||||
|
stdout;
|
||||||
import 'dart:isolate';
|
import 'dart:isolate';
|
||||||
import 'package:angel_framework/angel_framework.dart';
|
import 'package:angel_framework/angel_framework.dart';
|
||||||
import 'package:angel_websocket/server.dart';
|
import 'package:angel_websocket/server.dart';
|
||||||
|
@ -23,6 +24,7 @@ import 'package:dart2_constant/io.dart';
|
||||||
import 'package:glob/glob.dart';
|
import 'package:glob/glob.dart';
|
||||||
import 'package:html_builder/elements.dart';
|
import 'package:html_builder/elements.dart';
|
||||||
import 'package:html_builder/html_builder.dart';
|
import 'package:html_builder/html_builder.dart';
|
||||||
|
import 'package:io/ansi.dart';
|
||||||
import 'package:vm_service_lib/vm_service_lib.dart' as vm;
|
import 'package:vm_service_lib/vm_service_lib.dart' as vm;
|
||||||
import 'package:vm_service_lib/vm_service_lib_io.dart' as vm;
|
import 'package:vm_service_lib/vm_service_lib_io.dart' as vm;
|
||||||
import 'package:watcher/watcher.dart';
|
import 'package:watcher/watcher.dart';
|
||||||
|
@ -40,6 +42,11 @@ class HotReloader {
|
||||||
Duration _timeout;
|
Duration _timeout;
|
||||||
vm.VM _vmachine;
|
vm.VM _vmachine;
|
||||||
|
|
||||||
|
/// If `true` (default), then developers can `press 'r' to reload` the application on-the-fly.
|
||||||
|
///
|
||||||
|
/// This option triggers printing a Flutter-like output to the terminal.
|
||||||
|
final bool enableHotkeys;
|
||||||
|
|
||||||
/// Invoked to load a new instance of [Angel] on file changes.
|
/// Invoked to load a new instance of [Angel] on file changes.
|
||||||
final FutureOr<Angel> Function() generator;
|
final FutureOr<Angel> Function() generator;
|
||||||
|
|
||||||
|
@ -70,7 +77,8 @@ class HotReloader {
|
||||||
HotReloader(this.generator, Iterable paths,
|
HotReloader(this.generator, Iterable paths,
|
||||||
{Duration timeout,
|
{Duration timeout,
|
||||||
this.vmServiceHost: 'localhost',
|
this.vmServiceHost: 'localhost',
|
||||||
this.vmServicePort: 8181}) {
|
this.vmServicePort: 8181,
|
||||||
|
this.enableHotkeys: true}) {
|
||||||
_timeout = timeout ?? new Duration(seconds: 5);
|
_timeout = timeout ?? new Duration(seconds: 5);
|
||||||
_paths.addAll(paths ?? []);
|
_paths.addAll(paths ?? []);
|
||||||
}
|
}
|
||||||
|
@ -166,6 +174,20 @@ class HotReloader {
|
||||||
while (!_requestQueue.isEmpty) await _handle(_requestQueue.removeFirst());
|
while (!_requestQueue.isEmpty) await _handle(_requestQueue.removeFirst());
|
||||||
var server = await HttpServer.bind(address ?? '127.0.0.1', port ?? 0);
|
var server = await HttpServer.bind(address ?? '127.0.0.1', port ?? 0);
|
||||||
server.listen(handleRequest);
|
server.listen(handleRequest);
|
||||||
|
|
||||||
|
// Print a Flutter-like prompt...
|
||||||
|
if (enableHotkeys) {
|
||||||
|
var host = vmServiceHost == 'localhost' ? '127.0.0.1' : vmServiceHost;
|
||||||
|
var observatoryUri =
|
||||||
|
new Uri(scheme: 'http', host: host, port: vmServicePort);
|
||||||
|
print(styleBold.wrap(
|
||||||
|
'🔥 To hot reload changes while running, press "r". To hot restart (and rebuild state), press "R".'));
|
||||||
|
stdout.write(
|
||||||
|
'An Observatory debugger and profiler on iPhone XS Max is available at: ');
|
||||||
|
print(wrapWith('$observatoryUri', [cyan, styleUnderlined]));
|
||||||
|
print('To quit, press "q".');
|
||||||
|
}
|
||||||
|
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,6 +262,7 @@ class HotReloader {
|
||||||
if (old != null) {
|
if (old != null) {
|
||||||
// Do this asynchronously, because we really don't care about the old server anymore.
|
// Do this asynchronously, because we really don't care about the old server anymore.
|
||||||
new Future(() async {
|
new Future(() async {
|
||||||
|
// TODO: Instead of disconnecting, just forward websockets to the next server.
|
||||||
// Disconnect active WebSockets
|
// Disconnect active WebSockets
|
||||||
var ws = old.app.container.make(AngelWebSocket) as AngelWebSocket;
|
var ws = old.app.container.make(AngelWebSocket) as AngelWebSocket;
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ dependencies:
|
||||||
angel_websocket: ^2.0.0-alpha
|
angel_websocket: ^2.0.0-alpha
|
||||||
glob: ^1.0.0
|
glob: ^1.0.0
|
||||||
html_builder: ^1.0.0
|
html_builder: ^1.0.0
|
||||||
|
io: ^0.3.2
|
||||||
vm_service_lib: ^0.3.5
|
vm_service_lib: ^0.3.5
|
||||||
watcher: ^0.9.0
|
watcher: ^0.9.0
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
|
|
Loading…
Reference in a new issue