~cytrogen/gstack

ref: 1b60acd5768e37509e7dc09357cd2ca7567b6135 gstack/extension/popup.js -rw-r--r-- 1.7 KiB
1b60acd5 — Garry Tan fix: Codex hang fixes — plan visibility, stdout buffering, reasoning effort (v0.12.4.0) (#536) 14 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const portInput = document.getElementById('port');
const dot = document.getElementById('dot');
const statusText = document.getElementById('status-text');
const details = document.getElementById('details');
const sidePanelBtn = document.getElementById('side-panel-btn');

// Load saved port
chrome.runtime.sendMessage({ type: 'getPort' }, (resp) => {
  if (resp && resp.port) {
    portInput.value = resp.port;
    updateStatus(resp.connected);
  }
});

// Save port on change
let saveTimeout;
portInput.addEventListener('input', () => {
  clearTimeout(saveTimeout);
  saveTimeout = setTimeout(() => {
    const port = parseInt(portInput.value, 10);
    if (port > 0 && port < 65536) {
      chrome.runtime.sendMessage({ type: 'setPort', port });
    }
  }, 500);
});

// Listen for health updates
chrome.runtime.onMessage.addListener((msg) => {
  if (msg.type === 'health') {
    updateStatus(!!msg.data, msg.data);
  }
});

function updateStatus(connected, data) {
  dot.className = `dot ${connected ? 'connected' : ''}`;
  statusText.className = `status-text ${connected ? 'connected' : ''}`;
  statusText.textContent = connected ? 'Connected' : 'Disconnected';

  if (connected && data) {
    const parts = [];
    if (data.tabs) parts.push(`${data.tabs} tabs`);
    if (data.mode) parts.push(`Mode: ${data.mode}`);
    details.textContent = parts.join(' \u00b7 ');
  } else {
    details.textContent = '';
  }
}

// Open side panel
sidePanelBtn.addEventListener('click', async () => {
  try {
    const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
    if (tab) {
      await chrome.sidePanel.open({ tabId: tab.id });
      window.close();
    }
  } catch (err) {
    details.textContent = `Side panel error: ${err.message}`;
  }
});