Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit cd8b5f8

Browse files
committed
use --disable-http-cache to avoid exporting an old resource.
close dev tools by default to avoid console errors related to it starting up too soon.
1 parent 65fdb8a commit cd8b5f8

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

app/main.dev.js

+20-8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ export default class AppUpdater {
3131

3232
let mainWindow = null;
3333

34+
// Disable caching resources to avoid unexpected behavior when exporting metadata.xml and resources
35+
// see https://github.com/electron/electron/issues/1720
36+
// and https://github.com/scramjs/scram-engine/issues/5#issuecomment-222323820
37+
app.commandLine.appendSwitch('--disable-http-cache');
38+
3439
logHelpers.setupLogFile(__dirname, 'debug', 'error');
3540
log.info('Main App starting...');
3641

@@ -68,13 +73,6 @@ app.on('window-all-closed', () => {
6873
});
6974

7075
app.on('ready', async () => {
71-
if (
72-
process.env.NODE_ENV === 'development' ||
73-
process.env.DEBUG_PROD === 'true'
74-
) {
75-
await installExtensions();
76-
}
77-
7876
mainWindow = new BrowserWindow({
7977
show: false,
8078
width: 1024,
@@ -88,6 +86,20 @@ app.on('ready', async () => {
8886
`file://${__dirname}/app.html#${navigationConstants.NAVIGATION_WORKSPACES}`
8987
);
9088

89+
/*
90+
waiting until 'dom-ready' avoids startup errors related to devtools server extension
91+
https://github.com/LN-Zap/zap-desktop/pull/500
92+
*/
93+
mainWindow.webContents.on('dom-ready', async () => {
94+
mainWindow.webContents.closeDevTools();
95+
if (
96+
process.env.NODE_ENV === 'development' ||
97+
process.env.DEBUG_PROD === 'true'
98+
) {
99+
await installExtensions();
100+
}
101+
});
102+
91103
// @TODO: Use 'ready-to-show' event
92104
// https://github.com/electron/electron/blob/master/docs/api/browser-window.md#using-ready-to-show-event
93105
mainWindow.webContents.on('did-finish-load', () => {
@@ -133,6 +145,7 @@ app.on('ready', async () => {
133145
mainWindow = null;
134146
});
135147

148+
/*
136149
mainWindow.onerror = err => {
137150
// log.error(JSON.stringify(err));
138151
};
@@ -141,7 +154,6 @@ app.on('ready', async () => {
141154
// log.error(JSON.stringify(err));
142155
});
143156
144-
/*
145157
session.defaultSession.webRequest.onErrorOccurred((details) => {
146158
log.error(JSON.stringify(details));
147159
});

app/services/browserWindow.service.js

+11
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,17 @@ function openFileInChromeBrowser(
191191
show: false,
192192
...options
193193
});
194+
browserWin.webContents.on('dom-ready', () => {
195+
/*
196+
Don't automatically bring up devTools & Reduce spam from a bug:
197+
https://github.com/electron/electron/issues/12438#issuecomment-390211011
198+
https://github.com/electron/electron/issues/13008
199+
[23580:0926/110237.459:ERROR:CONSOLE(24)] "Empty response arrived for script 'chrome-devtools://devtools/remote/serve_file/@67b778eb4e0214a7dd0d01c286f15c0fcb6b3a90/product_registry_impl/product_registry_impl_module.js'",
200+
source: chrome-devtools://devtools/bundled/shell.js (24)
201+
[23580:0926/110237.471:ERROR:CONSOLE(108)] "Uncaught (in promise) Error: Could not instantiate: ProductRegistryImpl.Registry", source: chrome-devtools://devtools/bundled/shell.js (108)
202+
*/
203+
browserWin.webContents.closeDevTools();
204+
});
194205
browserWin.loadURL(url);
195206
browserWin.on('focus', () => {
196207
buildBrowserMenu(browserWin);

app/services/bundle.service.js

+4-9
Original file line numberDiff line numberDiff line change
@@ -453,15 +453,10 @@ function requestSaveResourceTo(
453453
relativeDestinationPath,
454454
progressCallback = () => {}
455455
) {
456-
// NOTE: for some reason getting metadata.xml via /resource-stream/ api leads to `Review metadata.xml`
457-
// getting the earlier version of the document. So use `/resource/` api instead.
458-
// Might be a Chrome feature for responses with attachments
459-
// see --disable-http-cache and https://github.com/electron/electron/issues/1720
460-
const resourceApi =
461-
uriRelativePath === 'metadata.xml'
462-
? RESOURCE_API
463-
: `${RESOURCE_API}-stream`;
464-
const url = `${dblDotLocalConfigConstants.getHttpDblDotLocalBaseUrl()}/${BUNDLE_API}/${bundleId}/${resourceApi}/${uriRelativePath}`;
456+
// NOTE: getting resources via /resource-stream/ api can result in
457+
// getting the earlier version of the cached resource.
458+
// To avoid this use --disable-http-cache (see https://github.com/electron/electron/issues/1720)
459+
const url = `${dblDotLocalConfigConstants.getHttpDblDotLocalBaseUrl()}/${BUNDLE_API}/${bundleId}/${RESOURCE_API}-stream/${uriRelativePath}`;
465460
const targetPath = path.join(selectedFolder, relativeDestinationPath);
466461
return download(url, targetPath, progressCallback, authHeader());
467462
}

0 commit comments

Comments
 (0)