diff --git a/btc-UI/electron/main.js b/btc-UI/electron/main.js index 88ae035..35c3692 100644 --- a/btc-UI/electron/main.js +++ b/btc-UI/electron/main.js @@ -5,6 +5,9 @@ const fs = require('fs'); let mainWindow; let screenWindow; let currentSharedData = null; // Store latest data for initial sync +let currentSelectedVenue = 'Select Venue'; +let currentSelectedRace = 1; +let currentStopMessage = ''; function createWindows() { const displays = screen.getAllDisplays(); @@ -45,6 +48,11 @@ function createWindows() { if (currentSharedData && screenWindow.webContents) { 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()); @@ -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 ipcMain.on('sync-stop-message', (event, message) => { + currentStopMessage = message; if (screenWindow && screenWindow.webContents) { screenWindow.webContents.send('update-stop-message', message); } diff --git a/btc-UI/electron/preload.js b/btc-UI/electron/preload.js index 767cc37..afc5373 100644 --- a/btc-UI/electron/preload.js +++ b/btc-UI/electron/preload.js @@ -9,4 +9,8 @@ contextBridge.exposeInMainWorld('electronAPI', { // Add these new lines syncStopMessage: (message) => ipcRenderer.send('sync-stop-message', 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)), }); \ No newline at end of file diff --git a/btc-UI/src/app/components/navbar/navbar.component.ts b/btc-UI/src/app/components/navbar/navbar.component.ts index a1af320..0cb1382 100755 --- a/btc-UI/src/app/components/navbar/navbar.component.ts +++ b/btc-UI/src/app/components/navbar/navbar.component.ts @@ -144,6 +144,8 @@ export class NavbarComponent implements OnInit, OnDestroy { this.currentDate = this.getTodayDate(); console.log('[INIT] Current venue:', this.currentVenue, 'date:', this.currentDate); + this.selectedVenue = localStorage.getItem('selectedVenue') || this.raceCardData?.venue || 'Select Venue'; + if (this.currentVenue) { try { 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 { @@ -531,6 +540,11 @@ export class NavbarComponent implements OnInit, OnDestroy { value: this.selectedVenue, }); + const electronAPI = (window as any).electronAPI; + if (electronAPI) { + electronAPI.syncSelectedVenue(this.selectedVenue); + } + const newVenue = venue.toUpperCase(); if (newVenue !== this.currentVenue) { this.currentVenue = newVenue; @@ -559,6 +573,11 @@ export class NavbarComponent implements OnInit, OnDestroy { value: this.selectedRace, }); + const electronAPI = (window as any).electronAPI; + if (electronAPI) { + electronAPI.syncSelectedRace(this.selectedRace); + } + const raceList = this.raceCardData?.raceVenueRaces?.races ?? []; const selectedRaceEntry = raceList[this.selectedRace - 1] ?? []; @@ -723,4 +742,4 @@ export class NavbarComponent implements OnInit, OnDestroy { trackByHorse(index: number, item: number): number { return item; } -} +} \ No newline at end of file diff --git a/btc-UI/src/app/components/shared-display/shared-display.component.ts b/btc-UI/src/app/components/shared-display/shared-display.component.ts index 88a0ca6..99c083f 100644 --- a/btc-UI/src/app/components/shared-display/shared-display.component.ts +++ b/btc-UI/src/app/components/shared-display/shared-display.component.ts @@ -53,22 +53,10 @@ export class SharedDisplayComponent implements OnInit { ngOnInit(): void { console.log('[SHARED DISPLAY] Initializing, electronAPI available:', !!window.electronAPI); 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) { - window.electronAPI.onUpdateSharedData((data: SharedData) => { + const electronAPI = (window as any).electronAPI; + if (electronAPI) { + electronAPI.onUpdateSharedData((data: SharedData) => { console.log('[SHARED DISPLAY] Received IPC data:', data); if (!data) return; 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) }))); 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 { - console.error('[SHARED DISPLAY] electronAPI or onUpdateSharedData not available'); + console.error('[SHARED DISPLAY] electronAPI not available'); } } } \ No newline at end of file diff --git a/btc-UI/src/electron.d.ts b/btc-UI/src/electron.d.ts index 902899b..698ee3b 100644 --- a/btc-UI/src/electron.d.ts +++ b/btc-UI/src/electron.d.ts @@ -7,6 +7,10 @@ interface ElectronAPI { // Add these new lines syncStopMessage: (message: string) => 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 {