Skip to content

Commit

Permalink
Fixed tray icon and limit to 5 messages on screen
Browse files Browse the repository at this point in the history
  • Loading branch information
MickeyUK committed Oct 19, 2023
1 parent 4db4643 commit ead7659
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
Smash-Soda-Overlay-win32-x64
7 changes: 7 additions & 0 deletions app/modules/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ function chat() { }
*/
chat.inputEnabled = false;

chat.messages = 5;

/**
* Adds a message to the chat window.
*
Expand Down Expand Up @@ -48,6 +50,11 @@ chat.addMessage = function (guest, message) {
div.innerHTML = msg;
document.getElementById("chat-messages").prepend(div);

// If chat is full, remove last message
if (document.getElementById("chat-messages").children.length > chat.messages) {
document.getElementById("chat-messages").lastChild.remove();
}

const timer = setTimeout(() => {
div.classList.add("fade-out");
div.onanimationend = function () {
Expand Down
25 changes: 22 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Import all the required Electron components
*/
const { electron, app, BrowserWindow, ipcMain, globalShortcut, Menu, Tray } = require('electron');
const { electron, app, BrowserWindow, ipcMain, globalShortcut, Menu, Tray, nativeImage } = require('electron');

/**
* Import all the required Node.js components
Expand All @@ -24,6 +24,11 @@ let tray = null;
// Create the websocket server
const server = new Server({ port: 9002 });

/**
* Was a connection made to Soda?
*/
let sodaConnected = false;

/**
* The list of messages to send to the renderer
*/
Expand Down Expand Up @@ -127,7 +132,15 @@ app.whenReady().then(() => {
// Register all the shortcut keys
registerShortcuts();

tray = new Tray('img/icon.ico')
var iconPath = path.join(__dirname, '/img/icon.ico');
let trayIcon = nativeImage.createFromPath(iconPath);

tray = new Tray(trayIcon);
trayIcon = trayIcon.resize({
width: 16,
height: 16
});

const contextMenu = Menu.buildFromTemplate([
{ label: 'Quit', click: () => { app.quit(); } },
])
Expand All @@ -153,8 +166,14 @@ app.on('window-all-closed', function () {

// Listen for new connections
server.on('connection', (ws) => {
sodaConnected = true;
console.log('New client connected!');
ws.on('close', () => console.log('Client has disconnected!'));
ws.on('close', () => {
console.log('Client has disconnected!');
if (sodaConnected) {
app.quit();
}
});

ws.on('message', (message) => {
console.log('Received: %s', message);
Expand Down

0 comments on commit ead7659

Please sign in to comment.