store window ref globally so when splitting files its easier to access.
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
53e2ce33b8
commit
b6d2ba2019
3 changed files with 15 additions and 21 deletions
|
@ -185,7 +185,7 @@ electron.app.on('ready', () => {
|
||||||
defaultHeight: 768,
|
defaultHeight: 768,
|
||||||
});
|
});
|
||||||
|
|
||||||
mainWindow = new electron.BrowserWindow({
|
mainWindow = global.mainWindow = new electron.BrowserWindow({
|
||||||
icon: iconPath,
|
icon: iconPath,
|
||||||
show: false,
|
show: false,
|
||||||
autoHideMenuBar: true,
|
autoHideMenuBar: true,
|
||||||
|
@ -203,7 +203,7 @@ electron.app.on('ready', () => {
|
||||||
mainWindow.hide();
|
mainWindow.hide();
|
||||||
|
|
||||||
// Create trayIcon icon
|
// Create trayIcon icon
|
||||||
tray.create(mainWindow, {
|
tray.create({
|
||||||
icon_path: iconPath,
|
icon_path: iconPath,
|
||||||
brand: vectorConfig.brand || 'Riot',
|
brand: vectorConfig.brand || 'Riot',
|
||||||
});
|
});
|
||||||
|
@ -215,7 +215,7 @@ electron.app.on('ready', () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
mainWindow.on('closed', () => {
|
mainWindow.on('closed', () => {
|
||||||
mainWindow = null;
|
mainWindow = global.mainWindow = null;
|
||||||
});
|
});
|
||||||
mainWindow.on('close', (e) => {
|
mainWindow.on('close', (e) => {
|
||||||
if (!global.appQuitting && (tray.hasTray() || process.platform === 'darwin')) {
|
if (!global.appQuitting && (tray.hasTray() || process.platform === 'darwin')) {
|
||||||
|
|
|
@ -26,17 +26,17 @@ exports.hasTray = function hasTray() {
|
||||||
return (trayIcon !== null);
|
return (trayIcon !== null);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.create = function(win, config) {
|
exports.create = function(config) {
|
||||||
// no trays on darwin
|
// no trays on darwin
|
||||||
if (process.platform === 'darwin' || trayIcon) return;
|
if (process.platform === 'darwin' || trayIcon) return;
|
||||||
|
|
||||||
const toggleWin = function() {
|
const toggleWin = function() {
|
||||||
if (win.isVisible() && !win.isMinimized()) {
|
if (global.mainWindow.isVisible() && !global.mainWindow.isMinimized()) {
|
||||||
win.hide();
|
global.mainWindow.hide();
|
||||||
} else {
|
} else {
|
||||||
if (win.isMinimized()) win.restore();
|
if (global.mainWindow.isMinimized()) global.mainWindow.restore();
|
||||||
if (!win.isVisible()) win.show();
|
if (!global.mainWindow.isVisible()) global.mainWindow.show();
|
||||||
win.focus();
|
global.mainWindow.focus();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ exports.create = function(win, config) {
|
||||||
trayIcon.on('click', toggleWin);
|
trayIcon.on('click', toggleWin);
|
||||||
|
|
||||||
let lastFavicon = null;
|
let lastFavicon = null;
|
||||||
win.webContents.on('page-favicon-updated', async function(ev, favicons) {
|
global.mainWindow.webContents.on('page-favicon-updated', async function(ev, favicons) {
|
||||||
let newFavicon = config.icon_path;
|
let newFavicon = config.icon_path;
|
||||||
if (favicons && favicons.length > 0 && favicons[0].startsWith('data:')) {
|
if (favicons && favicons.length > 0 && favicons[0].startsWith('data:')) {
|
||||||
newFavicon = favicons[0];
|
newFavicon = favicons[0];
|
||||||
|
@ -85,10 +85,10 @@ exports.create = function(win, config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
trayIcon.setImage(newFavicon);
|
trayIcon.setImage(newFavicon);
|
||||||
win.setIcon(newFavicon);
|
global.mainWindow.setIcon(newFavicon);
|
||||||
});
|
});
|
||||||
|
|
||||||
win.webContents.on('page-title-updated', function(ev, title) {
|
global.mainWindow.webContents.on('page-title-updated', function(ev, title) {
|
||||||
trayIcon.setToolTip(title);
|
trayIcon.setToolTip(title);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -67,17 +67,11 @@ module.exports.start = function startAutoUpdate(updateBaseUrl) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ipcMain.on('install_update', installUpdate);
|
ipcMain.on('install_update', installUpdate);
|
||||||
|
ipcMain.on('check_updates', pollForUpdates);
|
||||||
let ipcChannel;
|
|
||||||
ipcMain.on('check_updates', function(event) {
|
|
||||||
ipcChannel = event.sender;
|
|
||||||
pollForUpdates();
|
|
||||||
// event.sender.send('check_updates') // true/false/error = available(downloading)/notAvailable/error
|
|
||||||
});
|
|
||||||
|
|
||||||
function ipcChannelSendUpdateStatus(status) {
|
function ipcChannelSendUpdateStatus(status) {
|
||||||
if (ipcChannel) {
|
if (global.mainWindow) {
|
||||||
ipcChannel.send('check_updates', status);
|
global.mainWindow.webContents.send('check_updates', status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue