fix: ELECTRON-1488 (Update i18n resources when page fail to load) (#773)

* ELECTRON-1491 - Update i18n when page failed to load

* ELECTRON-1491 - Preload i18n resources & remove unwanted code
This commit is contained in:
Kiran Niranjan 2019-08-28 19:12:13 +05:30 committed by Vishwas Shashidhar
parent 4a5f7ff77d
commit b7067fca9a
4 changed files with 12 additions and 7 deletions

View File

@ -200,6 +200,10 @@ export class WindowHandler {
this.mainWindow.webContents.on('did-stop-loading', async () => {
if (this.mainWindow && windowExists(this.mainWindow)) {
this.mainWindow.webContents.send('page-load-failed', {
locale: i18n.getLocale(),
resources: i18n.loadedResources,
});
const href = await this.mainWindow.webContents.executeJavaScript('document.location.href');
try {
if (href === 'data:text/html,chromewebdata' || href === 'chrome-error://chromewebdata/') {

View File

@ -35,6 +35,9 @@ class Translation {
}
this.locale = locale;
if (!this.loadedResources[this.locale]) {
this.loadResource(this.locale);
}
}
/**

View File

@ -54,13 +54,6 @@ export default class WindowsTitleBar extends React.Component<{}, IState> {
}
}
public componentWillMount() {
this.window.removeListener('maximize', this.updateState);
this.window.removeListener('unmaximize', this.updateState);
this.window.removeListener('enter-full-screen', this.updateState);
this.window.removeListener('leave-full-screen', this.updateState);
}
public componentWillUnmount(): void {
if (this.observer) {
this.observer.disconnect();

View File

@ -86,6 +86,11 @@ ipcRenderer.on('page-load', (_event, { locale, resources, enableCustomTitleBar,
}
});
// When the window fails to load
ipcRenderer.on('page-load-failed', (_event, { locale, resources }) => {
i18n.setResource(locale, resources);
});
// Injects network error content into the DOM
ipcRenderer.on('network-error', (_event, { error }) => {
const networkErrorContainer = document.createElement( 'div' );