mirror of
https://github.com/Shik3i/KoalaSync.git
synced 2026-07-26 12:08:15 +00:00
chore(core): Integration and UX Polish fixes
This commit is contained in:
@@ -146,7 +146,6 @@ async function connect() {
|
||||
isConnecting = false;
|
||||
reconnectDelay = 1000;
|
||||
addLog('WebSocket Connection Opened', 'success');
|
||||
broadcastConnectionStatus('connected');
|
||||
reconnectStartTime = null;
|
||||
reconnectFailed = false;
|
||||
isNamespaceJoined = false;
|
||||
@@ -176,6 +175,7 @@ async function connect() {
|
||||
addLog(`Socket.IO Handshake: ${msg}`, 'info');
|
||||
} else if (msg.startsWith('40')) {
|
||||
isNamespaceJoined = true;
|
||||
broadcastConnectionStatus('connected');
|
||||
addLog('Joined Namespace /', 'success');
|
||||
// Auto-rejoin room if we have one in settings
|
||||
if (settings.roomId) {
|
||||
|
||||
@@ -364,6 +364,15 @@ function showError(msg) {
|
||||
|
||||
// --- Action Handlers ---
|
||||
elements.joinBtn.addEventListener('click', async () => {
|
||||
if (elements.joinBtn.disabled) return;
|
||||
elements.joinBtn.disabled = true;
|
||||
const originalText = elements.joinBtn.textContent;
|
||||
elements.joinBtn.textContent = 'Joining...';
|
||||
setTimeout(() => {
|
||||
elements.joinBtn.disabled = false;
|
||||
elements.joinBtn.textContent = originalText;
|
||||
}, 1500);
|
||||
|
||||
const serverUrl = elements.serverUrl.value;
|
||||
const roomId = elements.roomId.value || Math.random().toString(36).substring(2, 8).toUpperCase();
|
||||
const password = elements.password.value;
|
||||
@@ -412,9 +421,20 @@ elements.targetTab.addEventListener('change', async () => {
|
||||
});
|
||||
|
||||
elements.forceSyncBtn.addEventListener('click', async () => {
|
||||
if (elements.forceSyncBtn.disabled) return;
|
||||
|
||||
const settings = await chrome.storage.sync.get(['targetTabId']);
|
||||
if (!settings.targetTabId) return;
|
||||
|
||||
// Lockout to prevent spamming
|
||||
const originalText = elements.forceSyncBtn.textContent;
|
||||
elements.forceSyncBtn.disabled = true;
|
||||
elements.forceSyncBtn.textContent = 'Syncing...';
|
||||
setTimeout(() => {
|
||||
elements.forceSyncBtn.disabled = false;
|
||||
elements.forceSyncBtn.textContent = originalText;
|
||||
}, 5000);
|
||||
|
||||
const tabId = parseInt(settings.targetTabId);
|
||||
|
||||
const sendForceSync = (time) => {
|
||||
|
||||
+5
-5
@@ -202,7 +202,7 @@ io.on('connection', (socket) => {
|
||||
lastActivity: Date.now()
|
||||
};
|
||||
rooms.set(roomId, room);
|
||||
log('ROOM', `Created room: ${roomId}`);
|
||||
log('ROOM', `Created room: ${roomId.substring(0, 3)}***`);
|
||||
} else {
|
||||
if (room.passwordHash) {
|
||||
if (!password || !(await bcrypt.compare(password, room.passwordHash))) {
|
||||
@@ -228,7 +228,7 @@ io.on('connection', (socket) => {
|
||||
roomId,
|
||||
peers: Array.from(room.peers).map(sid => room.peerData.get(sid))
|
||||
});
|
||||
log('ROOM', `Peer ${peerId} joined: ${roomId}`);
|
||||
log('ROOM', `Peer ${peerId} joined: ${roomId.substring(0, 3)}***`);
|
||||
} catch (err) {
|
||||
log('ERROR', `Join error for ${socket.id}`, err);
|
||||
socket.emit(EVENTS.ERROR, { message: "Join error" });
|
||||
@@ -289,7 +289,7 @@ io.on('connection', (socket) => {
|
||||
socket.to(roomId).emit(EVENTS.PEER_STATUS, { peerId, status: 'left' });
|
||||
if (room.peers.size === 0) {
|
||||
rooms.delete(roomId);
|
||||
log('ROOM', `Deleted empty room: ${roomId}`);
|
||||
log('ROOM', `Deleted empty room: ${roomId.substring(0, 3)}***`);
|
||||
}
|
||||
}
|
||||
socketToRoom.delete(socket.id);
|
||||
@@ -309,7 +309,7 @@ io.on('connection', (socket) => {
|
||||
socket.to(roomId).emit(EVENTS.PEER_STATUS, { peerId, status: 'left' });
|
||||
if (room.peers.size === 0) {
|
||||
rooms.delete(roomId);
|
||||
log('ROOM', `Deleted empty room (after disconnect): ${roomId}`);
|
||||
log('ROOM', `Deleted empty room (after disconnect): ${roomId.substring(0, 3)}***`);
|
||||
}
|
||||
}
|
||||
socketToRoom.delete(socket.id);
|
||||
@@ -324,7 +324,7 @@ setInterval(() => {
|
||||
if (room.lastActivity < cutoff) {
|
||||
io.to(roomId).emit(EVENTS.ERROR, { message: 'Room closed due to inactivity' });
|
||||
rooms.delete(roomId);
|
||||
log('CLEANUP', `Deleted inactive room: ${roomId}`);
|
||||
log('CLEANUP', `Deleted inactive room: ${roomId.substring(0, 3)}***`);
|
||||
}
|
||||
}
|
||||
}, 30 * 60 * 1000);
|
||||
|
||||
Reference in New Issue
Block a user