fix: settings race condition and URL deep linking

This commit is contained in:
Trevor Mears
2026-01-17 18:32:19 -08:00
parent 26ccafa3ec
commit 95591a0c84
2 changed files with 29 additions and 21 deletions
+6 -2
View File
@@ -137,9 +137,13 @@ class App {
this.navigateTo(page, false); // false = don't add to history
});
// Initialize home page
// Initialize home page first (it's needed for channel list)
await this.pages.home.init();
this.navigateTo('home', true); // true = replace history (don't add)
// Navigate to the page from URL hash, or default to home
const hash = window.location.hash.slice(1); // Remove #
const initialPage = hash && this.pages[hash] ? hash : 'home';
this.navigateTo(initialPage, true); // true = replace history (don't add)
console.log('NodeCast TV initialized');
}
+10 -6
View File
@@ -94,7 +94,7 @@ class SettingsPage {
this.updateEpgLastRefreshed();
}
initTranscodingSettings() {
async initTranscodingSettings() {
// Encoder settings
const hwEncoderSelect = document.getElementById('setting-hw-encoder');
const maxResolutionSelect = document.getElementById('setting-max-resolution');
@@ -113,9 +113,14 @@ class SettingsPage {
const userAgentCustomInput = document.getElementById('setting-user-agent-custom-tc');
const customUaContainer = document.getElementById('custom-user-agent-container-tc');
// Load current settings
if (this.app.player?.settings) {
const s = this.app.player.settings;
// Fetch settings directly from API to avoid race condition with VideoPlayer
let s;
try {
s = await API.settings.get();
} catch (err) {
console.warn('[Settings] Failed to load settings from API, using player defaults:', err);
s = this.app.player?.settings || {};
}
if (hwEncoderSelect) hwEncoderSelect.value = s.hwEncoder || 'auto';
if (maxResolutionSelect) maxResolutionSelect.value = s.maxResolution || '1080p';
@@ -131,7 +136,6 @@ class SettingsPage {
if (customUaContainer) {
customUaContainer.style.display = userAgentSelect?.value === 'custom' ? 'flex' : 'none';
}
}
// Event listeners for encoder settings
hwEncoderSelect?.addEventListener('change', () => {
@@ -152,7 +156,7 @@ class SettingsPage {
// Audio Mix Preset
const audioMixSelect = document.getElementById('setting-audio-mix');
if (audioMixSelect) {
audioMixSelect.value = this.app.player?.settings?.audioMixPreset || 'auto';
audioMixSelect.value = s.audioMixPreset || 'auto';
audioMixSelect.addEventListener('change', () => {
this.app.player.settings.audioMixPreset = audioMixSelect.value;
this.app.player.saveSettings();