mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Switch from using app.progress to app.webLaunchUrl for passing web launch urls (#44268)
* Switch from using app.progress to app.url for passing web launch urls * Update daemon.md * Change app.url -> app.webLaunchUrl * Add tests for app.webLaunchUrl event * Update tests with recent changes after rebasing
This commit is contained in:
parent
af48f71497
commit
81f6ba84b9
@ -60,7 +60,7 @@ The `version()` command responds with a String with the protocol version.
|
|||||||
|
|
||||||
The `shutdown()` command will terminate the flutter daemon. It is not necessary to call this before shutting down the daemon; it is perfectly acceptable to just kill the daemon process.
|
The `shutdown()` command will terminate the flutter daemon. It is not necessary to call this before shutting down the daemon; it is perfectly acceptable to just kill the daemon process.
|
||||||
|
|
||||||
### daemon.getSupportedPlatforms
|
#### daemon.getSupportedPlatforms
|
||||||
|
|
||||||
The `getSupportedPlatforms()` command will enumerate all platforms supported by the project located at the provided `projectRoot`. It returns a Map with the key 'platforms' containing a List of strings which describe the set of all possibly supported platforms. Possible values include:
|
The `getSupportedPlatforms()` command will enumerate all platforms supported by the project located at the provided `projectRoot`. It returns a Map with the key 'platforms' containing a List of strings which describe the set of all possibly supported platforms. Possible values include:
|
||||||
- android
|
- android
|
||||||
@ -153,6 +153,10 @@ This is sent when an operation starts and again when it stops. When an operation
|
|||||||
|
|
||||||
This is sent when an app is stopped or detached from. The `params` field will be a map with the field `appId`.
|
This is sent when an app is stopped or detached from. The `params` field will be a map with the field `appId`.
|
||||||
|
|
||||||
|
#### app.webLaunchUrl
|
||||||
|
|
||||||
|
This is sent once a web application is being served and available for the user to access. The `params` field will be a map with a string `url` field and a boolean `launched` indicating whether the application has already been launched in a browser (this will generally be true for a browser device unless `--no-web-browser-launch` was used, and false for the headless `web-server` device).
|
||||||
|
|
||||||
### device domain
|
### device domain
|
||||||
|
|
||||||
#### device.getDevices
|
#### device.getDevices
|
||||||
|
@ -147,13 +147,11 @@ abstract class Logger {
|
|||||||
int progressIndicatorPadding = kDefaultStatusPadding,
|
int progressIndicatorPadding = kDefaultStatusPadding,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Send a progress notification that is instant.
|
/// Send an event to be emitted.
|
||||||
///
|
///
|
||||||
/// Only surfaces a value in machine modes, Loggers may ignore this message in
|
/// Only surfaces a value in machine modes, Loggers may ignore this message in
|
||||||
/// non-machine modes. Like [startProgress] but with a single event.
|
/// non-machine modes.
|
||||||
void sendNotification(String message, {
|
void sendEvent(String name, [Map<String, dynamic> args]) { }
|
||||||
String progressId,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class StdoutLogger extends Logger {
|
class StdoutLogger extends Logger {
|
||||||
@ -260,7 +258,7 @@ class StdoutLogger extends Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void sendNotification(String message, {String progressId}) { }
|
void sendEvent(String name, [Map<String, dynamic> args]) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A [StdoutLogger] which replaces Unicode characters that cannot be printed to
|
/// A [StdoutLogger] which replaces Unicode characters that cannot be printed to
|
||||||
@ -354,7 +352,7 @@ class BufferLogger extends Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void sendNotification(String message, {String progressId}) { }
|
void sendEvent(String name, [Map<String, dynamic> args]) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
class VerboseLogger extends Logger {
|
class VerboseLogger extends Logger {
|
||||||
@ -469,7 +467,7 @@ class VerboseLogger extends Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void sendNotification(String message, {String progressId}) { }
|
void sendEvent(String name, [Map<String, dynamic> args]) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
enum _LogType { error, status, trace }
|
enum _LogType { error, status, trace }
|
||||||
|
@ -900,7 +900,7 @@ class NotifyingLogger extends Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void sendNotification(String message, {String progressId}) { }
|
void sendEvent(String name, [Map<String, dynamic> args]) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A running application, started by this daemon.
|
/// A running application, started by this daemon.
|
||||||
@ -1113,13 +1113,12 @@ class _AppRunLogger extends Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void sendNotification(String message, {String progressId}) {
|
void sendEvent(String name, [Map<String, dynamic> args]) {
|
||||||
final int id = _nextProgressId++;
|
if (domain == null) {
|
||||||
_sendProgressEvent(<String, dynamic>{
|
printStatus('event sent after app closed: $name');
|
||||||
'id': id.toString(),
|
} else {
|
||||||
'progressId': progressId,
|
domain.sendEvent(name, args);
|
||||||
'finished': true,
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,9 +136,10 @@ class ChromeDevice extends Device {
|
|||||||
dataDir: fs.currentDirectory
|
dataDir: fs.currentDirectory
|
||||||
.childDirectory('.dart_tool')
|
.childDirectory('.dart_tool')
|
||||||
.childDirectory('chrome-device'));
|
.childDirectory('chrome-device'));
|
||||||
|
logger.sendEvent('app.webLaunchUrl', <String, dynamic>{'url': url, 'launched': true});
|
||||||
} else {
|
} else {
|
||||||
printStatus('Waiting for connection from Dart debug extension at $url', emphasis: true);
|
printStatus('Waiting for connection from Dart debug extension at $url', emphasis: true);
|
||||||
logger.sendNotification(url, progressId: 'debugExtension');
|
logger.sendEvent('app.webLaunchUrl', <String, dynamic>{'url': url, 'launched': false});
|
||||||
}
|
}
|
||||||
return LaunchResult.succeeded(observatoryUri: null);
|
return LaunchResult.succeeded(observatoryUri: null);
|
||||||
}
|
}
|
||||||
@ -250,7 +251,7 @@ class WebServerDevice extends Device {
|
|||||||
}) async {
|
}) async {
|
||||||
final String url = platformArgs['uri'];
|
final String url = platformArgs['uri'];
|
||||||
printStatus('$mainPath is being served at $url', emphasis: true);
|
printStatus('$mainPath is being served at $url', emphasis: true);
|
||||||
logger.sendNotification(url, progressId: 'debugExtension');
|
logger.sendEvent('app.webLaunchUrl', <String, dynamic>{'url': url, 'launched': false});
|
||||||
return LaunchResult.succeeded(observatoryUri: null);
|
return LaunchResult.succeeded(observatoryUri: null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -554,7 +554,7 @@ class StreamLogger extends Logger {
|
|||||||
Stream<String> get stream => _controller.stream;
|
Stream<String> get stream => _controller.stream;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void sendNotification(String message, {String progressId}) { }
|
void sendEvent(String name, [Map<String, dynamic> args]) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
class LoggerInterrupted implements Exception {
|
class LoggerInterrupted implements Exception {
|
||||||
|
@ -105,6 +105,7 @@ void main() {
|
|||||||
when(mockWebFs.recompile()).thenAnswer((Invocation _) {
|
when(mockWebFs.recompile()).thenAnswer((Invocation _) {
|
||||||
return Future<bool>.value(false);
|
return Future<bool>.value(false);
|
||||||
});
|
});
|
||||||
|
when(mockWebFs.uri).thenReturn('http://localhost:8765/app/');
|
||||||
when(mockDebugConnection.vmService).thenReturn(mockVmService);
|
when(mockDebugConnection.vmService).thenReturn(mockVmService);
|
||||||
when(mockDebugConnection.onDone).thenAnswer((Invocation invocation) {
|
when(mockDebugConnection.onDone).thenAnswer((Invocation invocation) {
|
||||||
return Completer<void>().future;
|
return Completer<void>().future;
|
||||||
@ -729,6 +730,75 @@ void main() {
|
|||||||
expect(bufferLogger.statusText, contains('Launching ${fs.path.join('lib', 'main.dart')} on Chromez in debug mode'));
|
expect(bufferLogger.statusText, contains('Launching ${fs.path.join('lib', 'main.dart')} on Chromez in debug mode'));
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
test('Sends launched app.webLaunchUrl event for Chrome device', () => testbed.run(() async {
|
||||||
|
_setupMocks();
|
||||||
|
when(mockFlutterDevice.device).thenReturn(ChromeDevice());
|
||||||
|
|
||||||
|
final DelegateLogger delegateLogger = logger;
|
||||||
|
final MockStatus mockStatus = MockStatus();
|
||||||
|
delegateLogger.status = mockStatus;
|
||||||
|
final ResidentWebRunner runner = DwdsWebRunnerFactory().createWebRunner(
|
||||||
|
mockFlutterDevice,
|
||||||
|
flutterProject: FlutterProject.current(),
|
||||||
|
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
|
||||||
|
ipv6: true,
|
||||||
|
stayResident: true,
|
||||||
|
dartDefines: const <String>[],
|
||||||
|
);
|
||||||
|
|
||||||
|
final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
|
||||||
|
unawaited(runner.run(
|
||||||
|
connectionInfoCompleter: connectionInfoCompleter,
|
||||||
|
));
|
||||||
|
await connectionInfoCompleter.future;
|
||||||
|
|
||||||
|
// Ensure we got the URL and that it was already launched.
|
||||||
|
verify(logger.sendEvent(
|
||||||
|
'app.webLaunchUrl',
|
||||||
|
argThat(allOf(
|
||||||
|
containsPair('url', 'http://localhost:8765/app/'),
|
||||||
|
containsPair('launched', true),
|
||||||
|
))
|
||||||
|
));
|
||||||
|
}, overrides: <Type, Generator>{
|
||||||
|
Logger: () => DelegateLogger(MockLogger()),
|
||||||
|
ChromeLauncher: () => MockChromeLauncher(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
test('Sends unlaunched app.webLaunchUrl event for Web Server device', () => testbed.run(() async {
|
||||||
|
_setupMocks();
|
||||||
|
when(mockFlutterDevice.device).thenReturn(WebServerDevice());
|
||||||
|
|
||||||
|
final DelegateLogger delegateLogger = logger;
|
||||||
|
final MockStatus mockStatus = MockStatus();
|
||||||
|
delegateLogger.status = mockStatus;
|
||||||
|
final ResidentWebRunner runner = DwdsWebRunnerFactory().createWebRunner(
|
||||||
|
mockFlutterDevice,
|
||||||
|
flutterProject: FlutterProject.current(),
|
||||||
|
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
|
||||||
|
ipv6: true,
|
||||||
|
stayResident: true,
|
||||||
|
dartDefines: const <String>[],
|
||||||
|
);
|
||||||
|
|
||||||
|
final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
|
||||||
|
unawaited(runner.run(
|
||||||
|
connectionInfoCompleter: connectionInfoCompleter,
|
||||||
|
));
|
||||||
|
await connectionInfoCompleter.future;
|
||||||
|
|
||||||
|
// Ensure we got the URL and that it was not already launched.
|
||||||
|
verify(logger.sendEvent(
|
||||||
|
'app.webLaunchUrl',
|
||||||
|
argThat(allOf(
|
||||||
|
containsPair('url', 'http://localhost:8765/app/'),
|
||||||
|
containsPair('launched', false),
|
||||||
|
))
|
||||||
|
));
|
||||||
|
}, overrides: <Type, Generator>{
|
||||||
|
Logger: () => DelegateLogger(MockLogger())
|
||||||
|
}));
|
||||||
|
|
||||||
test('Successfully turns WebSocketException into ToolExit', () => testbed.run(() async {
|
test('Successfully turns WebSocketException into ToolExit', () => testbed.run(() async {
|
||||||
_setupMocks();
|
_setupMocks();
|
||||||
final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
|
final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
|
||||||
@ -908,6 +978,7 @@ void main() {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class MockChromeLauncher extends Mock implements ChromeLauncher {}
|
||||||
class MockFlutterUsage extends Mock implements Usage {}
|
class MockFlutterUsage extends Mock implements Usage {}
|
||||||
class MockChromeDevice extends Mock implements ChromeDevice {}
|
class MockChromeDevice extends Mock implements ChromeDevice {}
|
||||||
class MockBuildDaemonCreator extends Mock implements BuildDaemonCreator {}
|
class MockBuildDaemonCreator extends Mock implements BuildDaemonCreator {}
|
||||||
@ -924,3 +995,4 @@ class MockChromeConnection extends Mock implements ChromeConnection {}
|
|||||||
class MockChromeTab extends Mock implements ChromeTab {}
|
class MockChromeTab extends Mock implements ChromeTab {}
|
||||||
class MockWipConnection extends Mock implements WipConnection {}
|
class MockWipConnection extends Mock implements WipConnection {}
|
||||||
class MockWipDebugger extends Mock implements WipDebugger {}
|
class MockWipDebugger extends Mock implements WipDebugger {}
|
||||||
|
class MockLogger extends Mock implements Logger {}
|
||||||
|
@ -801,8 +801,8 @@ class DelegateLogger implements Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void sendNotification(String message, {String progressId}) {
|
void sendEvent(String name, [Map<String, dynamic> args]) {
|
||||||
delegate.sendNotification(message, progressId: progressId);
|
delegate.sendEvent(name, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
Loading…
Reference in New Issue
Block a user