69 lines
1.6 KiB
JavaScript
69 lines
1.6 KiB
JavaScript
import {app, BrowserWindow, ipcMain} from 'electron';
|
|
import irc from "node-irc";
|
|
import path from 'path';
|
|
import {fileURLToPath} from 'url';
|
|
|
|
const generateUID = () => {
|
|
return Math.random().toString(36).substr(2, 9);
|
|
};
|
|
|
|
const client = new irc(
|
|
'irc.libera.chat',
|
|
6667,
|
|
generateUID(),
|
|
generateUID()
|
|
)
|
|
|
|
let joinedIRC = false
|
|
client.on('ready', () => {
|
|
if(!joinedIRC) {
|
|
client.join("#PMISDE")
|
|
joinedIRC = true
|
|
}
|
|
})
|
|
|
|
let win;
|
|
|
|
const createWindow = () => {
|
|
win = new BrowserWindow({
|
|
webPreferences: {
|
|
preload: path.dirname(fileURLToPath(import.meta.url)) + '/prerender.js',
|
|
devTools: true,
|
|
nodeIntegration: true,
|
|
scrollBounce: false,
|
|
textAreasAreResizable: false,
|
|
}
|
|
});
|
|
|
|
win.fullScreen = true;
|
|
win.loadFile('html/index.html');
|
|
};
|
|
|
|
let domreadied = false
|
|
|
|
app.whenReady().then(() => {
|
|
client.connect();
|
|
ipcMain.on('message', (ev, text) => {
|
|
client.say("#PMISDE", text);
|
|
})
|
|
createWindow();
|
|
app.on('activate', () => {
|
|
if (BrowserWindow.getAllWindows().length === 0) createWindow();
|
|
});
|
|
|
|
ipcMain.on('dom-ready', () => {
|
|
if (domreadied) return
|
|
domreadied = true
|
|
console.log("DOM READY!!!!!!")
|
|
client.on('CHANMSG', ({receiver, sender, message}) => {
|
|
if (receiver === "#PMISDE") {
|
|
win.webContents.send('speak', {sender, message})
|
|
}
|
|
console.log(`Message on ${receiver} from ${sender}: ${message}`);
|
|
})
|
|
});
|
|
});
|
|
|
|
app.on('window-all-closed', () => {
|
|
if (process.platform !== 'darwin') app.quit();
|
|
});
|