can show screen with Electron
This commit is contained in:
@@ -0,0 +1,56 @@
|
|||||||
|
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 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]);
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
|
||||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'">
|
||||||
|
<title>爱马仕约会</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Hello World!</h1>
|
||||||
|
We are using Node.js <span id="node-version"></span>,
|
||||||
|
Chromium <span id="chrome-version"></span>,
|
||||||
|
and Electron <span id="electron-version"></span>.
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -1,56 +1,25 @@
|
|||||||
const {_android: android} = require('playwright');
|
const {app, BrowserWindow} = require('electron')
|
||||||
const ExcelUtil = require("./src/excel/ExcelUtil");
|
const path = require("path");
|
||||||
const CommandorPage = require("./src/workers/CommandorPage");
|
|
||||||
const {MongoManager, formatDate} = require("./src/workers/mongo_manager");
|
|
||||||
|
|
||||||
const mongoManager = new MongoManager();
|
const createWindow = () => {
|
||||||
|
const win = new BrowserWindow({
|
||||||
let excelUtil = new ExcelUtil();
|
width: 800,
|
||||||
let contactList = excelUtil.readContacts()
|
height: 600,
|
||||||
mongoManager.connect().then(r =>
|
webPreferences: {
|
||||||
|
preload: path.join(__dirname, 'preload.js')
|
||||||
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]);
|
|
||||||
}
|
}
|
||||||
}))
|
});
|
||||||
|
|
||||||
// Connect to the device.
|
win.loadFile('index.html');
|
||||||
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function startBook(contactPojo, device) {
|
app.whenReady().then(() => {
|
||||||
console.log(`Model: ${device.model()}`);
|
createWindow();
|
||||||
console.log(`Serial: ${device.serial()}`);
|
app.on('activate', () => {
|
||||||
if (await needToBook(contactPojo, mongoManager)) {
|
if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
||||||
let commandor = new CommandorPage(contactPojo, device, mongoManager);
|
})
|
||||||
//read contacts form excel
|
})
|
||||||
return await commandor.loadPage();
|
|
||||||
} else {
|
|
||||||
console.log("do not send request --> skip")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
app.on('window-all-closed', () => {
|
||||||
async function startWithList(contacts, device) {
|
if (process.platform !== 'darwin') app.quit()
|
||||||
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());
|
|
||||||
}
|
|
||||||
+7
-1
@@ -1,10 +1,16 @@
|
|||||||
{
|
{
|
||||||
|
"main": "main.js",
|
||||||
|
"version": "0.1",
|
||||||
|
"author": "Lei PAN",
|
||||||
|
"description": "爱马仕约会",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node main.js"
|
"start": "electron ."
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@nodegui/nodegui": "^0.57.1",
|
||||||
"axios": "^0.27.2",
|
"axios": "^0.27.2",
|
||||||
"beepbeep": "^1.3.0",
|
"beepbeep": "^1.3.0",
|
||||||
|
"electron": "^20.1.3",
|
||||||
"mongodb": "^4.9.1",
|
"mongodb": "^4.9.1",
|
||||||
"mongoose": "^6.5.4",
|
"mongoose": "^6.5.4",
|
||||||
"node-xlsx": "^0.21.0",
|
"node-xlsx": "^0.21.0",
|
||||||
|
|||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
window.addEventListener('DOMContentLoaded', () => {
|
||||||
|
const replaceText = (selector, text) => {
|
||||||
|
const element = document.getElementById(selector)
|
||||||
|
if (element) element.innerText = text
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const dependency of ['chrome', 'node', 'electron']) {
|
||||||
|
replaceText(`${dependency}-version`, process.versions[dependency])
|
||||||
|
}
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user