Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,10 @@ function startServer(host, port, openBrowser = true) {
}
}

// Anonymous heartbeat — count active installs
sendHeartbeat();
// Delayed heartbeat + auto-sync (don't block startup)
setTimeout(sendHeartbeat, 5000);
setTimeout(autoSync, 15000); // first sync 15s after start
setInterval(autoSync, 300000); // then every 5 min
});
}

Expand All @@ -448,15 +450,11 @@ function sendHeartbeat() {
const { getOrCreateAnonId } = require('./data');
const anon = getOrCreateAnonId();
const pkg = require('../package.json');
const sessions = require('./data').loadSessions();
const agentCounts = {};
sessions.forEach(s => { agentCounts[s.tool] = (agentCounts[s.tool] || 0) + 1; });

const body = JSON.stringify({
anonId: anon.id,
version: pkg.version,
platform: process.platform,
agents: agentCounts,
});

const req = https.request({
Expand All @@ -465,12 +463,22 @@ function sendHeartbeat() {
headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(body) },
timeout: 5000,
});
req.on('error', () => {}); // silent fail
req.on('error', () => {});
req.write(body);
req.end();
} catch {}
}

function autoSync() {
try {
const profile = loadGitHubProfile();
if (!profile || !profile.authenticated) return; // not connected — skip
syncLeaderboard().then(() => {
log('SYNC', 'Auto-sync OK');
}).catch(() => {});
} catch {}
}

// ── Helpers ─────────────────────────────────
function json(res, data, status = 200) {
res.writeHead(status, { 'Content-Type': 'application/json' });
Expand Down
Loading