fix : venue changes accordingly in 2nd screen

This commit is contained in:
karthik 2025-09-18 14:07:11 +05:30
parent d493963add
commit 2cb45a6857
5 changed files with 69 additions and 17 deletions

View File

@ -5,6 +5,9 @@ const fs = require('fs');
let mainWindow; let mainWindow;
let screenWindow; let screenWindow;
let currentSharedData = null; // Store latest data for initial sync let currentSharedData = null; // Store latest data for initial sync
let currentSelectedVenue = 'Select Venue';
let currentSelectedRace = 1;
let currentStopMessage = '';
function createWindows() { function createWindows() {
const displays = screen.getAllDisplays(); const displays = screen.getAllDisplays();
@ -45,6 +48,11 @@ function createWindows() {
if (currentSharedData && screenWindow.webContents) { if (currentSharedData && screenWindow.webContents) {
screenWindow.webContents.send('update-shared-data', currentSharedData); screenWindow.webContents.send('update-shared-data', currentSharedData);
} }
if (screenWindow.webContents) {
screenWindow.webContents.send('update-selected-venue', currentSelectedVenue);
screenWindow.webContents.send('update-selected-race', currentSelectedRace);
screenWindow.webContents.send('update-stop-message', currentStopMessage);
}
}); });
ipcMain.on('close-second-screen', () => screenWindow.hide()); ipcMain.on('close-second-screen', () => screenWindow.hide());
@ -57,8 +65,25 @@ function createWindows() {
} }
}); });
// Handle selected venue sync
ipcMain.on('sync-selected-venue', (event, venue) => {
currentSelectedVenue = venue;
if (screenWindow && screenWindow.webContents) {
screenWindow.webContents.send('update-selected-venue', venue);
}
});
// Handle selected race sync
ipcMain.on('sync-selected-race', (event, race) => {
currentSelectedRace = race;
if (screenWindow && screenWindow.webContents) {
screenWindow.webContents.send('update-selected-race', race);
}
});
// Add this new handler // Add this new handler
ipcMain.on('sync-stop-message', (event, message) => { ipcMain.on('sync-stop-message', (event, message) => {
currentStopMessage = message;
if (screenWindow && screenWindow.webContents) { if (screenWindow && screenWindow.webContents) {
screenWindow.webContents.send('update-stop-message', message); screenWindow.webContents.send('update-stop-message', message);
} }

View File

@ -9,4 +9,8 @@ contextBridge.exposeInMainWorld('electronAPI', {
// Add these new lines // Add these new lines
syncStopMessage: (message) => ipcRenderer.send('sync-stop-message', message), syncStopMessage: (message) => ipcRenderer.send('sync-stop-message', message),
onUpdateStopMessage: (callback) => ipcRenderer.on('update-stop-message', (event, message) => callback(message)), onUpdateStopMessage: (callback) => ipcRenderer.on('update-stop-message', (event, message) => callback(message)),
syncSelectedVenue: (venue) => ipcRenderer.send('sync-selected-venue', venue),
onUpdateSelectedVenue: (callback) => ipcRenderer.on('update-selected-venue', (event, venue) => callback(venue)),
syncSelectedRace: (race) => ipcRenderer.send('sync-selected-race', race),
onUpdateSelectedRace: (callback) => ipcRenderer.on('update-selected-race', (event, race) => callback(race)),
}); });

View File

@ -144,6 +144,8 @@ export class NavbarComponent implements OnInit, OnDestroy {
this.currentDate = this.getTodayDate(); this.currentDate = this.getTodayDate();
console.log('[INIT] Current venue:', this.currentVenue, 'date:', this.currentDate); console.log('[INIT] Current venue:', this.currentVenue, 'date:', this.currentDate);
this.selectedVenue = localStorage.getItem('selectedVenue') || this.raceCardData?.venue || 'Select Venue';
if (this.currentVenue) { if (this.currentVenue) {
try { try {
this.stopbetService.initialize(this.currentVenue, this.currentDate); this.stopbetService.initialize(this.currentVenue, this.currentDate);
@ -287,6 +289,13 @@ export class NavbarComponent implements OnInit, OnDestroy {
} }
} }
}); });
// Initial sync for venue and race
const electronAPI = (window as any).electronAPI;
if (electronAPI) {
electronAPI.syncSelectedVenue(this.selectedVenue);
electronAPI.syncSelectedRace(this.selectedRace);
}
} }
private getTodayDate(): string { private getTodayDate(): string {
@ -531,6 +540,11 @@ export class NavbarComponent implements OnInit, OnDestroy {
value: this.selectedVenue, value: this.selectedVenue,
}); });
const electronAPI = (window as any).electronAPI;
if (electronAPI) {
electronAPI.syncSelectedVenue(this.selectedVenue);
}
const newVenue = venue.toUpperCase(); const newVenue = venue.toUpperCase();
if (newVenue !== this.currentVenue) { if (newVenue !== this.currentVenue) {
this.currentVenue = newVenue; this.currentVenue = newVenue;
@ -559,6 +573,11 @@ export class NavbarComponent implements OnInit, OnDestroy {
value: this.selectedRace, value: this.selectedRace,
}); });
const electronAPI = (window as any).electronAPI;
if (electronAPI) {
electronAPI.syncSelectedRace(this.selectedRace);
}
const raceList = this.raceCardData?.raceVenueRaces?.races ?? []; const raceList = this.raceCardData?.raceVenueRaces?.races ?? [];
const selectedRaceEntry = raceList[this.selectedRace - 1] ?? []; const selectedRaceEntry = raceList[this.selectedRace - 1] ?? [];
@ -723,4 +742,4 @@ export class NavbarComponent implements OnInit, OnDestroy {
trackByHorse(index: number, item: number): number { trackByHorse(index: number, item: number): number {
return item; return item;
} }
} }

View File

@ -53,22 +53,10 @@ export class SharedDisplayComponent implements OnInit {
ngOnInit(): void { ngOnInit(): void {
console.log('[SHARED DISPLAY] Initializing, electronAPI available:', !!window.electronAPI); console.log('[SHARED DISPLAY] Initializing, electronAPI available:', !!window.electronAPI);
this.btid = localStorage.getItem('btid'); this.btid = localStorage.getItem('btid');
this.sharedStateService.sharedData$.subscribe((data) => {
console.log('[SHARED DISPLAY] Received shared data:', data);
if (!data) return;
if (data.type === 'selectedVenue') {
this.selectedVenue = data.value;
console.log('[SHARED DISPLAY] Venue updated to:', this.selectedVenue);
}
if (data.type === 'selectedRace') {
this.selectedRace = data.value;
console.log('[SHARED DISPLAY] Race updated to:', this.selectedRace);
}
this.cdRef.detectChanges();
});
if (window.electronAPI && window.electronAPI.onUpdateSharedData) { const electronAPI = (window as any).electronAPI;
window.electronAPI.onUpdateSharedData((data: SharedData) => { if (electronAPI) {
electronAPI.onUpdateSharedData((data: SharedData) => {
console.log('[SHARED DISPLAY] Received IPC data:', data); console.log('[SHARED DISPLAY] Received IPC data:', data);
if (!data) return; if (!data) return;
this.filledRows = data.filledRows || this.filledRows; this.filledRows = data.filledRows || this.filledRows;
@ -80,8 +68,20 @@ export class SharedDisplayComponent implements OnInit {
console.log('[SHARED DISPLAY] Updated filledRows:', this.filledRows.map(row => ({ ...row, numbers: JSON.stringify(row.numbers) }))); console.log('[SHARED DISPLAY] Updated filledRows:', this.filledRows.map(row => ({ ...row, numbers: JSON.stringify(row.numbers) })));
this.cdRef.detectChanges(); this.cdRef.detectChanges();
}); });
electronAPI.onUpdateSelectedVenue((venue: string) => {
this.selectedVenue = venue;
console.log('[SHARED DISPLAY] Venue updated via IPC to:', this.selectedVenue);
this.cdRef.detectChanges();
});
electronAPI.onUpdateSelectedRace((race: number) => {
this.selectedRace = race.toString();
console.log('[SHARED DISPLAY] Race updated via IPC to:', this.selectedRace);
this.cdRef.detectChanges();
});
} else { } else {
console.error('[SHARED DISPLAY] electronAPI or onUpdateSharedData not available'); console.error('[SHARED DISPLAY] electronAPI not available');
} }
} }
} }

View File

@ -7,6 +7,10 @@ interface ElectronAPI {
// Add these new lines // Add these new lines
syncStopMessage: (message: string) => void; syncStopMessage: (message: string) => void;
onUpdateStopMessage: (callback: (message: string) => void) => void; onUpdateStopMessage: (callback: (message: string) => void) => void;
syncSelectedVenue: (venue: string) => void;
onUpdateSelectedVenue: (callback: (venue: string) => void) => void;
syncSelectedRace: (race: number) => void;
onUpdateSelectedRace: (callback: (race: number) => void) => void;
} }
interface SharedData { interface SharedData {