mirror of
https://github.com/garrytan/gstack.git
synced 2026-05-21 12:18:24 +08:00
feat: connection status pill — floating indicator when gstack controls Chrome
Small pill in bottom-right corner of every page: "● gstack · 3 refs" Shows when connected via CDP, fades to 30% opacity after 3s, full on hover. Disappears entirely when disconnected. Background worker now notifies content scripts on connect/disconnect state changes so the pill appears/disappears without polling. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -51,23 +51,42 @@ async function checkHealth() {
|
||||
}
|
||||
|
||||
function setConnected(healthData) {
|
||||
if (!isConnected) {
|
||||
isConnected = true;
|
||||
chrome.action.setBadgeText({ text: '' });
|
||||
chrome.action.setBadgeBackgroundColor({ color: '#4ade80' });
|
||||
// Small green dot via badge
|
||||
chrome.action.setBadgeText({ text: ' ' });
|
||||
}
|
||||
const wasDisconnected = !isConnected;
|
||||
isConnected = true;
|
||||
chrome.action.setBadgeBackgroundColor({ color: '#4ade80' });
|
||||
chrome.action.setBadgeText({ text: ' ' });
|
||||
|
||||
// Broadcast health to popup and side panel
|
||||
chrome.runtime.sendMessage({ type: 'health', data: healthData }).catch(() => {});
|
||||
|
||||
// Notify content scripts on connection change
|
||||
if (wasDisconnected) {
|
||||
notifyContentScripts('connected');
|
||||
}
|
||||
}
|
||||
|
||||
function setDisconnected() {
|
||||
if (isConnected) {
|
||||
isConnected = false;
|
||||
chrome.action.setBadgeText({ text: '' });
|
||||
}
|
||||
const wasConnected = isConnected;
|
||||
isConnected = false;
|
||||
chrome.action.setBadgeText({ text: '' });
|
||||
|
||||
chrome.runtime.sendMessage({ type: 'health', data: null }).catch(() => {});
|
||||
|
||||
// Notify content scripts on disconnection
|
||||
if (wasConnected) {
|
||||
notifyContentScripts('disconnected');
|
||||
}
|
||||
}
|
||||
|
||||
async function notifyContentScripts(type) {
|
||||
try {
|
||||
const tabs = await chrome.tabs.query({});
|
||||
for (const tab of tabs) {
|
||||
if (tab.id) {
|
||||
chrome.tabs.sendMessage(tab.id, { type }).catch(() => {});
|
||||
}
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
|
||||
// ─── Refs Relay ─────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user