fixes, stale extension problem
- SHA
ac0bee2056b423e802ea23e71e332188cb2e879d- Parents
-
7ca20f7 - Tree
91b81c2
ac0bee2
ac0bee2056b423e802ea23e71e332188cb2e879d7ca20f7
91b81c2| Status | File | + | - |
|---|---|---|---|
| C |
extension/background/background-fixed.js
|
0 | 0 |
| M |
extension/background/background.js
|
11 | 5 |
extension/background/background.js → extension/background/background-fixed.jscopied (88% similarity)@@ -1,4 +1,4 @@ | ||
| 1 | -// Background script for LooseCannon | |
| 1 | +// Background script for LooseCannon - Fixed Connection Issues | |
| 2 | 2 | console.log('[LooseCannon Background] Initialized'); |
| 3 | 3 | |
| 4 | 4 | class LooseCannonBackground { |
@@ -37,8 +37,11 @@ class LooseCannonBackground { | ||
| 37 | 37 | break; |
| 38 | 38 | |
| 39 | 39 | case 'GET_SERVER_STATUS': |
| 40 | - sendResponse({ connected: this.isConnected }); | |
| 41 | - break; | |
| 40 | + // Check connection immediately when asked | |
| 41 | + this.checkServerConnection().then(() => { | |
| 42 | + sendResponse({ connected: this.isConnected }); | |
| 43 | + }); | |
| 44 | + return true; // Keep channel open for async response | |
| 42 | 45 | |
| 43 | 46 | case 'GET_PERSONALITIES': |
| 44 | 47 | sendResponse({ personalities: this.personalities }); |
@@ -109,24 +112,28 @@ class LooseCannonBackground { | ||
| 109 | 112 | |
| 110 | 113 | async checkServerConnection() { |
| 111 | 114 | try { |
| 115 | + console.log('[LooseCannon] Checking server connection...'); | |
| 112 | 116 | const response = await fetch(`${this.serverUrl}/status`); |
| 117 | + | |
| 113 | 118 | if (response.ok) { |
| 114 | 119 | const data = await response.json(); |
| 115 | 120 | this.isConnected = true; |
| 116 | 121 | this.personalities = data.personalities || []; |
| 117 | - console.log('[LooseCannon] Server connected, personalities:', this.personalities); | |
| 122 | + console.log('[LooseCannon] Server connected successfully'); | |
| 123 | + console.log('[LooseCannon] Available personalities:', this.personalities); | |
| 124 | + return true; | |
| 118 | 125 | } else { |
| 119 | 126 | this.isConnected = false; |
| 120 | 127 | console.warn('[LooseCannon] Server responded with error:', response.status); |
| 128 | + return false; | |
| 121 | 129 | } |
| 122 | 130 | } catch (error) { |
| 123 | 131 | this.isConnected = false; |
| 124 | - console.error('[LooseCannon] Could not connect to server:', error); | |
| 125 | - } | |
| 132 | + console.error('[LooseCannon] Could not connect to server:', error.message); | |
| 126 | 133 | |
| 127 | - // Retry connection every 5 seconds if not connected | |
| 128 | - if (!this.isConnected) { | |
| 134 | + // Retry in 5 seconds | |
| 129 | 135 | setTimeout(() => this.checkServerConnection(), 5000); |
| 136 | + return false; | |
| 130 | 137 | } |
| 131 | 138 | } |
| 132 | 139 | |
extension/background/background.jsmodified@@ -37,8 +37,11 @@ class LooseCannonBackground { | ||
| 37 | 37 | break; |
| 38 | 38 | |
| 39 | 39 | case 'GET_SERVER_STATUS': |
| 40 | - sendResponse({ connected: this.isConnected }); | |
| 41 | - break; | |
| 40 | + // Check connection immediately when asked | |
| 41 | + this.checkServerConnection().then(() => { | |
| 42 | + sendResponse({ connected: this.isConnected }); | |
| 43 | + }); | |
| 44 | + return true; // Keep channel open for async response | |
| 42 | 45 | |
| 43 | 46 | case 'GET_PERSONALITIES': |
| 44 | 47 | sendResponse({ personalities: this.personalities }); |
@@ -109,19 +112,22 @@ class LooseCannonBackground { | ||
| 109 | 112 | |
| 110 | 113 | async checkServerConnection() { |
| 111 | 114 | try { |
| 115 | + console.log('[LooseCannon] Checking server connection to:', this.serverUrl); | |
| 112 | 116 | const response = await fetch(`${this.serverUrl}/status`); |
| 117 | + | |
| 113 | 118 | if (response.ok) { |
| 114 | 119 | const data = await response.json(); |
| 115 | 120 | this.isConnected = true; |
| 116 | 121 | this.personalities = data.personalities || []; |
| 117 | - console.log('[LooseCannon] Server connected, personalities:', this.personalities); | |
| 122 | + console.log('[LooseCannon] ✅ Server connected successfully'); | |
| 123 | + console.log('[LooseCannon] Available personalities:', this.personalities); | |
| 118 | 124 | } else { |
| 119 | 125 | this.isConnected = false; |
| 120 | - console.warn('[LooseCannon] Server responded with error:', response.status); | |
| 126 | + console.warn('[LooseCannon] ❌ Server responded with error:', response.status); | |
| 121 | 127 | } |
| 122 | 128 | } catch (error) { |
| 123 | 129 | this.isConnected = false; |
| 124 | - console.error('[LooseCannon] Could not connect to server:', error); | |
| 130 | + console.error('[LooseCannon] ❌ Could not connect to server:', error.message); | |
| 125 | 131 | } |
| 126 | 132 | |
| 127 | 133 | // Retry connection every 5 seconds if not connected |