can show screen with Electron
This commit is contained in:
@@ -1,56 +1,25 @@
|
||||
const {_android: android} = require('playwright');
|
||||
const ExcelUtil = require("./src/excel/ExcelUtil");
|
||||
const CommandorPage = require("./src/workers/CommandorPage");
|
||||
const {MongoManager, formatDate} = require("./src/workers/mongo_manager");
|
||||
const {app, BrowserWindow} = require('electron')
|
||||
const path = require("path");
|
||||
|
||||
const mongoManager = new MongoManager();
|
||||
|
||||
let excelUtil = new ExcelUtil();
|
||||
let contactList = excelUtil.readContacts()
|
||||
mongoManager.connect().then(r =>
|
||||
|
||||
android.devices().then((devices) => {
|
||||
let segmentNumber = contactList.length / devices.length;
|
||||
for (let i = 0; i < devices.length; i++) {
|
||||
startWithList(contactList.slice(i * segmentNumber, segmentNumber * (i + 1)), devices[i]);
|
||||
const createWindow = () => {
|
||||
const win = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
webPreferences: {
|
||||
preload: path.join(__dirname, 'preload.js')
|
||||
}
|
||||
}))
|
||||
});
|
||||
|
||||
// Connect to the device.
|
||||
|
||||
async function needToBook(contact, mongoManager) {
|
||||
let collectionName = formatDate(new Date())
|
||||
let alreadBooked = await mongoManager.getAllSuccessfulItemsForDay(collectionName)
|
||||
let toReturn = true;
|
||||
await alreadBooked.forEach((bookedItem) => {
|
||||
if (bookedItem.email === contact.mail) {
|
||||
toReturn = false;
|
||||
}
|
||||
}
|
||||
)
|
||||
return toReturn
|
||||
win.loadFile('index.html');
|
||||
}
|
||||
|
||||
async function startBook(contactPojo, device) {
|
||||
console.log(`Model: ${device.model()}`);
|
||||
console.log(`Serial: ${device.serial()}`);
|
||||
if (await needToBook(contactPojo, mongoManager)) {
|
||||
let commandor = new CommandorPage(contactPojo, device, mongoManager);
|
||||
//read contacts form excel
|
||||
return await commandor.loadPage();
|
||||
} else {
|
||||
console.log("do not send request --> skip")
|
||||
}
|
||||
}
|
||||
app.whenReady().then(() => {
|
||||
createWindow();
|
||||
app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
async function startWithList(contacts, device) {
|
||||
await contacts.reduce(async (promise, contactPojo) => {
|
||||
// This line will wait for the last async function to finish.
|
||||
// The first iteration uses an already resolved Promise
|
||||
// so, it will immediately continue.
|
||||
await promise;
|
||||
const contents = await startBook(contactPojo, device);
|
||||
console.log(contents);
|
||||
}, Promise.resolve());
|
||||
}
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') app.quit()
|
||||
})
|
||||
Reference in New Issue
Block a user