Skip to content

Commit b6d2ba2

Browse files
committed
store window ref globally so when splitting files its easier to access.
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
1 parent 53e2ce3 commit b6d2ba2

3 files changed

Lines changed: 15 additions & 21 deletions

File tree

‎electron_app/src/electron-main.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ electron.app.on('ready', () => {
185185
defaultHeight: 768,
186186
});
187187

188-
mainWindow = new electron.BrowserWindow({
188+
mainWindow = global.mainWindow = new electron.BrowserWindow({
189189
icon: iconPath,
190190
show: false,
191191
autoHideMenuBar: true,
@@ -203,7 +203,7 @@ electron.app.on('ready', () => {
203203
mainWindow.hide();
204204

205205
// Create trayIcon icon
206-
tray.create(mainWindow, {
206+
tray.create({
207207
icon_path: iconPath,
208208
brand: vectorConfig.brand || 'Riot',
209209
});
@@ -215,7 +215,7 @@ electron.app.on('ready', () => {
215215
}
216216

217217
mainWindow.on('closed', () => {
218-
mainWindow = null;
218+
mainWindow = global.mainWindow = null;
219219
});
220220
mainWindow.on('close', (e) => {
221221
if (!global.appQuitting && (tray.hasTray() || process.platform === 'darwin')) {

‎electron_app/src/tray.js‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ exports.hasTray = function hasTray() {
2626
return (trayIcon !== null);
2727
};
2828

29-
exports.create = function(win, config) {
29+
exports.create = function(config) {
3030
// no trays on darwin
3131
if (process.platform === 'darwin' || trayIcon) return;
3232

3333
const toggleWin = function() {
34-
if (win.isVisible() && !win.isMinimized()) {
35-
win.hide();
34+
if (global.mainWindow.isVisible() && !global.mainWindow.isMinimized()) {
35+
global.mainWindow.hide();
3636
} else {
37-
if (win.isMinimized()) win.restore();
38-
if (!win.isVisible()) win.show();
39-
win.focus();
37+
if (global.mainWindow.isMinimized()) global.mainWindow.restore();
38+
if (!global.mainWindow.isVisible()) global.mainWindow.show();
39+
global.mainWindow.focus();
4040
}
4141
};
4242

@@ -60,7 +60,7 @@ exports.create = function(win, config) {
6060
trayIcon.on('click', toggleWin);
6161

6262
let lastFavicon = null;
63-
win.webContents.on('page-favicon-updated', async function(ev, favicons) {
63+
global.mainWindow.webContents.on('page-favicon-updated', async function(ev, favicons) {
6464
let newFavicon = config.icon_path;
6565
if (favicons && favicons.length > 0 && favicons[0].startsWith('data:')) {
6666
newFavicon = favicons[0];
@@ -85,10 +85,10 @@ exports.create = function(win, config) {
8585
}
8686

8787
trayIcon.setImage(newFavicon);
88-
win.setIcon(newFavicon);
88+
global.mainWindow.setIcon(newFavicon);
8989
});
9090

91-
win.webContents.on('page-title-updated', function(ev, title) {
91+
global.mainWindow.webContents.on('page-title-updated', function(ev, title) {
9292
trayIcon.setToolTip(title);
9393
});
9494
};

‎electron_app/src/updater.js‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,11 @@ module.exports.start = function startAutoUpdate(updateBaseUrl) {
6767
}
6868

6969
ipcMain.on('install_update', installUpdate);
70-
71-
let ipcChannel;
72-
ipcMain.on('check_updates', function(event) {
73-
ipcChannel = event.sender;
74-
pollForUpdates();
75-
// event.sender.send('check_updates') // true/false/error = available(downloading)/notAvailable/error
76-
});
70+
ipcMain.on('check_updates', pollForUpdates);
7771

7872
function ipcChannelSendUpdateStatus(status) {
79-
if (ipcChannel) {
80-
ipcChannel.send('check_updates', status);
73+
if (global.mainWindow) {
74+
global.mainWindow.webContents.send('check_updates', status);
8175
}
8276
}
8377

0 commit comments

Comments
 (0)