Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 53 additions & 53 deletions dwds/debug_extension_mv3/web/panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ import 'messaging.dart';
import 'storage.dart';
import 'utils.dart';

bool connecting = false;
String backgroundColor = darkColor;
bool isDartApp = true;
bool _connecting = false;
String _backgroundColor = _darkColor;
bool _isDartApp = true;

const bugLinkId = 'bugLink';
const darkColor = '202125';
const darkThemeClass = 'dark-theme';
const hiddenClass = 'hidden';
const iframeContainerId = 'iframeContainer';
const landingPageId = 'landingPage';
const launchDebugConnectionButtonId = 'launchDebugConnectionButton';
const lightColor = 'ffffff';
const lightThemeClass = 'light-theme';
const loadingSpinnerId = 'loadingSpinner';
const panelAttribute = 'data-panel';
const panelBodyId = 'panelBody';
const showClass = 'show';
const warningBannerId = 'warningBanner';
const warningMsgId = 'warningMsg';
const _bugLinkId = 'bugLink';
const _darkColor = '202125';
const _darkThemeClass = 'dark-theme';
const _hiddenClass = 'hidden';
const _iframeContainerId = 'iframeContainer';
const _landingPageId = 'landingPage';
const _launchDebugConnectionButtonId = 'launchDebugConnectionButton';
const _lightColor = 'ffffff';
const _lightThemeClass = 'light-theme';
const _loadingSpinnerId = 'loadingSpinner';
const _panelAttribute = 'data-panel';
const _panelBodyId = 'panelBody';
const _showClass = 'show';
const _warningBannerId = 'warningBanner';
const _warningMsgId = 'warningMsg';

int get _tabId => chrome.devtools.inspectedWindow.tabId;

Expand All @@ -52,7 +52,7 @@ void _registerListeners() {
chrome.storage.onChanged.addListener(allowInterop(_handleStorageChanges));
chrome.runtime.onMessage.addListener(allowInterop(_handleRuntimeMessages));
final launchDebugConnectionButton =
document.getElementById(launchDebugConnectionButtonId) as ButtonElement;
document.getElementById(_launchDebugConnectionButtonId) as ButtonElement;
launchDebugConnectionButton.addEventListener('click', _launchDebugConnection);

_maybeInjectDevToolsIframe();
Expand Down Expand Up @@ -89,7 +89,7 @@ void _handleRuntimeMessages(
if (connectFailure.tabId != _tabId) {
return;
}
connecting = false;
_connecting = false;
_handleConnectFailure(
ConnectFailureReason.fromString(connectFailure.reason ?? 'unknown'),
);
Expand All @@ -115,12 +115,12 @@ void _handleStorageChanges(Object storageObj, String storageArea) {
}

void _handleDebugInfoChanges(DebugInfo? debugInfo) async {
if (debugInfo == null && isDartApp) {
isDartApp = false;
if (debugInfo == null && _isDartApp) {
_isDartApp = false;
_showWarningBanner('Dart app is no longer open.');
}
if (debugInfo != null && !isDartApp) {
isDartApp = true;
if (debugInfo != null && !_isDartApp) {
_isDartApp = true;
_hideWarningBanner();
}
}
Expand All @@ -138,7 +138,7 @@ void _maybeUpdateFileABugLink() async {
);
final isInternal = debugInfo?.isInternalBuild ?? false;
if (isInternal) {
final bugLink = document.getElementById(bugLinkId);
final bugLink = document.getElementById(_bugLinkId);
if (bugLink == null) return;
bugLink.setAttribute(
'href', 'http://b/issues/new?component=775375&template=1369639');
Expand All @@ -147,12 +147,12 @@ void _maybeUpdateFileABugLink() async {

void _setColorThemeToMatchChromeDevTools() async {
final chromeTheme = chrome.devtools.panels.themeName;
final panelBody = document.getElementById(panelBodyId);
final panelBody = document.getElementById(_panelBodyId);
if (chromeTheme == 'dark') {
backgroundColor = darkColor;
_backgroundColor = _darkColor;
_updateColorThemeForElement(panelBody, isDarkTheme: true);
} else {
backgroundColor = lightColor;
_backgroundColor = _lightColor;
_updateColorThemeForElement(panelBody, isDarkTheme: false);
}
}
Expand All @@ -162,18 +162,18 @@ void _updateColorThemeForElement(
required bool isDarkTheme,
}) {
if (element == null) return;
final classToRemove = isDarkTheme ? lightThemeClass : darkThemeClass;
final classToRemove = isDarkTheme ? _lightThemeClass : _darkThemeClass;
if (element.classes.contains(classToRemove)) {
element.classes.remove(classToRemove);
final classToAdd = isDarkTheme ? darkThemeClass : lightThemeClass;
final classToAdd = isDarkTheme ? _darkThemeClass : _lightThemeClass;
element.classes.add(classToAdd);
}
}

void _handleDebugConnectionLost(String? reason) {
final detachReason = DetachReason.fromString(reason ?? 'unknown');
_removeDevToolsIframe();
_updateElementVisibility(landingPageId, visible: true);
_updateElementVisibility(_landingPageId, visible: true);
if (detachReason != DetachReason.canceledByUser) {
_showWarningBanner('Lost connection.');
}
Expand All @@ -193,26 +193,26 @@ void _handleConnectFailure(ConnectFailureReason reason) {
default:
_showWarningBanner('Failed to connect, please try again.');
}
_updateElementVisibility(launchDebugConnectionButtonId, visible: true);
_updateElementVisibility(loadingSpinnerId, visible: false);
_updateElementVisibility(_launchDebugConnectionButtonId, visible: true);
_updateElementVisibility(_loadingSpinnerId, visible: false);
}

void _showWarningBanner(String message) {
final warningMsg = document.getElementById(warningMsgId);
final warningMsg = document.getElementById(_warningMsgId);
warningMsg?.setInnerHtml(message);
print(warningMsg);
final warningBanner = document.getElementById(warningBannerId);
warningBanner?.classes.add(showClass);
final warningBanner = document.getElementById(_warningBannerId);
warningBanner?.classes.add(_showClass);
}

void _hideWarningBanner() {
final warningBanner = document.getElementById(warningBannerId);
warningBanner?.classes.remove(showClass);
final warningBanner = document.getElementById(_warningBannerId);
warningBanner?.classes.remove(_showClass);
}

void _launchDebugConnection(Event _) async {
_updateElementVisibility(launchDebugConnectionButtonId, visible: false);
_updateElementVisibility(loadingSpinnerId, visible: true);
_updateElementVisibility(_launchDebugConnectionButtonId, visible: false);
_updateElementVisibility(_loadingSpinnerId, visible: true);
final json = jsonEncode(serializers.serialize(DebugStateChange((b) => b
..tabId = _tabId
..newState = DebugStateChange.startDebugging)));
Expand All @@ -225,9 +225,9 @@ void _launchDebugConnection(Event _) async {
}

void _maybeHandleConnectionTimeout() async {
connecting = true;
_connecting = true;
await Future.delayed(Duration(seconds: 10));
if (connecting == true) {
if (_connecting == true) {
_handleConnectFailure(ConnectFailureReason.timeout);
}
}
Expand All @@ -241,31 +241,31 @@ void _maybeInjectDevToolsIframe() async {
}

void _injectDevToolsIframe(String devToolsUri) {
connecting = false;
final iframeContainer = document.getElementById(iframeContainerId);
_connecting = false;
final iframeContainer = document.getElementById(_iframeContainerId);
if (iframeContainer == null) return;
final panelBody = document.getElementById(panelBodyId);
final panelType = panelBody?.getAttribute(panelAttribute) ?? 'debugger';
final panelBody = document.getElementById(_panelBodyId);
final panelType = panelBody?.getAttribute(_panelAttribute) ?? 'debugger';
final iframe = document.createElement('iframe');
final iframeSrc = addQueryParameters(
devToolsUri,
queryParameters: {
'ide': 'ChromeDevTools',
'embed': 'true',
'page': panelType,
'backgroundColor': backgroundColor,
'_backgroundColor': _backgroundColor,
},
);
iframe.setAttribute('src', iframeSrc);
_hideWarningBanner();
_updateElementVisibility(landingPageId, visible: false);
_updateElementVisibility(loadingSpinnerId, visible: false);
_updateElementVisibility(launchDebugConnectionButtonId, visible: true);
_updateElementVisibility(_landingPageId, visible: false);
_updateElementVisibility(_loadingSpinnerId, visible: false);
_updateElementVisibility(_launchDebugConnectionButtonId, visible: true);
iframeContainer.append(iframe);
}

void _removeDevToolsIframe() {
final iframeContainer = document.getElementById(iframeContainerId);
final iframeContainer = document.getElementById(_iframeContainerId);
final iframe = iframeContainer?.firstChild;
if (iframe == null) return;
iframe.remove();
Expand All @@ -275,8 +275,8 @@ void _updateElementVisibility(String elementId, {required bool visible}) {
final element = document.getElementById(elementId);
if (element == null) return;
if (visible) {
element.classes.remove(hiddenClass);
element.classes.remove(_hiddenClass);
} else {
element.classes.add(hiddenClass);
element.classes.add(_hiddenClass);
}
}