initLogStore function exported ✓ 100.0%

Last updated: 2026-03-01T23:25:47.125Z

Metrics

LOC: 30 Complexity: 9 Params: 0 Coverage: 100.0% (15/15 lines, 39x executed)

Signature

initLogStore(): : Promise<void>

Summary

Initializes the log store by loading existing entries from chrome.storage.session and subscribing to cross-context changes.

Source Code

export async function initLogStore(): Promise<void> {
  if (initialized) return;
  initialized = true;

  if (!hasSessionStorage()) return;

  try {
    const result = await chrome.storage.session.get(STORAGE_KEY);
    const stored = result[STORAGE_KEY] as LogEntry[] | undefined;
    if (Array.isArray(stored)) {
      localEntries = stored.slice(-maxEntries);
    }
  } catch {
    // Storage unavailable — stay with empty local entries
  }

  // Listen for changes from other contexts
  try {
    chrome.storage.onChanged.addListener((changes, area) => {
      if (area !== "session" || !changes[STORAGE_KEY]) return;
      const newVal = changes[STORAGE_KEY].newValue as LogEntry[] | undefined;
      if (Array.isArray(newVal)) {
        localEntries = newVal.slice(-maxEntries);
        notifyListeners();
      }
    });
  } catch {
    // Listener setup failed — cross-context sync won't work
  }
}

Dependencies (Outgoing)

graph LR initLogStore["initLogStore"] hasSessionStorage["hasSessionStorage"] notifyListeners["notifyListeners"] initLogStore -->|calls| hasSessionStorage initLogStore -->|calls| notifyListeners style initLogStore fill:#dbeafe,stroke:#2563eb,stroke-width:2px click initLogStore "e592afd94ce8e81f.html" click hasSessionStorage "a7e74519d0293203.html" click notifyListeners "907bc8a226709b64.html"
TargetType
hasSessionStorage calls
notifyListeners calls
STORAGE_KEY dynamic_call

Impact (Incoming)

graph LR initLogStore["initLogStore"] LogLevel["LogLevel"] initLogger["initLogger"] LogLevel -->|uses| initLogStore initLogger -->|calls| initLogStore style initLogStore fill:#dbeafe,stroke:#2563eb,stroke-width:2px click initLogStore "e592afd94ce8e81f.html" click LogLevel "c16627126b9be48e.html" click initLogger "ad03e6e0ac6d4c9a.html"
SourceType
LogLevel uses
initLogger calls