MCPcopy Create free account
hub / github.com/winfunc/opcode / saveTabs

Method saveTabs

src/services/tabPersistence.ts:53–96  ·  view source on GitHub ↗

* Save tabs to localStorage

(tabs: Tab[], activeTabId: string | null)

Source from the content-addressed store, hash-verified

51 * Save tabs to localStorage
52 */
53 static saveTabs(tabs: Tab[], activeTabId: string | null): void {
54 // Don't save if persistence is disabled
55 if (!this.isEnabled()) return;
56
57 try {
58 // Filter out tabs that shouldn't be persisted
59 const persistableTabs = tabs.filter(tab => {
60 // Don't persist tabs with running status (they're likely stale)
61 if (tab.status === 'running') return false;
62
63 // Don't persist create/import agent tabs (they're temporary)
64 if (tab.type === 'create-agent' || tab.type === 'import-agent') return false;
65
66 return true;
67 });
68
69 // Serialize tabs (excluding complex objects)
70 const serializedTabs: SerializedTab[] = persistableTabs.map(tab => ({
71 id: tab.id,
72 type: tab.type,
73 title: tab.title,
74 sessionId: tab.sessionId,
75 agentRunId: tab.agentRunId,
76 claudeFileId: tab.claudeFileId,
77 initialProjectPath: tab.initialProjectPath,
78 projectPath: tab.projectPath,
79 status: tab.status === 'running' ? 'idle' : tab.status, // Reset running status
80 hasUnsavedChanges: false, // Reset unsaved changes
81 order: tab.order,
82 icon: tab.icon,
83 createdAt: tab.createdAt instanceof Date ? tab.createdAt.toISOString() : tab.createdAt,
84 updatedAt: tab.updatedAt instanceof Date ? tab.updatedAt.toISOString() : tab.updatedAt
85 }));
86
87 localStorage.setItem(STORAGE_KEY, JSON.stringify(serializedTabs));
88
89 // Save active tab ID
90 if (activeTabId && persistableTabs.some(tab => tab.id === activeTabId)) {
91 localStorage.setItem(ACTIVE_TAB_KEY, activeTabId);
92 }
93 } catch (error) {
94 console.error('Failed to save tabs:', error);
95 }
96 }
97
98 /**
99 * Load tabs from localStorage

Callers 2

TabProviderFunction · 0.80
handleBeforeUnloadFunction · 0.80

Calls 1

isEnabledMethod · 0.95

Tested by

no test coverage detected