[MM-22229] migrate some operations to promises (#1223)
* [MM-22229] convert download dialog into promises * use callback * [MM-22231] switch clearcache to promises * [MM-22232] migrate flush cookies to promises
This commit is contained in:
parent
9b5f53a294
commit
f1baa03a8f
|
@ -227,9 +227,7 @@ export default class MattermostView extends React.Component {
|
||||||
errorInfo: null,
|
errorInfo: null,
|
||||||
});
|
});
|
||||||
const webContents = this.webviewRef.current.getWebContents();
|
const webContents = this.webviewRef.current.getWebContents();
|
||||||
webContents.session.clearCache(() => {
|
webContents.session.clearCache().then(webContents.reload);
|
||||||
webContents.reload();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
focusOnWebView = () => {
|
focusOnWebView = () => {
|
||||||
|
|
|
@ -1123,10 +1123,7 @@ function wasUpdated(lastAppVersion) {
|
||||||
function clearAppCache() {
|
function clearAppCache() {
|
||||||
if (mainWindow) {
|
if (mainWindow) {
|
||||||
console.log('Clear cache after update');
|
console.log('Clear cache after update');
|
||||||
mainWindow.webContents.session.clearCache(() => {
|
mainWindow.webContents.session.clearCache().then(mainWindow.reload);
|
||||||
//Restart after cache clear
|
|
||||||
mainWindow.reload();
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
//Wait for mainWindow
|
//Wait for mainWindow
|
||||||
setTimeout(clearAppCache, 100);
|
setTimeout(clearAppCache, 100);
|
||||||
|
|
|
@ -4,10 +4,8 @@
|
||||||
import {app} from 'electron';
|
import {app} from 'electron';
|
||||||
|
|
||||||
function flushCookiesStore(session) {
|
function flushCookiesStore(session) {
|
||||||
session.cookies.flushStore((err) => {
|
session.cookies.flushStore().catch((err) => {
|
||||||
if (err) {
|
console.log(`There was a problem flushing cookies:\n${err}`);
|
||||||
console.log(err);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,10 +17,17 @@ export default function downloadURL(browserWindow, URL, callback) {
|
||||||
const dialogOptions = {
|
const dialogOptions = {
|
||||||
defaultPath: path.join(app.getPath('downloads'), file),
|
defaultPath: path.join(app.getPath('downloads'), file),
|
||||||
};
|
};
|
||||||
dialog.showSaveDialog(browserWindow, dialogOptions, (filename) => {
|
dialog.showSaveDialog(
|
||||||
if (filename) {
|
browserWindow,
|
||||||
saveResponseBody(response, filename, callback);
|
dialogOptions
|
||||||
|
).then(
|
||||||
|
(filename) => {
|
||||||
|
if (filename) {
|
||||||
|
saveResponseBody(response, filename, callback);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
).catch((err) => {
|
||||||
|
callback(err);
|
||||||
});
|
});
|
||||||
}).on('error', callback);
|
}).on('error', callback);
|
||||||
request.end();
|
request.end();
|
||||||
|
|
|
@ -144,9 +144,7 @@ function createTemplate(mainWindow, config, isDev) {
|
||||||
if (focusedWindow === mainWindow) {
|
if (focusedWindow === mainWindow) {
|
||||||
mainWindow.webContents.send('clear-cache-and-reload-tab');
|
mainWindow.webContents.send('clear-cache-and-reload-tab');
|
||||||
} else {
|
} else {
|
||||||
focusedWindow.webContents.session.clearCache(() => {
|
focusedWindow.webContents.session.clearCache().then(focusedWindow.reload);
|
||||||
focusedWindow.reload();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue