22// for details. All rights reserved. Use of this source code is governed by a
33// BSD-style license that can be found in the LICENSE file.
44
5- // @dart = 2.9
6-
75import 'dart:async' ;
86import 'dart:convert' ;
97import 'dart:io' ;
@@ -32,7 +30,7 @@ const _clientScript = 'dwds/src/injected/client';
3230/// information.
3331class DwdsInjector {
3432 final LoadStrategy _loadStrategy;
35- final Future <String > _extensionUri;
33+ final Future <String >? _extensionUri;
3634 final _devHandlerPaths = StreamController <String >();
3735 final _logger = Logger ('DwdsInjector' );
3836 final bool _enableDevtoolsLaunch;
@@ -41,14 +39,14 @@ class DwdsInjector {
4139
4240 DwdsInjector (
4341 this ._loadStrategy, {
44- Future <String > extensionUri,
45- bool enableDevtoolsLaunch,
46- bool useSseForInjectedClient,
47- bool emitDebugEvents,
42+ Future <String >? extensionUri,
43+ bool enableDevtoolsLaunch = false ,
44+ bool useSseForInjectedClient = true ,
45+ bool emitDebugEvents = true ,
4846 }) : _extensionUri = extensionUri,
4947 _enableDevtoolsLaunch = enableDevtoolsLaunch,
50- _useSseForInjectedClient = useSseForInjectedClient ?? true ,
51- _emitDebugEvents = emitDebugEvents ?? true ;
48+ _useSseForInjectedClient = useSseForInjectedClient,
49+ _emitDebugEvents = emitDebugEvents;
5250
5351 /// Returns the embedded dev handler paths.
5452 ///
@@ -60,6 +58,9 @@ class DwdsInjector {
6058 if (request.url.path.endsWith ('$_clientScript .js' )) {
6159 final uri = await Isolate .resolvePackageUri (
6260 Uri .parse ('package:$_clientScript .js' ));
61+ if (uri == null ) {
62+ throw StateError ('Cannot resolve "package:$_clientScript .js"' );
63+ }
6364 final result = await File (uri.toFilePath ()).readAsString ();
6465 return Response .ok (result, headers: {
6566 HttpHeaders .contentTypeHeader: 'application/javascript'
@@ -123,8 +124,7 @@ class DwdsInjector {
123124 return response.change (body: body, headers: newHeaders);
124125 } else {
125126 final loadResponse = await _loadStrategy.handler (request);
126- if (loadResponse != null &&
127- loadResponse.statusCode != HttpStatus .notFound) {
127+ if (loadResponse.statusCode != HttpStatus .notFound) {
128128 return loadResponse;
129129 }
130130 return innerHandler (request);
@@ -140,7 +140,7 @@ String _injectClientAndHoistMain(
140140 String appId,
141141 String devHandlerPath,
142142 String entrypointPath,
143- String extensionUri,
143+ String ? extensionUri,
144144 LoadStrategy loadStrategy,
145145 bool enableDevtoolsLaunch,
146146 bool emitDebugEvents,
@@ -194,7 +194,7 @@ String _injectedClientSnippet(
194194 String appId,
195195 String devHandlerPath,
196196 String entrypointPath,
197- String extensionUri,
197+ String ? extensionUri,
198198 LoadStrategy loadStrategy,
199199 bool enableDevtoolsLaunch,
200200 bool emitDebugEvents,
0 commit comments