Skip to content

Commit

Permalink
Avoid a few non-null assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
parlough committed Oct 4, 2024
1 parent 2098365 commit e34700d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 26 deletions.
4 changes: 2 additions & 2 deletions dwds/debug_extension/web/background.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ void _registerListeners() {
chrome.windows.onFocusChanged.addListener(
allowInterop((_) async {
final currentTab = await activeTab;
if (currentTab?.id != null) {
await _updateIcon(currentTab!.id);
if (currentTab?.id case final tabId?) {
await _updateIcon(tabId);
}
}),
);
Expand Down
5 changes: 3 additions & 2 deletions dwds/debug_extension/web/debug_session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,12 @@ Future<bool> _connectToDwds({
required int dartAppTabId,
required DebugInfo debugInfo,
}) async {
if (debugInfo.extensionUrl == null) {
final extensionUrl = debugInfo.extensionUrl;
if (extensionUrl == null) {
debugWarn('Can\'t connect to DWDS without an extension URL.');
return false;
}
final uri = Uri.parse(debugInfo.extensionUrl!);
final uri = Uri.parse(extensionUrl);
// Start the client connection with DWDS:
final client = uri.isScheme('ws') || uri.isScheme('wss')
? WebSocketClient(WebSocketChannel.connect(uri))
Expand Down
5 changes: 3 additions & 2 deletions dwds/debug_extension/web/popup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ Future<void> _launchDevTools(Event _) async {
}

void _copyAppId(Event _) {
if (_appId == null) return;
final appId = _appId;
if (appId == null) return;
final clipboard = window.navigator.clipboard;
if (clipboard == null) return;
clipboard.writeText(_appId!);
clipboard.writeText(appId);
_updateElementVisibility(_copiedSuccessId, visible: true);
}

Expand Down
26 changes: 6 additions & 20 deletions dwds/debug_extension/web/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,32 +115,18 @@ void setExtensionPopup(PopupDetails details) {
}
}

bool? _isDevMode;

bool get isDevMode {
if (_isDevMode != null) {
return _isDevMode!;
}
final bool isDevMode = () {
final extensionManifest = chrome.runtime.getManifest();
final extensionName = getProperty<String?>(extensionManifest, 'name') ?? '';
final isDevMode = extensionName.contains('DEV');
_isDevMode = isDevMode;
return isDevMode;
}
return extensionName.contains('DEV');
}();

bool? _isMV3;

bool get isMV3 {
if (_isMV3 != null) {
return _isMV3!;
}
final bool isMV3 = () {
final extensionManifest = chrome.runtime.getManifest();
final manifestVersion =
getProperty(extensionManifest, 'manifest_version') ?? 2;
final isMV3 = manifestVersion == 3;
_isMV3 = isMV3;
return isMV3;
}
return manifestVersion == 3;
}();

String addQueryParameters(
String uri, {
Expand Down

0 comments on commit e34700d

Please sign in to comment.