diff --git a/FMScanMonitor/CHANGELOG.md b/FMScanMonitor/CHANGELOG.md index b639bb2..efcc319 100644 --- a/FMScanMonitor/CHANGELOG.md +++ b/FMScanMonitor/CHANGELOG.md @@ -1,5 +1,40 @@ # Changelog +## 0.9.13 + +- Add a native `Scan Monitor` shortcut beside the other Webserver plugin icons. +- Open and smoothly reveal the expanded `Frequency scan list` when a public visitor selects the shortcut. +- Open the administrator Scan Monitor panel from the same shortcut while signed in. +- Refine the desktop Frequency-card status spacing and text rendering. +- Improve the running indicator and public-control countdown legibility on desktop and mobile. +- Resume immediately after an explicit `Release tuner` action while retaining the reconnect grace period after an unexpected disconnect. + +## 0.9.12 + +- Add a compact, always-visible FM scan status and tuner-handover control inside the existing Webserver `Frequency` card on desktop and mobile. +- Keep the original frequency-arrow area and surrounding receiver layout unchanged while scanner state, action and public-control countdown update in place. +- Add administrator pause/resume actions to the new control and move the public `Pause & tune` / `Release tuner` action there. +- Pause FM Scan Monitor automatically when Highpoint Scanner starts, then resume safely after Highpoint stops. +- Reject simultaneous scanner starts and preserve manual or visitor pauses during scanner handover. + +## 0.9.11 + +- Stop an active Highpoint Scanner auto-scan before FM Scan Monitor starts a scan. +- Prevent the two plugins from sending competing frequency commands and skipping the upper FM band. +- Leave the Highpoint Scanner plugin and the FM-DX Webserver core unchanged. + +## 0.9.10 + +- Wait up to 1.5 seconds for a slower TEF tuner to confirm the requested frequency before evaluating its signal. +- Poll only when telemetry still reports the previous frequency, preserving the normal scan speed on fast tuners. +- Prevent one delayed frequency update from making the remainder of the band scan too quickly without logging stations. + +## 0.9.9 + +- Retry the internal telemetry request up to three times when the Webserver event loop is temporarily busy. +- Keep a single transient `/api` delay from stopping a continuous scan and leaving a permanent error status. +- Report the attempt count only when all recovery attempts fail. + ## 0.9.8 - Limit simultaneous OpenTopoMap downloads, with a stricter three-request limit on iPhone and iPad. diff --git a/FMScanMonitor/README.md b/FMScanMonitor/README.md index c8426c6..f5c81ee 100644 --- a/FMScanMonitor/README.md +++ b/FMScanMonitor/README.md @@ -2,9 +2,12 @@ **FM Scan Monitor by Aurel** is a responsive live band scanner and reception monitor for FM-DX Webserver, designed for both desktop and mobile browsers. It is a standalone plugin and does not modify the Webserver core or the existing Scanner plugin. -## Version 0.9.8 +## Version 0.9.13 - Single-pass and continuous scanning. +- Native `Scan Monitor` shortcut beside the Webserver's other plugin icons; it opens and reveals the frequency list or administrator panel. +- Compact live scanner status and tuner-handover button inside the Webserver's existing `Frequency` card, without replacing the frequency arrows or adding a new receiver row. +- Bidirectional Highpoint Scanner interlock: starting either scanner releases the other, and FM Scan Monitor resumes safely when Highpoint stops. - Password-free public tuner handover: a visitor can explicitly pause an active scan, use the normal tuner controls or tune directly from any received-station card, and release them without gaining scanner administration rights. - Public station-card tuning remains available when an administrator has already paused or stopped the scanner; no extra visitor pause is required in that state. - Automatic scan resume ten seconds after the last controlling tab disconnects, with refresh/reconnect recovery and support for multiple control leases. @@ -67,7 +70,7 @@ The report is generated locally and displayed directly in the browser's native P ## Installation -Copy `FMScanMonitorPlugin.js` and the complete `FMScanMonitor` directory into the Webserver `plugins` directory. Restart FM-DX Webserver, open Administration > Plugins, enable **FM Scan Monitor by Aurel [v0.9.8]**, save, restart once more when enabling it for the first time, and reload the receiver page while logged in as administrator. +Copy `FMScanMonitorPlugin.js` and the complete `FMScanMonitor` directory into the Webserver `plugins` directory. Restart FM-DX Webserver, open Administration > Plugins, enable **FM Scan Monitor by Aurel [v0.9.13]**, save, restart once more when enabling it for the first time, and reload the receiver page while logged in as administrator. Upgrading from an earlier `FMScanMobile` release automatically copies the existing browser settings, hidden-frequency rules, distance filter and temporary public-control state to the new `fmScanMonitor` storage keys. The legacy values are retained as a safe fallback. diff --git a/FMScanMonitor/fm-scan-monitor-client.test.js b/FMScanMonitor/fm-scan-monitor-client.test.js new file mode 100644 index 0000000..211ea67 --- /dev/null +++ b/FMScanMonitor/fm-scan-monitor-client.test.js @@ -0,0 +1,64 @@ +'use strict'; + +const assert = require('node:assert/strict'); +const fs = require('fs'); +const path = require('path'); +const test = require('node:test'); + +const clientSource = fs.readFileSync(path.join(__dirname, 'fm-scan-monitor.js'), 'utf8'); +const serverSource = fs.readFileSync(path.join(__dirname, 'fm-scan-monitor_server.js'), 'utf8'); + +test('stops the Highpoint Scanner before starting FM Scan Monitor', () => { + const startFunction = clientSource.indexOf('function startScan(continuous)'); + const stopCall = clientSource.indexOf('stopCompetingScanner();', startFunction); + const startCall = clientSource.indexOf("sendCommand('start'", startFunction); + + assert.notEqual(startFunction, -1); + assert.ok(stopCall > startFunction); + assert.ok(startCall > stopCall); +}); + +test('uses the legacy Scanner stop protocol without changing the Scanner plugin', () => { + const stopFunction = clientSource.indexOf('function stopCompetingScanner()'); + const startFunction = clientSource.indexOf('function startScan(continuous)', stopFunction); + const implementation = clientSource.slice(stopFunction, startFunction); + + assert.match(implementation, /type:\s*'Scanner'/); + assert.match(implementation, /status:\s*'command'/); + assert.match(implementation, /Scan:\s*'off'/); + assert.match(implementation, /source:\s*'FM Scan Monitor'/); +}); + +test('mounts the scan status inside the existing Frequency card instead of the tuning arrows', () => { + const statusFunction = clientSource.indexOf('function ensureTunerStatusControl()'); + const actionFunction = clientSource.indexOf('function handleTunerStatusAction', statusFunction); + const implementation = clientSource.slice(statusFunction, actionFunction); + + assert.notEqual(statusFunction, -1); + assert.match(implementation, /getElementById\('freq-container'\)/); + assert.match(implementation, /frequencyPanel\.appendChild\(control\)/); + assert.doesNotMatch(implementation, /tune-buttons/); +}); + +test('provides Frequency-card actions for public and administrator tuner handover', () => { + assert.match(clientSource, /action = 'public-control'/); + assert.match(clientSource, /action = 'pause-admin'/); + assert.match(clientSource, /action = 'resume-admin'/); + assert.match(clientSource, /text = 'Highpoint Scanner active'/); +}); + +test('adds a Webserver header shortcut that opens and reveals Scan Monitor', () => { + assert.match(clientSource, /addIconToPluginPanel\(/); + assert.match(clientSource, /'Scan Monitor'/); + assert.match(clientSource, /'tower-broadcast'/); + assert.match(clientSource, /publicList\.open = true/); + assert.match(clientSource, /publicList\.scrollIntoView/); + assert.match(clientSource, /launcher\.click\(\)/); +}); + +test('resumes immediately after an explicit tuner release while retaining disconnect grace', () => { + assert.match(serverSource, /releasePublicControl\(ws, \{ immediate: true \}\)/); + assert.match(serverSource, /function releasePublicControl\(ws, \{ immediate = false \} = \{\}\)/); + assert.match(serverSource, /if \(immediate\)[\s\S]*engine\.resume\(\)/); + assert.match(serverSource, /function removeClient\(ws\)[\s\S]*releasePublicControl\(ws\)/); +}); diff --git a/FMScanMonitor/fm-scan-monitor-engine.js b/FMScanMonitor/fm-scan-monitor-engine.js index 86b0714..4a72335 100644 --- a/FMScanMonitor/fm-scan-monitor-engine.js +++ b/FMScanMonitor/fm-scan-monitor-engine.js @@ -14,6 +14,8 @@ const DEFAULTS = Object.freeze({ }); const RDS_SAMPLE_INTERVAL = 300; +const TUNER_FREQUENCY_CONFIRM_TIMEOUT = 1500; +const TUNER_FREQUENCY_CONFIRM_INTERVAL = 100; const RDS_MINIMUM_VOTES = 3; const RDS_MAX_ACCEPTED_PS_ERROR = 4; const ADJACENT_CHANNEL_GAP_DB = 15; @@ -35,6 +37,22 @@ function sleep(milliseconds) { return new Promise(resolve => setTimeout(resolve, milliseconds)); } +async function retryAsync(operation, { attempts = 3, delayMs = 250 } = {}) { + if (typeof operation !== 'function') throw new TypeError('A retry operation is required.'); + const maximumAttempts = Math.max(1, Math.trunc(Number(attempts) || 1)); + const retryDelay = Math.max(0, Number(delayMs) || 0); + let lastError = null; + for (let attempt = 1; attempt <= maximumAttempts; attempt += 1) { + try { + return await operation(attempt); + } catch (error) { + lastError = error instanceof Error ? error : new Error(String(error)); + if (attempt < maximumAttempts && retryDelay > 0) await sleep(retryDelay); + } + } + throw lastError; +} + function normalizePi(value) { const pi = String(value ?? '').trim().toUpperCase(); return /^[0-9A-F]{4}$/.test(pi) && pi !== '0000' ? pi : ''; @@ -88,6 +106,27 @@ function publicTuneAccessMode({ return Math.max(0, Number(publicControlUsers) || 0) === 0 ? 'administrator-pause' : ''; } +function highpointScannerState(message) { + if (!message || message.type !== 'Scanner' || !message.value || typeof message.value !== 'object') return null; + const status = String(message.value.status ?? '').trim().toLowerCase(); + if (!['broadcast', 'command', 'send'].includes(status)) return null; + const scan = String(message.value.Scan ?? '').trim().toLowerCase(); + if (scan === 'on') return true; + if (scan === 'off') return false; + return null; +} + +function shouldResumeAfterHighpoint({ + scanning = false, + paused = false, + pauseReason = '', + publicControlUsers = 0 +} = {}) { + if (!scanning) return false; + if (!paused) return true; + return Math.max(0, Number(publicControlUsers) || 0) > 0 || pauseReason === 'Tuner in use'; +} + function destinationPoint(latitude, longitude, distanceKm, azimuthDeg) { if (![latitude, longitude, distanceKm, azimuthDeg].every(Number.isFinite)) return null; const angularDistance = distanceKm / 6371; @@ -335,8 +374,9 @@ class FMScanMonitorEngine { return true; } - pause(reason = 'Tuner in use') { - if (!this.scanning || this.paused) return false; + pause(reason = 'Tuner in use', { replaceReason = false } = {}) { + if (!this.scanning) return false; + if (this.paused && !replaceReason) return false; this.paused = true; this.pauseReason = String(reason || 'Tuner in use'); this.frequency = null; @@ -459,14 +499,15 @@ class FMScanMonitorEngine { this.frequency = frequency; this.status = this.continuous ? 'Continuous scan' : 'Single scan'; this.publish(); + const confirmationDeadline = Date.now() + Math.max(cfg.tuningDelay, TUNER_FREQUENCY_CONFIRM_TIMEOUT); const sent = await this.sendCommand(`T${Math.round(frequency * 1000)}`); if (!sent) throw new Error('Receiver connection is not ready.'); const tuningWait = await this.sleepInterruptible(cfg.tuningDelay); if (tuningWait !== 'complete') return tuningWait; - const initialSample = normalizeTelemetry(await this.readTelemetry()); - if (this.stopRequested) return 'stopped'; - if (this.paused) return 'paused'; - if (!this.matchesFrequency(initialSample, frequency, cfg.step)) return 'complete'; + const confirmation = await this.waitForTunedSample(frequency, cfg.step, confirmationDeadline); + if (confirmation.outcome !== 'complete') return confirmation.outcome; + const initialSample = confirmation.sample; + if (!initialSample) return 'complete'; if (!Number.isFinite(initialSample.signal) || initialSample.signal < cfg.signalThreshold) return 'complete'; this.status = `Station detected - waiting ${(cfg.rdsTimeout / 1000).toFixed(1)} s for data`; @@ -487,6 +528,27 @@ class FMScanMonitorEngine { return 'complete'; } + async waitForTunedSample(frequency, step, deadline) { + while (!this.stopRequested && !this.paused) { + const sample = normalizeTelemetry(await this.readTelemetry()); + if (this.stopRequested) return { outcome: 'stopped', sample: null }; + if (this.paused) return { outcome: 'paused', sample: null }; + if (this.matchesFrequency(sample, frequency, step)) { + return { outcome: 'complete', sample }; + } + + const remaining = deadline - Date.now(); + if (remaining <= 0) return { outcome: 'complete', sample: null }; + const confirmationWait = await this.sleepInterruptible( + Math.min(TUNER_FREQUENCY_CONFIRM_INTERVAL, remaining) + ); + if (confirmationWait !== 'complete') { + return { outcome: confirmationWait, sample: null }; + } + } + return { outcome: this.stopRequested ? 'stopped' : 'paused', sample: null }; + } + matchesFrequency(sample, frequency, step) { return Boolean(sample && Math.abs(sample.frequency - frequency) <= Math.max(step / 2, 0.006)); } @@ -587,6 +649,9 @@ module.exports = { normalizeTelemetry, normalizeTransmitterCountry, parsePsErrors, + highpointScannerState, publicTuneAccessMode, - sanitizeSettings + retryAsync, + sanitizeSettings, + shouldResumeAfterHighpoint }; diff --git a/FMScanMonitor/fm-scan-monitor-engine.test.js b/FMScanMonitor/fm-scan-monitor-engine.test.js index 09abb12..e0053ce 100644 --- a/FMScanMonitor/fm-scan-monitor-engine.test.js +++ b/FMScanMonitor/fm-scan-monitor-engine.test.js @@ -5,12 +5,48 @@ const assert = require('node:assert/strict'); const { FMScanMonitorEngine, consolidateTelemetrySamples, + highpointScannerState, normalizeTelemetry, normalizeTransmitterCountry, publicTuneAccessMode, - sanitizeSettings + retryAsync, + sanitizeSettings, + shouldResumeAfterHighpoint } = require('./fm-scan-monitor-engine'); +test('recognizes Highpoint Scanner ownership broadcasts and commands', () => { + assert.equal(highpointScannerState({ type: 'Scanner', value: { status: 'command', Scan: 'on' } }), true); + assert.equal(highpointScannerState({ type: 'Scanner', value: { status: 'broadcast', Scan: 'off' } }), false); + assert.equal(highpointScannerState({ type: 'Scanner', value: { status: 'send', Scan: 'on' } }), true); + assert.equal(highpointScannerState({ type: 'Scanner', value: { status: 'request', Scan: 'on' } }), null); + assert.equal(highpointScannerState({ type: 'Scanner', value: { status: 'command', Scan: '' } }), null); + assert.equal(highpointScannerState({ type: 'Other', value: { Scan: 'on' } }), null); +}); + +test('retries a transient telemetry operation and returns the recovered value', async () => { + let calls = 0; + const value = await retryAsync(async attempt => { + calls += 1; + if (attempt < 3) throw new Error('temporary telemetry delay'); + return { frequency: 100.9 }; + }, { attempts: 3, delayMs: 0 }); + + assert.deepEqual(value, { frequency: 100.9 }); + assert.equal(calls, 3); +}); + +test('preserves the last telemetry error after all retry attempts fail', async () => { + let calls = 0; + await assert.rejects( + retryAsync(async () => { + calls += 1; + throw new Error(`failure ${calls}`); + }, { attempts: 3, delayMs: 0 }), + /failure 3/ + ); + assert.equal(calls, 3); +}); + test('sanitizes the shared LOC and DX distance thresholds', () => { const configured = sanitizeSettings({ localDistanceKm: 15, dxDistanceKm: 250 }); assert.equal(configured.localDistanceKm, 15); @@ -62,6 +98,28 @@ test('grants public station tuning only in safe scanner states', () => { assert.equal(publicTuneAccessMode({ canUsePublicTuner: false, scanning: false }), ''); }); +test('lets a competing scanner replace the current pause reason safely', () => { + const scanner = new FMScanMonitorEngine({ + sendCommand: async () => true, + readTelemetry: async () => ({}), + publish: () => {} + }); + scanner.scanning = true; + assert.equal(scanner.pause('Tuner in use'), true); + assert.equal(scanner.pause('Highpoint Scanner active', { replaceReason: true }), true); + assert.equal(scanner.paused, true); + assert.equal(scanner.pauseReason, 'Highpoint Scanner active'); + scanner.stop(); +}); + +test('resumes after Highpoint only when FM scanning was active or publicly paused', () => { + assert.equal(shouldResumeAfterHighpoint({ scanning: true, paused: false }), true); + assert.equal(shouldResumeAfterHighpoint({ scanning: true, paused: true, pauseReason: 'Tuner in use' }), true); + assert.equal(shouldResumeAfterHighpoint({ scanning: true, paused: true, publicControlUsers: 1 }), true); + assert.equal(shouldResumeAfterHighpoint({ scanning: true, paused: true, pauseReason: 'Administrator tuner control' }), false); + assert.equal(shouldResumeAfterHighpoint({ scanning: false, paused: false }), false); +}); + function telemetry({ freq = 102.2, sig = 65, pi = 'F748', ps = 'CHAMP FM', psErrors = '0,0,0,0,0,0,0,0', tx = 'Champagne FM', itu = 'F' } = {}) { return normalizeTelemetry({ freq, @@ -107,6 +165,39 @@ async function waitFor(predicate, timeoutMs = 1500) { assert.equal(predicate(), true, 'Timed out waiting for scanner state.'); } +test('waits for a slower tuner to confirm the requested frequency before measuring signal', async () => { + const commands = []; + const reportedFrequencies = [105.9, 105.9, 106.0]; + let telemetryReads = 0; + const scanner = new FMScanMonitorEngine({ + sendCommand: async command => { + commands.push(command); + return true; + }, + readTelemetry: async () => ({ + freq: reportedFrequencies[Math.min(telemetryReads++, reportedFrequencies.length - 1)], + sig: 55, + pi: '', + ps: '', + rds: false, + st: true + }), + publish: () => {} + }); + + const outcome = await scanner.scanFrequency(106.0, { + step: 0.1, + tuningDelay: 100, + signalThreshold: 30, + rdsTimeout: 0 + }); + + assert.equal(outcome, 'complete'); + assert.deepEqual(commands, ['T106000']); + assert.equal(telemetryReads, 3); + assert.equal(scanner.results.get('106.000|-').signal, 55); +}); + test('pauses without ending a continuous scan and retries the interrupted frequency on resume', async () => { const commands = []; const scanner = new FMScanMonitorEngine({ diff --git a/FMScanMonitor/fm-scan-monitor.css b/FMScanMonitor/fm-scan-monitor.css index bed6b64..eeb32c2 100644 --- a/FMScanMonitor/fm-scan-monitor.css +++ b/FMScanMonitor/fm-scan-monitor.css @@ -6,6 +6,27 @@ body.modal-open #fsm-root { display: none !important; } .fsm-launcher { position: static; min-width: 78px; height: 52px; padding: 0 16px; border: 0; border-radius: 26px; background: var(--color-3, #20a4d8); color: #fff; box-shadow: 0 8px 24px #0008; font-weight: 700; cursor: pointer; } .fsm-launcher i { margin-right: 7px; } button.fsm-tuner-locked { opacity: .35; cursor: not-allowed; filter: grayscale(1); } +#freq-container.fsm-frequency-host { position: relative; box-sizing: border-box; } +#freq-container.fsm-frequency-host #data-frequency { position: relative; top: -16px; display: block; } +.fsm-tuner-status { position: absolute; z-index: 3; right: 8px; bottom: -1px; left: 8px; display: flex; align-items: center; justify-content: center; gap: 7px; height: 31px; min-width: 0; padding: 0 7px; border: 1px solid #ffffff24; border-radius: 8px; background: var(--color-1, rgb(39, 42, 49)); color: var(--color-text, #fff); box-shadow: none; font-family: 'Titillium Web', sans-serif; font-size: 14px; font-style: normal; font-synthesis: none; line-height: 1; text-rendering: auto; -webkit-font-smoothing: auto; white-space: nowrap; overflow: hidden; } +.fsm-tuner-status-brand { flex: 0 0 auto; color: var(--color-3, #5cc8f3); font-size: 9px; font-weight: 700; letter-spacing: .06em; } +.fsm-tuner-status-dot { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: #88919d; box-shadow: 0 0 7px currentColor; } +.fsm-tuner-status-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; font-weight: 600; letter-spacing: 0; line-height: 1.25; } +.fsm-tuner-status button { flex: 0 0 auto; width: auto !important; height: 25px !important; min-height: 25px !important; margin: 0 !important; padding: 0 9px !important; border: 1px solid #ff9ca2 !important; border-radius: 6px !important; background: #b93838 !important; color: #fff !important; font: inherit; font-weight: 600; cursor: pointer; } +.fsm-tuner-status button[hidden] { display: none !important; } +.fsm-tuner-status .fsm-public-countdown { display: none; visibility: visible; min-width: 34px; color: #ff6872; font-size: 11px; font-weight: 700; opacity: 1; } +.fsm-tuner-status .fsm-public-countdown.is-visible { display: inline; } +.fsm-tuner-status.is-running .fsm-tuner-status-dot { color: #22c55e; background: #22c55e; animation: fsm-running-sparkle 1.35s ease-in-out infinite; } +.fsm-tuner-status.is-paused .fsm-tuner-status-dot { color: #ef4444; background: #ef4444; } +.fsm-tuner-status.is-paused button { border-color: #79d6a7 !important; background: #277554 !important; } +.fsm-tuner-status.is-highpoint .fsm-tuner-status-dot { color: #f59e0b; background: #f59e0b; } +.fsm-tuner-status.is-error .fsm-tuner-status-dot { color: #ef4444; background: #ef4444; } +.fsm-tuner-status.is-connecting .fsm-tuner-status-dot { animation: fsm-status-pulse 1s ease-in-out infinite; } +.fsm-toolbar-control-hidden { display: none !important; } +.fsm-header-shortcut span { display: inline-block; line-height: 1; white-space: nowrap; } +@keyframes fsm-status-pulse { 50% { opacity: .3; } } +@keyframes fsm-running-sparkle { 0%, 100% { opacity: .7; transform: scale(.85); box-shadow: 0 0 4px currentColor; } 50% { opacity: 1; transform: scale(1.15); box-shadow: 0 0 11px 3px currentColor; } } +@keyframes fsm-running-sparkle-soft { 0%, 100% { opacity: .72; box-shadow: 0 0 4px currentColor; } 50% { opacity: 1; box-shadow: 0 0 10px 2px currentColor; } } .fsm-backdrop { position: fixed; inset: 0; z-index: 9991; background: #0009; backdrop-filter: blur(2px); } .fsm-panel { position: fixed; z-index: 9992; top: 0; right: 0; width: min(520px, 100vw); height: 100dvh; transform: translateX(105%); transition: transform .2s ease; background: var(--color-main, #202228); color: var(--color-text, #eee); box-shadow: -12px 0 36px #0009; overflow: hidden; } .fsm-panel.is-open { transform: translateX(0); } @@ -45,6 +66,9 @@ button.fsm-tuner-locked { opacity: .35; cursor: not-allowed; filter: grayscale(1 #fsm-root[data-access="public"] .fsm-result { grid-template-columns: minmax(0, 1fr); } .fsm-dialog { width: min(480px, calc(100vw - 24px)); border: 1px solid #ffffff22; border-radius: 16px; padding: 0; background: var(--color-main, #202228); color: var(--color-text, #eee); }.fsm-dialog::backdrop { background: #000a; }.fsm-dialog header { display: flex; justify-content: space-between; align-items: center; padding: 14px; border-bottom: 1px solid #ffffff1c; }.fsm-dialog form { margin: 0; }.fsm-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 14px; }.fsm-form-grid label { font-size: 12px; }.fsm-form-grid input, .fsm-form-grid select { display: block; width: 100%; height: 42px; margin-top: 4px; border: 1px solid #ffffff22; border-radius: 8px; background: var(--color-1, #272a31); color: var(--color-text, #fff); padding: 0 10px; }.fsm-check { display: flex; gap: 8px; padding: 0 14px 14px; font-size: 13px; }.fsm-settings-reset { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 14px 14px; padding: 12px; border: 1px solid #ffffff18; border-radius: 10px; background: #ffffff08; }.fsm-settings-reset strong, .fsm-settings-reset small { display: block; }.fsm-settings-reset small { margin-top: 3px; opacity: .65; }.fsm-settings-reset button { flex: 0 0 auto; min-height: 42px; padding: 8px 10px; border: 1px solid #ffffff22; border-radius: 9px; background: #ffffff0c; color: inherit; font-weight: 700; }.fsm-settings-reset button:disabled { opacity: .4; }.fsm-settings-reset button i { margin-right: 5px; }.fsm-dialog footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px; border-top: 1px solid #ffffff1c; } @media (max-width: 768px) { #af-list { width: 100%; height: 28px !important; min-height: 28px; max-height: 28px !important; overflow-x: auto !important; overflow-y: hidden !important; overscroll-behavior-x: contain; } #af-list ul { display: flex !important; flex-flow: row nowrap !important; align-items: center; width: max-content; min-width: 100%; height: 28px !important; margin: 0 !important; padding: 0 2px !important; white-space: nowrap; } #af-list ul li { display: block !important; flex: 0 0 40px; margin-right: 5px; } } -@media (max-width: 430px) { #fsm-root { width: 100%; margin: 0; padding: 10px 8px 110px; }.fsm-public-list { width: 100%; }.fsm-public-content { padding: 9px; }.fsm-form-grid { grid-template-columns: 1fr; }.fsm-settings-reset { align-items: stretch; flex-direction: column; }.fsm-settings-reset button { width: 100%; }.fsm-toolbar, #fsm-root[data-access="public"] .fsm-toolbar { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 44px 44px 44px; gap: 6px; }.fsm-filter-control, .fsm-sort-control, .fsm-distance-control { grid-column: span 2; }.fsm-toolbar button { width: 44px; height: 46px; min-height: 46px; padding: 0; }.fsm-toolbar button i { margin: 0; }.fsm-toolbar-label { display: none; }.fsm-public-control.is-paused-status .fsm-toolbar-label { display: inline; font-size: 8px; line-height: 1.05; white-space: normal; text-transform: uppercase; }.fsm-public-control-group { position: relative; width: 44px; }.fsm-public-control-group .fsm-public-countdown { position: absolute; z-index: 1; top: -7px; right: 0; min-width: 36px; padding: 2px 4px; border: 1px solid #ff5a6477; border-radius: 8px; background: var(--color-main, #202228); font-size: 10px; }.fsm-result { column-gap: 8px; }.fsm-result-actions { gap: 4px; }.fsm-result-actions button { width: 40px; min-height: 40px; padding: 0; }.fsm-result-actions i { margin: 0; }.fsm-action-label { display: none; }.fsm-result-details { grid-template-columns: repeat(2, minmax(0, 1fr)); } } +@media (max-width: 768px) { #freq-container.fsm-frequency-host #data-frequency { top: -10px; }.fsm-tuner-status { right: 5px; bottom: -2px; left: 5px; gap: 5px; height: 32px; padding: 0 5px; border-radius: 8px; font-size: 11px; }.fsm-tuner-status-brand { font-size: 8px; }.fsm-tuner-status button { height: 26px !important; min-height: 26px !important; padding: 0 7px !important; }.fsm-tuner-status .fsm-public-countdown { min-width: 34px; font-size: 11px; } } +@media (max-width: 430px) { .fsm-tuner-status-brand { display: none; }.fsm-tuner-status button { padding: 0 6px !important; } } +@media (max-width: 430px) { #fsm-root { width: 100%; margin: 0; padding: 10px 8px 110px; }.fsm-public-list { width: 100%; }.fsm-public-content { padding: 9px; }.fsm-form-grid { grid-template-columns: 1fr; }.fsm-settings-reset { align-items: stretch; flex-direction: column; }.fsm-settings-reset button { width: 100%; }.fsm-toolbar, #fsm-root[data-access="public"] .fsm-toolbar { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 44px 44px 44px; gap: 6px; }.fsm-filter-control, .fsm-sort-control, .fsm-distance-control { grid-column: span 2; }.fsm-toolbar button { width: 44px; height: 46px; min-height: 46px; padding: 0; }.fsm-toolbar button i { margin: 0; }.fsm-toolbar-label { display: none; }.fsm-public-control.is-paused-status .fsm-toolbar-label { display: inline; font-size: 8px; line-height: 1.05; white-space: normal; text-transform: uppercase; }.fsm-public-control-group { position: relative; width: 44px; }.fsm-public-control-group .fsm-public-countdown { position: absolute; z-index: 1; top: -7px; right: 0; min-width: 36px; padding: 2px 4px; border: 1px solid #ff5a6477; border-radius: 8px; background: var(--color-main, #202228); font-size: 11px; }.fsm-result { column-gap: 8px; }.fsm-result-actions { gap: 4px; }.fsm-result-actions button { width: 40px; min-height: 40px; padding: 0; }.fsm-result-actions i { margin: 0; }.fsm-action-label { display: none; }.fsm-result-details { grid-template-columns: repeat(2, minmax(0, 1fr)); } } +@media (max-width: 430px) { #fsm-root[data-access="public"] { margin-top: max(-72px, -6vh); } } @media (max-width: 430px) { #fsm-pdf, #fsm-export, .fsm-public-control { width: 44px; height: 46px; min-height: 46px; } } -@media (prefers-reduced-motion: reduce) { .fsm-panel, .fsm-result, .fsm-result-details-hint i { transition: none; } } +@media (prefers-reduced-motion: reduce) { .fsm-panel, .fsm-result, .fsm-result-details-hint i { transition: none; }.fsm-tuner-status.is-running .fsm-tuner-status-dot { animation: fsm-running-sparkle-soft 1.8s ease-in-out infinite; } } diff --git a/FMScanMonitor/fm-scan-monitor.js b/FMScanMonitor/fm-scan-monitor.js index 4e3c3c4..6119ea2 100644 --- a/FMScanMonitor/fm-scan-monitor.js +++ b/FMScanMonitor/fm-scan-monitor.js @@ -2,6 +2,7 @@ 'use strict'; const PLUGIN_ID = 'fsm'; + const HEADER_SHORTCUT_ID = `${PLUGIN_ID}-header-shortcut`; const ADJACENT_SPILLOVER_GAP_DB = 15; const SETTINGS_KEY = 'fmScanMonitor.settings.v1'; const HIDDEN_KEY = 'fmScanMonitor.hidden.v1'; @@ -42,6 +43,7 @@ results: new Map(), scanning: false, paused: false, + pauseReason: null, continuous: false, cycles: 0, frequency: null, @@ -53,6 +55,7 @@ canUsePublicTuner: false, publicControlDeadline: null, publicControlUnlimited: false, + highpointScannerActive: false, minimumDistanceKm: Math.max(0, Number(localStorage.getItem(DISTANCE_FILTER_KEY)) || 0) }; @@ -251,7 +254,7 @@ const link = document.createElement('link'); link.id = `${PLUGIN_ID}-styles`; link.rel = 'stylesheet'; - link.href = 'js/plugins/FMScanMonitor/fm-scan-monitor.css?v=0.9.8'; + link.href = 'js/plugins/FMScanMonitor/fm-scan-monitor.css?v=0.9.13-7'; document.head.appendChild(link); } @@ -261,6 +264,77 @@ else document.body.appendChild(root); } + function revealScanMonitor() { + const publicList = document.getElementById(`${PLUGIN_ID}-public-list`); + const scrollBehavior = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches ? 'auto' : 'smooth'; + if (publicList) { + publicList.open = true; + window.requestAnimationFrame(() => publicList.scrollIntoView({ behavior: scrollBehavior, block: 'start' })); + return; + } + + const launcher = document.getElementById(`${PLUGIN_ID}-launcher`); + if (!launcher) return; + launcher.scrollIntoView({ behavior: scrollBehavior, block: 'center' }); + launcher.click(); + } + + function ensureHeaderShortcut(attempt = 0) { + if (document.getElementById(HEADER_SHORTCUT_ID)) return; + if (typeof addIconToPluginPanel !== 'function' || !document.querySelector('.scrollable-container')) { + if (attempt < 200) window.setTimeout(() => ensureHeaderShortcut(attempt + 1), 50); + return; + } + addIconToPluginPanel( + HEADER_SHORTCUT_ID, + 'Scan Monitor', + 'solid', + 'tower-broadcast', + 'Open FM Scan Monitor' + ); + const shortcut = document.getElementById(HEADER_SHORTCUT_ID); + if (!shortcut) return; + shortcut.classList.add('fsm-header-shortcut'); + shortcut.setAttribute('aria-label', 'Open FM Scan Monitor'); + shortcut.addEventListener('click', revealScanMonitor); + } + + function ensureTunerStatusControl() { + const existing = document.getElementById(`${PLUGIN_ID}-tuner-status`); + if (existing) return existing; + const frequencyPanel = document.getElementById('freq-container'); + if (!frequencyPanel) return null; + frequencyPanel.classList.add('fsm-frequency-host'); + const control = document.createElement('div'); + control.id = `${PLUGIN_ID}-tuner-status`; + control.className = 'fsm-tuner-status is-idle'; + control.setAttribute('role', 'group'); + control.setAttribute('aria-label', 'FM Scan Monitor tuner control'); + control.innerHTML = ` + FM SCAN + + Scan idle + 10:00 + `; + control.querySelector('button').addEventListener('click', handleTunerStatusAction); + frequencyPanel.appendChild(control); + document.querySelector(`#${PLUGIN_ID}-root .fsm-public-control-group`)?.classList.add('fsm-toolbar-control-hidden'); + return control; + } + + function handleTunerStatusAction(event) { + event.preventDefault(); + event.stopPropagation(); + const action = event.currentTarget.dataset.action || ''; + if (action === 'public-control') { + togglePublicControl(); + } else if (action === 'pause-admin') { + sendCommand('pause-admin'); + } else if (action === 'resume-admin') { + sendCommand('resume-admin'); + } + } + function buildInterface() { const admin = isAdmin(); const root = document.createElement('div'); @@ -320,12 +394,12 @@ return; } root.innerHTML = ` -