Skip to content

Commit

Permalink
Fix issue kevinatown#128
Browse files Browse the repository at this point in the history
This fix is inspired by https://github.com/amirthapa27/MMM-Screencast

When autoCloseScript is called, it sends a message (mmm-screencast.exited)
to the console. If the message is received then an IPC is emitted as
well as a call to the app.quit() method.
  • Loading branch information
goldyfruit committed Oct 10, 2022
1 parent 328ad9c commit c25ebe1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
27 changes: 17 additions & 10 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ app.once('ready', () => {
const { url, position, width, height, x, y } = data;

const usingXY = x && y;

// electron
const windowOptions = {
maxHeight: height,
Expand Down Expand Up @@ -59,23 +59,18 @@ app.once('ready', () => {

//
// THIS MIGHT NEED WORK
//
//


//
// maybe something like this:
//
//
// win.webContents.on('console-message', () => {
// // do the shit to cloes the window like above
// })
//
//
// create a specific message or something to know that shit's done, or listen to whatever
// https://electronjs.org/docs/api/web-contents#event-console-message
//
//
// ipc.server.on('screenCastWindow_config', (data, socket) => {
// const { extraScript, closeOnEnd } = data;

// const doScript = `${extraScript} ${closeOnEnd ? autoCloseScript : ''}`;
// screenCastWindow.webContents.executeJavaScript(doScript, true);

Expand All @@ -87,12 +82,24 @@ app.once('ready', () => {
// ipc.server.broadcast('screenCastWindow_shown', { show: true });

const autoCloseScript = `
window.setInterval(function() {
if (document.getElementsByClassName('WEB_PAGE_TYPE_ACCOUNT_SELECTOR').length >= 1) {
console.log("mmm-screencast.exited");
}
}, 1000);
`;

screenCastWindow.webContents.on('console-message', (event, level, message, line, sourceId) => {
if (message === "mmm-screencast.exited") {
ipcInstance.server.emit(socket, 'quit');
app.quit();
}
});

screenCastWindow.show();
// screenCastWindow.webContents.openDevTools();
screenCastWindow.webContents.executeJavaScript(autoPlayScript, true);
screenCastWindow.webContents.executeJavaScript(autoCloseScript, true);
ipcInstance.emit(socket, 'APP_READY', {});
});
});
Expand Down
5 changes: 4 additions & 1 deletion node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ module.exports = NodeHelper.create({
start: function() {
this.dialServer.mmSendSocket = (n,p) => this.sendSocketNotification(n,p);
},
stop: function() {
this.dialServer.stopCast();
},
socketNotificationReceived: function(notification, payload) {
switch (notification) {
case 'SET_CONFIG':
const { x, y, position } = payload;

if (!(x && y) && !POSITIONS[position]) {
const message = 'There was an error with your positioning config. Please check your config.'
console.error(`${MODULE_NOTIFICATIONS.config_error}: ${message}`);
Expand Down

0 comments on commit c25ebe1

Please sign in to comment.