mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2024-09-28 12:29:00 +00:00
``` Uncaught Exception: TypeError: Cannot read property 'show' of undefined at App.<anonymous> (/src/main.ts:177:18) ``` Seems like an oversight of the recent refactor. * macOS: fix crash on activating main window (fix #1210) * Eliminate need for global mainWindow, refactor widevine / non-widevine events (#1218) Co-authored-by: Adam Weeden <adamweeden@gmail.com>
This commit is contained in:
parent
cdc6fa79c2
commit
709557c7ab
151
app/src/main.ts
151
app/src/main.ts
@ -98,8 +98,6 @@ if (appArgs.processEnvs) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mainWindow: BrowserWindow;
|
|
||||||
|
|
||||||
if (typeof appArgs.flashPluginDir === 'string') {
|
if (typeof appArgs.flashPluginDir === 'string') {
|
||||||
app.commandLine.appendSwitch('ppapi-flash-path', appArgs.flashPluginDir);
|
app.commandLine.appendSwitch('ppapi-flash-path', appArgs.flashPluginDir);
|
||||||
} else if (appArgs.flashPluginDir) {
|
} else if (appArgs.flashPluginDir) {
|
||||||
@ -169,16 +167,6 @@ app.on('window-all-closed', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.on('activate', (event, hasVisibleWindows) => {
|
|
||||||
log.debug('app.activate', { event, hasVisibleWindows });
|
|
||||||
if (isOSX()) {
|
|
||||||
// this is called when the dock is clicked
|
|
||||||
if (!hasVisibleWindows) {
|
|
||||||
mainWindow.show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
app.on('before-quit', () => {
|
app.on('before-quit', () => {
|
||||||
log.debug('app.before-quit');
|
log.debug('app.before-quit');
|
||||||
// not fired when the close button on the window is clicked
|
// not fired when the close button on the window is clicked
|
||||||
@ -212,59 +200,97 @@ if (appArgs.crashReporter) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// quit if singleInstance mode and there's already another instance running
|
if (appArgs.widevine) {
|
||||||
const shouldQuit = appArgs.singleInstance && !app.requestSingleInstanceLock();
|
// @ts-ignore This event only appears on the widevine version of electron, which we'd see at runtime
|
||||||
if (shouldQuit) {
|
app.on('widevine-ready', (version: string, lastVersion: string) => {
|
||||||
app.quit();
|
log.debug('app.widevine-ready', { version, lastVersion });
|
||||||
|
onReady().catch((err) => log.error('onReady ERROR', err));
|
||||||
|
});
|
||||||
|
|
||||||
|
app.on(
|
||||||
|
// @ts-ignore This event only appears on the widevine version of electron, which we'd see at runtime
|
||||||
|
'widevine-update-pending',
|
||||||
|
(currentVersion: string, pendingVersion: string) => {
|
||||||
|
log.debug('app.widevine-update-pending', {
|
||||||
|
currentVersion,
|
||||||
|
pendingVersion,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// @ts-ignore This event only appears on the widevine version of electron, which we'd see at runtime
|
||||||
|
app.on('widevine-error', (error: any) => {
|
||||||
|
log.error('app.widevine-error', error);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
app.on('second-instance', () => {
|
app.on('ready', () => {
|
||||||
log.debug('app.second-instance');
|
log.debug('ready');
|
||||||
if (mainWindow) {
|
onReady().catch((err) => log.error('onReady ERROR', err));
|
||||||
if (!mainWindow.isVisible()) {
|
});
|
||||||
// try
|
}
|
||||||
|
|
||||||
|
function initAppWindowEvents(mainWindow: BrowserWindow) {
|
||||||
|
app.on('activate', (event, hasVisibleWindows) => {
|
||||||
|
log.debug('app.activate', { event, hasVisibleWindows });
|
||||||
|
if (isOSX()) {
|
||||||
|
// this is called when the dock is clicked
|
||||||
|
if (!hasVisibleWindows) {
|
||||||
mainWindow.show();
|
mainWindow.show();
|
||||||
}
|
}
|
||||||
if (mainWindow.isMinimized()) {
|
|
||||||
// minimized
|
|
||||||
mainWindow.restore();
|
|
||||||
}
|
|
||||||
mainWindow.focus();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (appArgs.widevine) {
|
// quit if singleInstance mode and there's already another instance running
|
||||||
// @ts-ignore This event only appears on the widevine version of electron, which we'd see at runtime
|
const shouldQuit = appArgs.singleInstance && !app.requestSingleInstanceLock();
|
||||||
app.on('widevine-ready', (version: string, lastVersion: string) => {
|
if (shouldQuit) {
|
||||||
log.debug('app.widevine-ready', { version, lastVersion });
|
app.quit();
|
||||||
onReady().catch((err) => log.error('onReady ERROR', err));
|
|
||||||
});
|
|
||||||
|
|
||||||
app.on(
|
|
||||||
// @ts-ignore This event only appears on the widevine version of electron, which we'd see at runtime
|
|
||||||
'widevine-update-pending',
|
|
||||||
(currentVersion: string, pendingVersion: string) => {
|
|
||||||
log.debug('app.widevine-update-pending', {
|
|
||||||
currentVersion,
|
|
||||||
pendingVersion,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
// @ts-ignore This event only appears on the widevine version of electron, which we'd see at runtime
|
|
||||||
app.on('widevine-error', (error: any) => {
|
|
||||||
log.error('app.widevine-error', error);
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
app.on('ready', () => {
|
app.on('second-instance', () => {
|
||||||
log.debug('ready');
|
log.debug('app.second-instance');
|
||||||
onReady().catch((err) => log.error('onReady ERROR', err));
|
if (mainWindow) {
|
||||||
|
if (!mainWindow.isVisible()) {
|
||||||
|
// try
|
||||||
|
mainWindow.show();
|
||||||
|
}
|
||||||
|
if (mainWindow.isMinimized()) {
|
||||||
|
// minimized
|
||||||
|
mainWindow.restore();
|
||||||
|
}
|
||||||
|
mainWindow.focus();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.on('new-window-for-tab', () => {
|
||||||
|
log.debug('app.new-window-for-tab');
|
||||||
|
if (mainWindow) {
|
||||||
|
mainWindow.emit('new-tab');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.on('login', (event, webContents, request, authInfo, callback) => {
|
||||||
|
log.debug('app.login', { event, request });
|
||||||
|
// for http authentication
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
if (
|
||||||
|
appArgs.basicAuthUsername !== null &&
|
||||||
|
appArgs.basicAuthPassword !== null
|
||||||
|
) {
|
||||||
|
callback(appArgs.basicAuthUsername, appArgs.basicAuthPassword);
|
||||||
|
} else {
|
||||||
|
createLoginWindow(callback, mainWindow).catch((err) =>
|
||||||
|
log.error('createLoginWindow ERROR', err),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onReady(): Promise<void> {
|
async function onReady(): Promise<void> {
|
||||||
const mainWindow = await createMainWindow(appArgs, setDockBadge);
|
const mainWindow = await createMainWindow(appArgs, setDockBadge);
|
||||||
|
|
||||||
|
initAppWindowEvents(mainWindow);
|
||||||
|
|
||||||
createTrayIcon(appArgs, mainWindow);
|
createTrayIcon(appArgs, mainWindow);
|
||||||
|
|
||||||
// Register global shortcuts
|
// Register global shortcuts
|
||||||
@ -339,29 +365,6 @@ async function onReady(): Promise<void> {
|
|||||||
.catch((err) => log.error('dialog.showMessageBox ERROR', err));
|
.catch((err) => log.error('dialog.showMessageBox ERROR', err));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
app.on('new-window-for-tab', () => {
|
|
||||||
log.debug('app.new-window-for-tab');
|
|
||||||
if (mainWindow) {
|
|
||||||
mainWindow.emit('new-tab');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
app.on('login', (event, webContents, request, authInfo, callback) => {
|
|
||||||
log.debug('app.login', { event, request });
|
|
||||||
// for http authentication
|
|
||||||
event.preventDefault();
|
|
||||||
|
|
||||||
if (
|
|
||||||
appArgs.basicAuthUsername !== null &&
|
|
||||||
appArgs.basicAuthPassword !== null
|
|
||||||
) {
|
|
||||||
callback(appArgs.basicAuthUsername, appArgs.basicAuthPassword);
|
|
||||||
} else {
|
|
||||||
createLoginWindow(callback, mainWindow).catch((err) =>
|
|
||||||
log.error('createLoginWindow ERROR', err),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
app.on(
|
app.on(
|
||||||
'accessibility-support-changed',
|
'accessibility-support-changed',
|
||||||
|
Loading…
Reference in New Issue
Block a user