mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-12 20:16:15 -08:00
* feat(epg): add vertical list view for the live EPG panel
Add an EPG list view — a vertical, single-day programme list — as an
alternative rendering of the live EPG panel, selectable via a new
Settings → EPG → "Guide view" toggle (epgViewMode: 'timeline' | 'list',
default 'timeline' so existing users see no change).
- New EpgListViewComponent (app-epg-list-view) mirrors
EpgTimelineComponent's input/output contract 1:1, so all four live
hosts (M3U player, unified live tab, Xtream, Stalker) swap the panel
with a plain @if and identical bindings.
- Reuses the shared view-agnostic EPG modules (classifyTimelineWhen,
hasProgramsForDateKey, epg-archive.util catch-up gating,
epg-summary.util collapsed-summary maths, epg-date helpers,
EpgProgrammeDialogService, app-epg-timeline-empty-state) — no
duplicated logic.
- Rows show time range, title, optional description, live progress on
the on-air row, catch-up "Watch" on past rows when archive playback
is available, and a details dialog; keyboard activation guards
nested buttons (target === currentTarget).
- Auto-focuses the on-air row on channel select, restores it across
collapse/expand remounts, and shows a sticky in-flow "On now" strip
(never overlaying rows) when the current programme is scrolled away;
all scroll maths is rect-based relative to the scroller.
- List mode raises only the inline panel height via an epg--list
modifier (--epg-inline-height clamp); timeline and collapsed heights
are unchanged.
- Setting flows end-to-end (Settings interface → DEFAULT_SETTINGS →
SettingsStore/StorageMap → segmented control in the EPG section);
Electron-only UI, PWA stays on the timeline default. i18n keys added
to all 18 locales.
- Tests: new component/row/utils/scroll-controller specs, settings
persistence spec, swap tests in all four host specs, and Electron
E2E for the settings round-trip and the rendered list view. Docs
updated (m3u-playlist-module.md).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* fix(epg): address list-view review findings from Codex and Greptile
- Reset the list view to today when a new channel's programme set
arrives while the user is parked on another day (timeline parity):
the scroll controller now keys by the full programme-set identity
(programsFocusKey) and commits today before focusing, instead of
silently stranding the new channel on the stale day. (Codex P2)
- Centralise the 'timeline' fallback as a resolvedEpgViewMode computed
on SettingsStore; the four live hosts consume the derived signal
instead of duplicating the `?? 'timeline'` expression. (Greptile P2)
- Extract the component's reactive plumbing into
registerEpgListViewEffects(), bringing the component back under the
300-line guideline (290). (Greptile P2)
- Controller spec rewritten around programme-set fixtures with new
coverage: return-to-today on channel switch, day navigation left
alone, no-takeover when today has no data, empty-set no-op.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* fix(epg): drop malformed programmes from the list-view day filter
Reject programmes whose stop is not after their start in
buildEpgListRows — same as the timeline's buildTimelineBlocks. Bad
provider data would otherwise render impossible time ranges and could
even be offered as catch-up playable. (Codex P2 on e6fd0d08)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
280 lines
9.4 KiB
TypeScript
280 lines
9.4 KiB
TypeScript
import { computed, inject } from '@angular/core';
|
|
import {
|
|
patchState,
|
|
signalStore,
|
|
withComputed,
|
|
withHooks,
|
|
withMethods,
|
|
withState,
|
|
} from '@ngrx/signals';
|
|
import { StorageMap } from '@ngx-pwa/local-storage';
|
|
import { firstValueFrom } from 'rxjs';
|
|
import {
|
|
DEFAULT_DASHBOARD_RAILS_SETTINGS,
|
|
ElectronBridgeTrustOptions,
|
|
EpgViewMode,
|
|
Language,
|
|
Settings,
|
|
StartupBehavior,
|
|
STORE_KEY,
|
|
StreamFormat,
|
|
Theme,
|
|
VideoPlayer,
|
|
normalizeDashboardRailsSettings,
|
|
} from '@iptvnator/shared/interfaces';
|
|
|
|
const DEFAULT_SETTINGS: Settings = {
|
|
player: VideoPlayer.VideoJs,
|
|
streamFormat: StreamFormat.AutoStreamFormat,
|
|
openStreamOnDoubleClick: false,
|
|
language: Language.ENGLISH,
|
|
showCaptions: false,
|
|
showDashboard: true,
|
|
startupBehavior: StartupBehavior.FirstView,
|
|
showExternalPlaybackBar: true,
|
|
theme: Theme.SystemTheme,
|
|
mpvPlayerPath: '',
|
|
mpvPlayerArguments: '',
|
|
mpvReuseInstance: false,
|
|
vlcPlayerPath: '',
|
|
vlcPlayerArguments: '',
|
|
vlcReuseInstance: false,
|
|
remoteControl: false,
|
|
remoteControlPort: 8765,
|
|
epgUrl: [],
|
|
downloadFolder: '',
|
|
recordingFolder: '',
|
|
coverSize: 'medium',
|
|
epgViewMode: 'timeline',
|
|
dashboardRails: DEFAULT_DASHBOARD_RAILS_SETTINGS,
|
|
preferUploadedEpgOverXtream: false,
|
|
trustedPrivateNetworkEpgUrls: [],
|
|
trustedInsecureTlsHosts: [],
|
|
};
|
|
|
|
let embeddedMpvPrepareScheduled = false;
|
|
|
|
function scheduleEmbeddedMpvPrepare(): void {
|
|
if (
|
|
embeddedMpvPrepareScheduled ||
|
|
typeof window === 'undefined' ||
|
|
!window.electron?.prepareEmbeddedMpv
|
|
) {
|
|
return;
|
|
}
|
|
|
|
embeddedMpvPrepareScheduled = true;
|
|
const prepare = () => {
|
|
void window.electron
|
|
.prepareEmbeddedMpv?.()
|
|
.then((support) => {
|
|
if (!support?.supported) {
|
|
embeddedMpvPrepareScheduled = false;
|
|
}
|
|
})
|
|
.catch((error) => {
|
|
embeddedMpvPrepareScheduled = false;
|
|
console.warn('Failed to prepare embedded MPV.', error);
|
|
});
|
|
};
|
|
const idleWindow = window as typeof window & {
|
|
requestIdleCallback?: (
|
|
callback: IdleRequestCallback,
|
|
options?: IdleRequestOptions
|
|
) => number;
|
|
};
|
|
|
|
if (idleWindow.requestIdleCallback) {
|
|
idleWindow.requestIdleCallback(prepare, { timeout: 5000 });
|
|
} else {
|
|
window.setTimeout(prepare, 2000);
|
|
}
|
|
}
|
|
|
|
export const SettingsStore = signalStore(
|
|
{ providedIn: 'root' },
|
|
withState<Settings>(DEFAULT_SETTINGS),
|
|
withComputed((store) => ({
|
|
/**
|
|
* Live EPG panel layout with the `'timeline'` default applied — the
|
|
* single source of truth for the four live hosts, so the fallback is
|
|
* not duplicated per call-site.
|
|
*/
|
|
resolvedEpgViewMode: computed<EpgViewMode>(
|
|
() => store.epgViewMode?.() ?? 'timeline'
|
|
),
|
|
})),
|
|
withMethods((store, storage = inject(StorageMap)) => ({
|
|
async loadSettings() {
|
|
try {
|
|
const stored = await firstValueFrom(
|
|
storage.get(STORE_KEY.Settings)
|
|
);
|
|
if (stored) {
|
|
const storedSettings = stored as Partial<Settings>;
|
|
patchState(store, {
|
|
...DEFAULT_SETTINGS,
|
|
...storedSettings,
|
|
dashboardRails: normalizeDashboardRailsSettings(
|
|
storedSettings.dashboardRails
|
|
),
|
|
});
|
|
void this.sanitizeEmbeddedMpvSelection().catch((error) => {
|
|
console.warn(
|
|
'Failed to verify embedded MPV support while loading settings.',
|
|
error
|
|
);
|
|
});
|
|
}
|
|
} catch (error) {
|
|
console.error('Failed to load settings:', error);
|
|
// Keep default settings if loading fails
|
|
}
|
|
},
|
|
|
|
async updateSettings(settings: Partial<Settings>) {
|
|
patchState(store, {
|
|
...settings,
|
|
...(settings.dashboardRails !== undefined
|
|
? {
|
|
dashboardRails: normalizeDashboardRailsSettings(
|
|
settings.dashboardRails
|
|
),
|
|
}
|
|
: {}),
|
|
});
|
|
// Save the complete settings object, not just the partial update
|
|
const completeSettings = this.getSettings();
|
|
try {
|
|
await firstValueFrom(
|
|
storage.set(STORE_KEY.Settings, completeSettings)
|
|
);
|
|
if (completeSettings.player === VideoPlayer.EmbeddedMpv) {
|
|
scheduleEmbeddedMpvPrepare();
|
|
}
|
|
} catch (error) {
|
|
console.error('Failed to save settings:', error);
|
|
throw error;
|
|
}
|
|
},
|
|
|
|
getSettings() {
|
|
return {
|
|
player: store.player(),
|
|
streamFormat: store.streamFormat(),
|
|
openStreamOnDoubleClick: store.openStreamOnDoubleClick(),
|
|
language: store.language(),
|
|
showCaptions: store.showCaptions(),
|
|
showDashboard: store.showDashboard(),
|
|
startupBehavior: store.startupBehavior(),
|
|
showExternalPlaybackBar:
|
|
store.showExternalPlaybackBar?.() ??
|
|
DEFAULT_SETTINGS.showExternalPlaybackBar,
|
|
theme: store.theme(),
|
|
mpvPlayerPath: store.mpvPlayerPath(),
|
|
mpvPlayerArguments: store.mpvPlayerArguments(),
|
|
mpvReuseInstance: store.mpvReuseInstance(),
|
|
vlcPlayerPath: store.vlcPlayerPath(),
|
|
vlcPlayerArguments: store.vlcPlayerArguments(),
|
|
vlcReuseInstance: store.vlcReuseInstance(),
|
|
remoteControl: store.remoteControl(),
|
|
remoteControlPort: store.remoteControlPort(),
|
|
epgUrl: store.epgUrl(),
|
|
downloadFolder:
|
|
store.downloadFolder?.() ?? DEFAULT_SETTINGS.downloadFolder,
|
|
recordingFolder:
|
|
store.recordingFolder?.() ??
|
|
DEFAULT_SETTINGS.recordingFolder,
|
|
coverSize: store.coverSize?.() ?? DEFAULT_SETTINGS.coverSize,
|
|
epgViewMode:
|
|
store.epgViewMode?.() ?? DEFAULT_SETTINGS.epgViewMode,
|
|
dashboardRails: normalizeDashboardRailsSettings(
|
|
store.dashboardRails?.()
|
|
),
|
|
preferUploadedEpgOverXtream:
|
|
store.preferUploadedEpgOverXtream?.() ??
|
|
DEFAULT_SETTINGS.preferUploadedEpgOverXtream,
|
|
trustedPrivateNetworkEpgUrls:
|
|
store.trustedPrivateNetworkEpgUrls?.() ??
|
|
DEFAULT_SETTINGS.trustedPrivateNetworkEpgUrls,
|
|
trustedInsecureTlsHosts:
|
|
store.trustedInsecureTlsHosts?.() ??
|
|
DEFAULT_SETTINGS.trustedInsecureTlsHosts,
|
|
};
|
|
},
|
|
|
|
getDownloadFolder() {
|
|
return store.downloadFolder?.() ?? DEFAULT_SETTINGS.downloadFolder;
|
|
},
|
|
|
|
getRecordingFolder() {
|
|
return (
|
|
store.recordingFolder?.() ?? DEFAULT_SETTINGS.recordingFolder
|
|
);
|
|
},
|
|
|
|
getTrustOptions(): ElectronBridgeTrustOptions {
|
|
const settings = this.getSettings();
|
|
return {
|
|
trustedPrivateNetworkEpgUrls:
|
|
settings.trustedPrivateNetworkEpgUrls ?? [],
|
|
trustedInsecureTlsHosts: settings.trustedInsecureTlsHosts ?? [],
|
|
};
|
|
},
|
|
|
|
getPlayer() {
|
|
return store.player();
|
|
},
|
|
|
|
isEmbeddedPlayer() {
|
|
return (
|
|
store.player() === VideoPlayer.VideoJs ||
|
|
store.player() === VideoPlayer.Html5Player ||
|
|
store.player() === VideoPlayer.ArtPlayer ||
|
|
store.player() === VideoPlayer.EmbeddedMpv
|
|
);
|
|
},
|
|
|
|
async sanitizeEmbeddedMpvSelection() {
|
|
if (store.player() !== VideoPlayer.EmbeddedMpv) {
|
|
return;
|
|
}
|
|
|
|
if (
|
|
typeof window === 'undefined' ||
|
|
!window.electron?.getEmbeddedMpvSupport
|
|
) {
|
|
await this.updateSettings({
|
|
player: DEFAULT_SETTINGS.player,
|
|
});
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const support = await window.electron.getEmbeddedMpvSupport();
|
|
if (!support.supported) {
|
|
await this.updateSettings({
|
|
player: DEFAULT_SETTINGS.player,
|
|
});
|
|
return;
|
|
}
|
|
|
|
scheduleEmbeddedMpvPrepare();
|
|
} catch (error) {
|
|
console.warn(
|
|
'Failed to verify embedded MPV support; reverting to the default inline player.',
|
|
error
|
|
);
|
|
await this.updateSettings({
|
|
player: DEFAULT_SETTINGS.player,
|
|
});
|
|
}
|
|
},
|
|
})),
|
|
withHooks({
|
|
onInit(store) {
|
|
store.loadSettings();
|
|
},
|
|
})
|
|
);
|