@@ -29,6 +29,16 @@ void _registerListeners() {
29
29
chrome.runtime.onMessage.addListener (allowInterop (_handleRuntimeMessages));
30
30
chrome.tabs.onRemoved
31
31
.addListener (allowInterop ((tabId, _) => maybeRemoveLifelinePort (tabId)));
32
+ // Update the extension icon on tab navigation:
33
+ chrome.tabs.onActivated.addListener (allowInterop ((ActiveInfo info) {
34
+ _updateIcon (info.tabId);
35
+ }));
36
+ chrome.windows.onFocusChanged.addListener (allowInterop ((_) async {
37
+ final currentTab = await _getTab ();
38
+ if (currentTab? .id != null ) {
39
+ _updateIcon (currentTab! .id);
40
+ }
41
+ }));
32
42
33
43
// Detect clicks on the Dart Debug Extension icon.
34
44
chrome.action.onClicked.addListener (allowInterop (_startDebugSession));
@@ -86,27 +96,39 @@ void _handleRuntimeMessages(
86
96
expectedSender: Script .detector,
87
97
expectedRecipient: Script .background,
88
98
messageHandler: (DebugInfo debugInfo) async {
89
- final currentTab = await _getTab ();
90
- final currentUrl = currentTab? .url ?? '' ;
91
- final appUrl = debugInfo.appUrl ?? '' ;
92
- if (currentTab == null ||
93
- currentUrl.isEmpty ||
94
- appUrl.isEmpty ||
95
- currentUrl != appUrl) {
96
- console.warn (
97
- 'Dart app detected at $appUrl but current tab is $currentUrl .' );
99
+ final dartTab = sender.tab;
100
+ if (dartTab == null ) {
101
+ console.warn ('Received debug info but tab is missing.' );
98
102
return ;
99
103
}
100
104
// Save the debug info for the Dart app in storage:
101
105
await setStorageObject <DebugInfo >(
102
- type: StorageObject .debugInfo,
103
- value: debugInfo,
104
- tabId: currentTab.id);
106
+ type: StorageObject .debugInfo, value: debugInfo, tabId: dartTab.id);
105
107
// Update the icon to show that a Dart app has been detected:
106
- chrome.action.setIcon (IconInfo (path: 'dart.png' ), /*callback*/ null );
108
+ final currentTab = await _getTab ();
109
+ if (currentTab? .id == dartTab.id) {
110
+ _setDebuggableIcon ();
111
+ }
107
112
});
108
113
}
109
114
115
+ void _updateIcon (int activeTabId) async {
116
+ final debugInfo = await _fetchDebugInfo (activeTabId);
117
+ if (debugInfo != null ) {
118
+ _setDebuggableIcon ();
119
+ } else {
120
+ _setDefaultIcon ();
121
+ }
122
+ }
123
+
124
+ void _setDebuggableIcon () {
125
+ chrome.action.setIcon (IconInfo (path: 'dart.png' ), /*callback*/ null );
126
+ }
127
+
128
+ void _setDefaultIcon () {
129
+ chrome.action.setIcon (IconInfo (path: 'dart_grey.png' ), /*callback*/ null );
130
+ }
131
+
110
132
Future <DebugInfo ?> _fetchDebugInfo (int tabId) {
111
133
return fetchStorageObject <DebugInfo >(
112
134
type: StorageObject .debugInfo,
0 commit comments