Skip to content

Commit

Permalink
✨ add customEvent lib for main with example
Browse files Browse the repository at this point in the history
  • Loading branch information
kiomarzsss committed Jun 4, 2024
1 parent a6975b3 commit 99e4d8f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions release/app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/main/ipcListeners/wp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { logMetadata, logPath } from './log';
import { getUserSettings, handleWpErrors, setStuffPath } from '../lib/wp';
import { defaultSettings } from '../../defaultSettings';
import { regeditVbsDirPath } from '../main';
import { customEvent } from '../lib/customEvent';

const simpleLog = log.create('simpleLog');
simpleLog.transports.console.format = '{text}';
Expand Down Expand Up @@ -44,12 +45,14 @@ ipcMain.on('wp-start', async (event) => {
const sendConnectedSignalToRenderer = () => {
if (connectedFlags[0] && connectedFlags[1]) {
event.reply('wp-start', true);
customEvent.emit('zombie');
}
};

const sendDisconnectedSignalToRenderer = () => {
if (disconnectedFlags[0] && disconnectedFlags[1]) {
event.reply('wp-end', true);
customEvent.emit('zombie');
}
};

Expand Down
15 changes: 15 additions & 0 deletions src/main/lib/customEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import EventEmitter from 'events';

export const customEvent = new EventEmitter();

/*
EXAMPLE: 👇
*/

// listen for an event
customEvent.on('greet', () => {
console.log('Hello world!');
});

// trigger an event
customEvent.emit('greet');
9 changes: 9 additions & 0 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import './ipc';
import { wpAssetPath, wpBinPath } from './ipcListeners/wp';
import { devPlayground } from './playground';
import { logMetadata } from './ipcListeners/log';
import { customEvent } from './lib/customEvent';

let mainWindow: BrowserWindow | null = null;

Expand All @@ -34,6 +35,14 @@ export const binAssetsPath = path.join(
);
export const regeditVbsDirPath = path.join(binAssetsPath, 'vbs');

customEvent.on('zombie', () => {
console.log('🧟 HELLO WORLD HELLO WORLD 🧟');
console.log('🧟 HELLO WORLD HELLO WORLD 🧟');
console.log('🧟 HELLO WORLD HELLO WORLD 🧟');
console.log('🧟 HELLO WORLD HELLO WORLD 🧟');
console.log('🧟 HELLO WORLD HELLO WORLD 🧟');
});

if (!gotTheLock) {
log.info("did'nt create new instance since there was already one running.");
app.exit(0);
Expand Down

0 comments on commit 99e4d8f

Please sign in to comment.