Skip to content

Commit

Permalink
fixes send image
Browse files Browse the repository at this point in the history
  • Loading branch information
luizfverissimo committed May 10, 2021
1 parent b76c947 commit d630e7e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
7 changes: 5 additions & 2 deletions api/senderApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ async function sendWhatsappMessage(message, contacts, timeBefore, timeAfter, isS
await page.goto(urlCreated);
await page.waitForSelector('#side > header');
await page.waitForTimeout((Math.random() * (4 - 2) + 2) * timeBefore);
await page.keyboard.press('Enter');

if(isSendingImage) {
await page.waitForTimeout((Math.random() * (4 - 2) + 2) * timeAfter);
await page.waitForTimeout((Math.random() * (4 - 2) + 2) * timeBefore);
clipboard.writeImage(nativeImage.createFromPath(imagePath));
await page.keyboard.down('Control')
await page.keyboard.press('V')
Expand All @@ -43,6 +42,10 @@ async function sendWhatsappMessage(message, contacts, timeBefore, timeAfter, isS
await page.keyboard.press('Enter');
}

if (!isSendingImage) {
await page.keyboard.press('Enter');
}

await page.waitForTimeout((Math.random() * (4 - 2) + 2) * timeAfter);
} catch (err) {
console.log(err);
Expand Down
30 changes: 25 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function createWindow() {
const win = new BrowserWindow({
width: 1024,
height: 768,
icon: path.join(__dirname, 'assets/logo-full.png'),
icon: path.join(__dirname, 'assets/icon.ico'),
backgroundColor: '#fff',
webPreferences: {
nodeIntegration: false,
Expand All @@ -21,6 +21,8 @@ function createWindow() {
}
});

win.setMenuBarVisibility(false);

win.loadFile('index.html');
}

Expand All @@ -34,7 +36,7 @@ ipcMain.on('notify', (event, message) => {
});

ipcMain.on('imageSend', (event, path) => {
imageCopyToClipboard(path)
imageCopyToClipboard(path);
});

ipcMain.on('file', (event) => {
Expand All @@ -47,8 +49,26 @@ ipcMain.on('image', (event) => {
event.returnValue = result;
});

ipcMain.on('send', (event, message, contacts, timeBefore, timeAfter, isSendingImage, imagePath ) => {
sendWhatsappMessage(message, contacts, timeBefore, timeAfter, isSendingImage, imagePath)
});
ipcMain.on(
'send',
(
event,
message,
contacts,
timeBefore,
timeAfter,
isSendingImage,
imagePath
) => {
sendWhatsappMessage(
message,
contacts,
timeBefore,
timeAfter,
isSendingImage,
imagePath
);
}
);

app.whenReady().then(createWindow);

0 comments on commit d630e7e

Please sign in to comment.