Repository navigation
Expand file tree
/
Copy pathrenderer.js
More file actions
137 lines (118 loc) · 4.21 KB
/
Copy pathrenderer.js
File metadata and controls
137 lines (118 loc) · 4.21 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Tab switching functionality
document.addEventListener('DOMContentLoaded', async () => {
// Load and display app version
try {
const version = await window.electronAPI.getAppVersion();
const versionElement = document.querySelector('.app-version');
if (versionElement) {
versionElement.textContent = `v${version}`;
}
} catch (error) {
console.error('Failed to load app version:', error);
}
// Check for updates
checkUpdateStatus();
// Update indicator click event
const updateIndicator = document.getElementById('update-indicator');
if (updateIndicator) {
updateIndicator.addEventListener('click', async () => {
await window.electronAPI.openReleasePage();
});
}
const navItems = document.querySelectorAll('.nav-item');
const contentPanels = document.querySelectorAll('.content-panel');
function switchToTab(targetTab) {
// Get previous tab before changing active states
const previousTab = document.querySelector('.content-panel.active')?.id;
navItems.forEach(navItem => navItem.classList.remove('active'));
contentPanels.forEach(panel => panel.classList.remove('active'));
// Find and activate the target tab
const targetNavItem = document.querySelector(`[data-tab="${targetTab}"]`);
const targetPanel = document.getElementById(targetTab);
if (targetNavItem && targetPanel) {
targetNavItem.classList.add('active');
targetPanel.classList.add('active');
}
// Clean up previous tab if needed
if (previousTab === 'now' && targetTab !== 'now') {
// Stop the second-by-second updates when leaving Now tab
window.nowManager?.destroy();
window.nowManager = null;
}
// Load data when tabs are activated
if (targetTab === 'statistics') {
setTimeout(() => window.statisticsManager?.loadStatistics(), 100);
} else if (targetTab === 'now') {
setTimeout(() => {
// Recreate NowManager if it doesn't exist or was destroyed
if (!window.nowManager) {
window.nowManager = new NowManager();
}
window.nowManager?.loadNowData();
}, 100);
} else if (targetTab === 'agents') {
setTimeout(() => {
if (typeof window.initializeAgentsUI === 'function') {
window.initializeAgentsUI();
}
}, 100);
}
}
navItems.forEach(item => {
item.addEventListener('click', () => {
const targetTab = item.getAttribute('data-tab');
switchToTab(targetTab);
});
});
// Listen for tab switch requests from main process
window.electronAPI.onSwitchTab((event, tabName) => {
switchToTab(tabName);
});
// Load Now tab data on startup since it's the default tab
setTimeout(() => {
console.log('Loading Now tab data on startup...');
// Ensure NowManager exists before loading data
if (!window.nowManager) {
window.nowManager = new NowManager();
}
window.nowManager?.loadNowData();
}, 500);
// Handle GitHub link click
const githubLink = document.getElementById('github-link');
if (githubLink) {
githubLink.addEventListener('click', async (e) => {
e.preventDefault();
const url = githubLink.getAttribute('data-url');
if (url) {
await window.electronAPI.openExternal(url);
}
});
}
});
// Update status checking function
async function checkUpdateStatus() {
try {
const updateInfo = await window.electronAPI.getUpdateInfo();
if (updateInfo && updateInfo.updateAvailable) {
showUpdateIndicator(updateInfo);
}
} catch (error) {
console.error('Failed to check update status:', error);
}
}
// Show update indicator function
function showUpdateIndicator(updateInfo) {
const indicator = document.getElementById('update-indicator');
if (!indicator) return;
const text = indicator.querySelector('.update-text');
if (text) {
text.textContent = `v${updateInfo.latestVersion} Update`;
}
indicator.classList.remove('hidden');
// Add tooltip
indicator.title = `Current: v${updateInfo.currentVersion}\nLatest: v${updateInfo.latestVersion}\nClick to download`;
}
// Listen for update available event from main process
window.electronAPI.onUpdateAvailable?.((updateInfo) => {
showUpdateIndicator(updateInfo);
});