feat : btno fetching properly for electron
This commit is contained in:
parent
68bad8d8d7
commit
c52b22a1ee
@ -1,5 +1,6 @@
|
|||||||
const { app, BrowserWindow, screen, ipcMain } = require('electron');
|
const { app, BrowserWindow, screen, ipcMain } = require('electron');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
let mainWindow;
|
let mainWindow;
|
||||||
let screenWindow;
|
let screenWindow;
|
||||||
@ -20,7 +21,7 @@ function createWindows() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mainWindow.loadURL('http://10.83.77.61:4200/login');
|
mainWindow.loadURL('http://10.74.231.124:4200/login');
|
||||||
|
|
||||||
screenWindow = new BrowserWindow({
|
screenWindow = new BrowserWindow({
|
||||||
x: secondary.bounds.x,
|
x: secondary.bounds.x,
|
||||||
@ -35,10 +36,23 @@ function createWindows() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
screenWindow.loadURL('http://10.83.77.61:4200/shared-display');
|
screenWindow.loadURL('http://10.74.231.124:4200/shared-display');
|
||||||
|
|
||||||
ipcMain.on('open-second-screen', () => screenWindow.show());
|
ipcMain.on('open-second-screen', () => screenWindow.show());
|
||||||
ipcMain.on('close-second-screen', () => screenWindow.hide());
|
ipcMain.on('close-second-screen', () => screenWindow.hide());
|
||||||
|
|
||||||
|
// ✅ IPC to return BTID
|
||||||
|
ipcMain.handle('get-btid', () => {
|
||||||
|
try {
|
||||||
|
const filePath = path.join(process.env.HOME || process.env.USERPROFILE, 'BTID', 'betting.txt');
|
||||||
|
const content = fs.readFileSync(filePath, 'utf-8');
|
||||||
|
const match = content.match(/Btid\s*=\s*(\d+)/i);
|
||||||
|
return match ? match[1] : null;
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error reading betting.txt:', err);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
app.whenReady().then(createWindows);
|
app.whenReady().then(createWindows);
|
||||||
|
|||||||
@ -3,4 +3,7 @@ const { contextBridge, ipcRenderer } = require('electron');
|
|||||||
contextBridge.exposeInMainWorld('electronAPI', {
|
contextBridge.exposeInMainWorld('electronAPI', {
|
||||||
openSecondScreen: () => ipcRenderer.send('open-second-screen'),
|
openSecondScreen: () => ipcRenderer.send('open-second-screen'),
|
||||||
closeSecondScreen: () => ipcRenderer.send('close-second-screen'),
|
closeSecondScreen: () => ipcRenderer.send('close-second-screen'),
|
||||||
});
|
|
||||||
|
// ✅ Ask main process for Btid
|
||||||
|
getBtid: () => ipcRenderer.invoke('get-btid')
|
||||||
|
});
|
||||||
@ -12,7 +12,7 @@
|
|||||||
</span>
|
</span>
|
||||||
|
|
||||||
<span class="btno-label me-3">
|
<span class="btno-label me-3">
|
||||||
<b>B.T.No: 1111</b>
|
<b>B.T.No: </b> {{ btid }}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,8 @@ export class NavbarComponent implements OnInit, OnDestroy {
|
|||||||
screenWidth: number = window.innerWidth;
|
screenWidth: number = window.innerWidth;
|
||||||
private subscription!: Subscription;
|
private subscription!: Subscription;
|
||||||
userName: string = '';
|
userName: string = '';
|
||||||
|
btid: string | null = null;
|
||||||
|
|
||||||
liveStatusOk: boolean = true;
|
liveStatusOk: boolean = true;
|
||||||
|
|
||||||
showVenueModal = false;
|
showVenueModal = false;
|
||||||
@ -76,6 +77,7 @@ export class NavbarComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.userName = localStorage.getItem('userName') || '';
|
this.userName = localStorage.getItem('userName') || '';
|
||||||
|
this.btid = localStorage.getItem('btid');
|
||||||
// Use NgZone to run setInterval outside Angular's change detection
|
// Use NgZone to run setInterval outside Angular's change detection
|
||||||
this.zone.runOutsideAngular(() => {
|
this.zone.runOutsideAngular(() => {
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
|
|||||||
@ -215,69 +215,74 @@ export class LoginComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ✅ Updated onSubmit with BTID
|
||||||
|
async onSubmit(): Promise<void> {
|
||||||
|
if (this.loginForm.invalid) {
|
||||||
|
this.loginForm.markAllAsTouched();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
onSubmit(): void {
|
const { email, password } = this.loginForm.value;
|
||||||
if (this.loginForm.invalid) {
|
|
||||||
this.loginForm.markAllAsTouched();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { email, password } = this.loginForm.value;
|
this.btcService.userLogin(email, password).subscribe({
|
||||||
this.btcService.userLogin(email, password).subscribe({
|
next: async (response) => {
|
||||||
next: (response) => {
|
const employee = response.body;
|
||||||
const employee = response.body;
|
console.log('🧠 Raw employee response:', employee);
|
||||||
console.log('🧠 Raw employee response:', employee);
|
|
||||||
|
|
||||||
const userName = employee?.userName || 'Unknown User';
|
const userName = employee?.userName || 'Unknown User';
|
||||||
const employeeId = employee?.userIdNumber || email;
|
const employeeId = employee?.userIdNumber || email;
|
||||||
|
|
||||||
console.log('✅ Parsed name:', userName);
|
console.log('✅ Parsed name:', userName);
|
||||||
console.log('✅ Parsed ID:', employeeId);
|
console.log('✅ Parsed ID:', employeeId);
|
||||||
|
|
||||||
this.passwordStatus = true;
|
this.passwordStatus = true;
|
||||||
|
|
||||||
// Prepare print data
|
// ✅ Fetch BTID from Electron preload
|
||||||
const printData = {
|
const btid = await (window as any).electronAPI?.getBtid?.();
|
||||||
name: userName,
|
console.log("📦 BTID from file:", btid);
|
||||||
employeeId: employeeId,
|
|
||||||
action: 'login',
|
|
||||||
type: 'login' // ← ADD THIS
|
|
||||||
};
|
|
||||||
|
|
||||||
|
// Prepare print data
|
||||||
|
const printData = {
|
||||||
|
name: userName,
|
||||||
|
employeeId: employeeId,
|
||||||
|
action: 'login',
|
||||||
|
type: 'login'
|
||||||
|
};
|
||||||
|
|
||||||
// Store in localStorage
|
// ✅ Store in localStorage
|
||||||
localStorage.setItem('userName', userName);
|
localStorage.setItem('userName', userName);
|
||||||
localStorage.setItem('employeeId', employeeId);
|
localStorage.setItem('employeeId', employeeId);
|
||||||
localStorage.setItem('password', password);
|
localStorage.setItem('password', password);
|
||||||
|
localStorage.setItem('btid', btid || "unknown");
|
||||||
|
|
||||||
// Optional print logic
|
// ✅ Optional second screen + navigate
|
||||||
fetch('http://localhost:9100/print', {
|
// fetch('http://localhost:9100/print', {
|
||||||
method: 'POST',
|
// method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
// headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify(printData),
|
// body: JSON.stringify(printData),
|
||||||
})
|
// })
|
||||||
.then((res) => {
|
// .then((res) => {
|
||||||
if (!res.ok) throw new Error('Print failed');
|
// if (!res.ok) throw new Error('Print failed');
|
||||||
console.log('🖨️ Print successful');
|
// console.log('🖨️ Print successful');
|
||||||
// Open second screen
|
// Open second screen
|
||||||
(window as any).electronAPI?.openSecondScreen?.();
|
(window as any).electronAPI?.openSecondScreen?.();
|
||||||
|
|
||||||
// // Navigate to home
|
// // Navigate to home
|
||||||
this.router.navigate(['/home']);
|
this.router.navigate(['/home']);
|
||||||
})
|
// })
|
||||||
.catch((err) => {
|
// .catch((err) => {
|
||||||
console.error('‼️ Print failed', err);
|
// console.error('‼️ Print failed', err);
|
||||||
this.loginError = 'Login OK, but printing failed.';
|
// this.loginError = 'Login OK, but printing failed.';
|
||||||
});
|
// });
|
||||||
|
|
||||||
|
|
||||||
},
|
// },
|
||||||
|
// error: () => {
|
||||||
|
// this.loginError = 'Invalid login credentials';
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
error: () => {
|
|
||||||
this.loginError = 'Invalid login credentials';
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
showConfirmModal : boolean = false;
|
showConfirmModal : boolean = false;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user