|
43 | 43 | this._localSendspinDesired = false; |
44 | 44 | this._localSendspinLifecycleListening = false; |
45 | 45 | this._localSendspinSuppressClose = false; |
| 46 | + this._toastHistory = new Map(); |
46 | 47 | this._directMaPlayers = []; |
47 | 48 | this._directMaPlayersRefreshPromise = null; |
48 | 49 |
|
|
2964 | 2965 | this._localSendspinPlayerId = session.playerId || this._localSendspinPlayerId || ""; |
2965 | 2966 | this._localSendspinState = session.state || this._localSendspinState || null; |
2966 | 2967 | this._localSendspinDesired = !!session.desired || this._localSendspinDesired; |
2967 | | - if (session.desired || this._isLocalSendspinDesired()) { |
2968 | | - this._state.awaitingThisDevicePlayer = true; |
| 2968 | + const desired = session.desired || this._isLocalSendspinDesired(); |
| 2969 | + if (desired) { |
2969 | 2970 | this._state.localSendspinStatus = session.connected ? "connected" : (session.connecting ? "connecting" : "reconnecting"); |
| 2971 | + if (session.connected) this._state.awaitingThisDevicePlayer = false; |
2970 | 2972 | } |
2971 | 2973 | return session; |
2972 | 2974 | } |
|
3319 | 3321 | if (this._state.menuOpen && typeof this._renderMobileMenu === "function") { |
3320 | 3322 | this._renderMobileMenu().catch(() => {}); |
3321 | 3323 | } |
3322 | | - if (delay === 10000 && this._state.awaitingThisDevicePlayer) { |
3323 | | - this._toast(this._localText( |
3324 | | - "Local player is connected; waiting for Home Assistant to publish it.", |
3325 | | - "הנגן המקומי מחובר; ממתין ש-Home Assistant יציג אותו ברשימה." |
3326 | | - )); |
3327 | | - } |
3328 | 3324 | }, delay)); |
3329 | 3325 | } |
3330 | 3326 |
|
|
3416 | 3412 | ? session.controller |
3417 | 3413 | : this; |
3418 | 3414 | if (desired) { |
3419 | | - if (controller.isConnected) { |
3420 | | - controller._toast(controller._localText( |
3421 | | - "This device player paused in the background; reconnecting when the dashboard is active.", |
3422 | | - "נגן המכשיר הושהה ברקע; יתחבר מחדש כשהדשבורד פעיל." |
3423 | | - )); |
3424 | | - } |
3425 | 3415 | controller._scheduleLocalSendspinReconnect(event?.type || "socket_close", 1200); |
3426 | 3416 | } |
3427 | 3417 | } |
|
7640 | 7630 | this._state.knownBrowserPlayerIds = []; |
7641 | 7631 | this._state.selectedPlayer = newcomer.entity_id; |
7642 | 7632 | this._state.hasAutoSelectedPlayer = true; |
7643 | | - this._toast(this._t("This device player connected")); |
7644 | 7633 | } |
7645 | 7634 | } |
7646 | 7635 | const selectedPlayer = this._playerByEntityId(this._state.selectedPlayer); |
|
8643 | 8632 | _toast(message, variant = "info") { |
8644 | 8633 | const wrap = this.$("toastWrap"); |
8645 | 8634 | if (!wrap) return; |
8646 | | - const el = document.createElement("div"); |
| 8635 | + const text = String(message ?? "").trim(); |
| 8636 | + if (!text) return; |
8647 | 8637 | const safeVariant = ["success", "error", "info"].includes(variant) ? variant : "info"; |
| 8638 | + const now = Date.now(); |
| 8639 | + const key = `${safeVariant}:${text}`; |
| 8640 | + const lastShown = this._toastHistory?.get(key) || 0; |
| 8641 | + if (now - lastShown < 2500) return; |
| 8642 | + if (!this._toastHistory) this._toastHistory = new Map(); |
| 8643 | + this._toastHistory.set(key, now); |
| 8644 | + for (const [toastKey, at] of this._toastHistory.entries()) { |
| 8645 | + if (now - at > 12000) this._toastHistory.delete(toastKey); |
| 8646 | + } |
| 8647 | + const activeToasts = Array.from(wrap.querySelectorAll(".toast")); |
| 8648 | + while (activeToasts.length >= 3) activeToasts.shift()?.remove(); |
| 8649 | + const el = document.createElement("div"); |
8648 | 8650 | el.className = `toast ${safeVariant}`; |
8649 | 8651 | const icon = safeVariant === "success" ? "✓" : safeVariant === "error" ? "×" : "i"; |
8650 | | - el.innerHTML = `<span class="toast-icon">${icon}</span><span class="toast-text">${this._esc(message)}</span>`; |
| 8652 | + el.innerHTML = `<span class="toast-icon">${icon}</span><span class="toast-text">${this._esc(text)}</span>`; |
8651 | 8653 | wrap.appendChild(el); |
8652 | 8654 | setTimeout(() => el.remove(), 3300); |
8653 | 8655 | } |
|
0 commit comments