Skip to content

442: maintain references between socket.io connection events #486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ElectronNET.Host/api/browserView.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BrowserView } from 'electron';
const browserViews: Electron.BrowserView[] = [];
const browserViews: BrowserView[] = (global['browserViews'] = global['browserViews'] || []) as BrowserView[];
let browserView: BrowserView, electronSocket;

const browserViewApi = (socket: SocketIO.Socket) => {
Expand Down
2 changes: 1 addition & 1 deletion ElectronNET.Host/api/browserWindows.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BrowserWindow, Menu, nativeImage } from 'electron';
import { browserViewMediateService } from './browserView';
const path = require('path');
const windows: Electron.BrowserWindow[] = [];
const windows: Electron.BrowserWindow[] = (global['browserWindows'] = global['browserWindows'] || []) as Electron.BrowserWindow[];
let readyToShowWindowsIds: number[] = [];
let window, lastOptions, electronSocket;
let mainWindowURL;
Expand Down
2 changes: 1 addition & 1 deletion ElectronNET.Host/api/menu.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Menu, BrowserWindow } from 'electron';
const contextMenuItems = [];
const contextMenuItems = (global['contextMenuItems'] = global['contextMenuItems'] || []);
let electronSocket;

export = (socket: SocketIO.Socket) => {
Expand Down
29 changes: 14 additions & 15 deletions ElectronNET.Host/api/notification.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
"use strict";
const electron_1 = require("electron");
const notifications = [];
let electronSocket;
module.exports = (socket) => {
var electron_1 = require("electron");
var notifications = (global['notifications'] = global['notifications'] || []);
var electronSocket;
module.exports = function (socket) {
electronSocket = socket;
socket.on('createNotification', (options) => {
const notification = new electron_1.Notification(options);
let haveEvent = false;
socket.on('createNotification', function (options) {
var notification = new electron_1.Notification(options);
var haveEvent = false;
if (options.showID) {
haveEvent = true;
notification.on('show', () => {
notification.on('show', function () {
electronSocket.emit('NotificationEventShow', options.showID);
});
}
if (options.clickID) {
haveEvent = true;
notification.on('click', () => {
notification.on('click', function () {
electronSocket.emit('NotificationEventClick', options.clickID);
});
}
if (options.closeID) {
haveEvent = true;
notification.on('close', () => {
notification.on('close', function () {
electronSocket.emit('NotificationEventClose', options.closeID);
});
}
if (options.replyID) {
haveEvent = true;
notification.on('reply', (event, value) => {
notification.on('reply', function (event, value) {
electronSocket.emit('NotificationEventReply', [options.replyID, value]);
});
}
if (options.actionID) {
haveEvent = true;
notification.on('action', (event, value) => {
notification.on('action', function (event, value) {
electronSocket.emit('NotificationEventAction', [options.actionID, value]);
});
}
Expand All @@ -42,9 +42,8 @@ module.exports = (socket) => {
}
notification.show();
});
socket.on('notificationIsSupported', () => {
const isSupported = electron_1.Notification.isSupported;
socket.on('notificationIsSupported', function () {
var isSupported = electron_1.Notification.isSupported;
electronSocket.emit('notificationIsSupportedComplete', isSupported);
});
};
//# sourceMappingURL=notification.js.map
2 changes: 1 addition & 1 deletion ElectronNET.Host/api/notification.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Notification } from 'electron';
const notifications: Electron.Notification[] = [];
const notifications: Electron.Notification[] = (global['notifications'] = global['notifications'] || []) as Electron.Notification[];
let electronSocket;

export = (socket: SocketIO.Socket) => {
Expand Down
105 changes: 52 additions & 53 deletions ElectronNET.Host/api/tray.js
Original file line number Diff line number Diff line change
@@ -1,108 +1,107 @@
"use strict";
const electron_1 = require("electron");
let tray;
let electronSocket;
module.exports = (socket) => {
var electron_1 = require("electron");
var tray = (global['tray'] = global['tray'] || { value: null });
var electronSocket;
module.exports = function (socket) {
electronSocket = socket;
socket.on('register-tray-click', (id) => {
if (tray) {
tray.on('click', (event, bounds) => {
socket.on('register-tray-click', function (id) {
if (tray.value) {
tray.value.on('click', function (event, bounds) {
electronSocket.emit('tray-click-event' + id, [event.__proto__, bounds]);
});
}
});
socket.on('register-tray-right-click', (id) => {
if (tray) {
tray.on('right-click', (event, bounds) => {
socket.on('register-tray-right-click', function (id) {
if (tray.value) {
tray.value.on('right-click', function (event, bounds) {
electronSocket.emit('tray-right-click-event' + id, [event.__proto__, bounds]);
});
}
});
socket.on('register-tray-double-click', (id) => {
if (tray) {
tray.on('double-click', (event, bounds) => {
socket.on('register-tray-double-click', function (id) {
if (tray.value) {
tray.value.on('double-click', function (event, bounds) {
electronSocket.emit('tray-double-click-event' + id, [event.__proto__, bounds]);
});
}
});
socket.on('register-tray-balloon-show', (id) => {
if (tray) {
tray.on('balloon-show', () => {
socket.on('register-tray-balloon-show', function (id) {
if (tray.value) {
tray.value.on('balloon-show', function () {
electronSocket.emit('tray-balloon-show-event' + id);
});
}
});
socket.on('register-tray-balloon-click', (id) => {
if (tray) {
tray.on('balloon-click', () => {
socket.on('register-tray-balloon-click', function (id) {
if (tray.value) {
tray.value.on('balloon-click', function () {
electronSocket.emit('tray-balloon-click-event' + id);
});
}
});
socket.on('register-tray-balloon-closed', (id) => {
if (tray) {
tray.on('balloon-closed', () => {
socket.on('register-tray-balloon-closed', function (id) {
if (tray.value) {
tray.value.on('balloon-closed', function () {
electronSocket.emit('tray-balloon-closed-event' + id);
});
}
});
socket.on('create-tray', (image, menuItems) => {
const trayIcon = electron_1.nativeImage.createFromPath(image);
tray = new electron_1.Tray(trayIcon);
socket.on('create-tray', function (image, menuItems) {
var trayIcon = electron_1.nativeImage.createFromPath(image);
tray.value = new electron_1.Tray(trayIcon);
if (menuItems) {
const menu = electron_1.Menu.buildFromTemplate(menuItems);
addMenuItemClickConnector(menu.items, (id) => {
var menu = electron_1.Menu.buildFromTemplate(menuItems);
addMenuItemClickConnector(menu.items, function (id) {
electronSocket.emit('trayMenuItemClicked', id);
});
tray.setContextMenu(menu);
tray.value.setContextMenu(menu);
}
});
socket.on('tray-destroy', () => {
if (tray) {
tray.destroy();
socket.on('tray-destroy', function () {
if (tray.value) {
tray.value.destroy();
}
});
socket.on('tray-setImage', (image) => {
if (tray) {
tray.setImage(image);
socket.on('tray-setImage', function (image) {
if (tray.value) {
tray.value.setImage(image);
}
});
socket.on('tray-setPressedImage', (image) => {
if (tray) {
const img = electron_1.nativeImage.createFromPath(image);
tray.setPressedImage(img);
socket.on('tray-setPressedImage', function (image) {
if (tray.value) {
var img = electron_1.nativeImage.createFromPath(image);
tray.value.setPressedImage(img);
}
});
socket.on('tray-setToolTip', (toolTip) => {
if (tray) {
tray.setToolTip(toolTip);
socket.on('tray-setToolTip', function (toolTip) {
if (tray.value) {
tray.value.setToolTip(toolTip);
}
});
socket.on('tray-setTitle', (title) => {
if (tray) {
tray.setTitle(title);
socket.on('tray-setTitle', function (title) {
if (tray.value) {
tray.value.setTitle(title);
}
});
socket.on('tray-displayBalloon', (options) => {
if (tray) {
tray.displayBalloon(options);
socket.on('tray-displayBalloon', function (options) {
if (tray.value) {
tray.value.displayBalloon(options);
}
});
socket.on('tray-isDestroyed', () => {
if (tray) {
const isDestroyed = tray.isDestroyed();
socket.on('tray-isDestroyed', function () {
if (tray.value) {
var isDestroyed = tray.value.isDestroyed();
electronSocket.emit('tray-isDestroyedCompleted', isDestroyed);
}
});
function addMenuItemClickConnector(menuItems, callback) {
menuItems.forEach((item) => {
menuItems.forEach(function (item) {
if (item.submenu && item.submenu.items.length > 0) {
addMenuItemClickConnector(item.submenu.items, callback);
}
if ('id' in item && item.id) {
item.click = () => { callback(item.id); };
item.click = function () { callback(item.id); };
}
});
}
};
//# sourceMappingURL=tray.js.map
58 changes: 29 additions & 29 deletions ElectronNET.Host/api/tray.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
import { Menu, Tray, nativeImage } from 'electron';
let tray: Electron.Tray;
let tray: { value: Electron.Tray } = (global['$tray'] = global['tray'] || { value: null });
let electronSocket;

export = (socket: SocketIO.Socket) => {
electronSocket = socket;
socket.on('register-tray-click', (id) => {
if (tray) {
tray.on('click', (event, bounds) => {
if (tray.value) {
tray.value.on('click', (event, bounds) => {
electronSocket.emit('tray-click-event' + id, [(<any>event).__proto__, bounds]);
});
}
});

socket.on('register-tray-right-click', (id) => {
if (tray) {
tray.on('right-click', (event, bounds) => {
if (tray.value) {
tray.value.on('right-click', (event, bounds) => {
electronSocket.emit('tray-right-click-event' + id, [(<any>event).__proto__, bounds]);
});
}
});

socket.on('register-tray-double-click', (id) => {
if (tray) {
tray.on('double-click', (event, bounds) => {
if (tray.value) {
tray.value.on('double-click', (event, bounds) => {
electronSocket.emit('tray-double-click-event' + id, [(<any>event).__proto__, bounds]);
});
}
});

socket.on('register-tray-balloon-show', (id) => {
if (tray) {
tray.on('balloon-show', () => {
if (tray.value) {
tray.value.on('balloon-show', () => {
electronSocket.emit('tray-balloon-show-event' + id);
});
}
});

socket.on('register-tray-balloon-click', (id) => {
if (tray) {
tray.on('balloon-click', () => {
if (tray.value) {
tray.value.on('balloon-click', () => {
electronSocket.emit('tray-balloon-click-event' + id);
});
}
});

socket.on('register-tray-balloon-closed', (id) => {
if (tray) {
tray.on('balloon-closed', () => {
if (tray.value) {
tray.value.on('balloon-closed', () => {
electronSocket.emit('tray-balloon-closed-event' + id);
});
}
Expand All @@ -55,58 +55,58 @@ export = (socket: SocketIO.Socket) => {
socket.on('create-tray', (image, menuItems) => {
const trayIcon = nativeImage.createFromPath(image);

tray = new Tray(trayIcon);
tray.value = new Tray(trayIcon);

if (menuItems) {
const menu = Menu.buildFromTemplate(menuItems);

addMenuItemClickConnector(menu.items, (id) => {
electronSocket.emit('trayMenuItemClicked', id);
});
tray.setContextMenu(menu);
tray.value.setContextMenu(menu);
}
});

socket.on('tray-destroy', () => {
if (tray) {
tray.destroy();
if (tray.value) {
tray.value.destroy();
}
});

socket.on('tray-setImage', (image) => {
if (tray) {
tray.setImage(image);
if (tray.value) {
tray.value.setImage(image);
}
});

socket.on('tray-setPressedImage', (image) => {
if (tray) {
if (tray.value) {
const img = nativeImage.createFromPath(image);
tray.setPressedImage(img);
tray.value.setPressedImage(img);
}
});

socket.on('tray-setToolTip', (toolTip) => {
if (tray) {
tray.setToolTip(toolTip);
if (tray.value) {
tray.value.setToolTip(toolTip);
}
});

socket.on('tray-setTitle', (title) => {
if (tray) {
tray.setTitle(title);
if (tray.value) {
tray.value.setTitle(title);
}
});

socket.on('tray-displayBalloon', (options) => {
if (tray) {
tray.displayBalloon(options);
if (tray.value) {
tray.value.displayBalloon(options);
}
});

socket.on('tray-isDestroyed', () => {
if (tray) {
const isDestroyed = tray.isDestroyed();
if (tray.value) {
const isDestroyed = tray.value.isDestroyed();
electronSocket.emit('tray-isDestroyedCompleted', isDestroyed);
}
});
Expand Down
Loading