Unverified Commit 95217eb7 authored by Lau Ching Jun's avatar Lau Ching Jun Committed by GitHub

Add new hook for setupHotReload and after updating devFS is complete (#87532)

* Add new hook for setupHotReload and after updating devFS is complete

* Handle the case where updateDevFS failed
parent 788aea4b
...@@ -52,6 +52,18 @@ class HotRunnerConfig { ...@@ -52,6 +52,18 @@ class HotRunnerConfig {
Future<bool> setupHotRestart() async { Future<bool> setupHotRestart() async {
return true; return true;
} }
/// A hook for implementations to perform any necessary initialization prior
/// to a hot reload. Should return true if the hot restart should continue.
Future<bool> setupHotReload() async {
return true;
}
/// A hook for implementations to perform any necessary cleanup after the
/// devfs sync is complete. At this point the flutter_tools no longer needs to
/// access the source files and assets.
void updateDevFSComplete() {}
/// A hook for implementations to perform any necessary operations right /// A hook for implementations to perform any necessary operations right
/// before the runner is about to be shut down. /// before the runner is about to be shut down.
Future<void> runPreShutdownOperations() async { Future<void> runPreShutdownOperations() async {
...@@ -546,7 +558,12 @@ class HotRunner extends ResidentRunner { ...@@ -546,7 +558,12 @@ class HotRunner extends ResidentRunner {
String reason, String reason,
}) async { }) async {
final Stopwatch restartTimer = Stopwatch()..start(); final Stopwatch restartTimer = Stopwatch()..start();
final UpdateFSReport updatedDevFS = await _updateDevFS(fullRestart: true); UpdateFSReport updatedDevFS;
try {
updatedDevFS = await _updateDevFS(fullRestart: true);
} finally {
hotRunnerConfig.updateDevFSComplete();
}
if (!updatedDevFS.success) { if (!updatedDevFS.success) {
for (final FlutterDevice device in flutterDevices) { for (final FlutterDevice device in flutterDevices) {
if (device.generator != null) { if (device.generator != null) {
...@@ -857,8 +874,16 @@ class HotRunner extends ResidentRunner { ...@@ -857,8 +874,16 @@ class HotRunner extends ResidentRunner {
} }
final Stopwatch reloadTimer = _stopwatchFactory.createStopwatch('reloadSources:reload')..start(); final Stopwatch reloadTimer = _stopwatchFactory.createStopwatch('reloadSources:reload')..start();
if (!(await hotRunnerConfig.setupHotReload())) {
return OperationResult(1, 'setupHotReload failed');
}
final Stopwatch devFSTimer = Stopwatch()..start(); final Stopwatch devFSTimer = Stopwatch()..start();
final UpdateFSReport updatedDevFS = await _updateDevFS(); UpdateFSReport updatedDevFS;
try {
updatedDevFS= await _updateDevFS();
} finally {
hotRunnerConfig.updateDevFSComplete();
}
// Record time it took to synchronize to DevFS. // Record time it took to synchronize to DevFS.
bool shouldReportReloadTime = true; bool shouldReportReloadTime = true;
_addBenchmarkData('hotReloadDevFSSyncMilliseconds', devFSTimer.elapsed.inMilliseconds); _addBenchmarkData('hotReloadDevFSSyncMilliseconds', devFSTimer.elapsed.inMilliseconds);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment