[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:
Guillermo Vayá 2020-04-08 14:56:25 +02:00 committed by GitHub
parent 9b5f53a294
commit f1baa03a8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 17 deletions

View file

@ -227,9 +227,7 @@ export default class MattermostView extends React.Component {
errorInfo: null,
});
const webContents = this.webviewRef.current.getWebContents();
webContents.session.clearCache(() => {
webContents.reload();
});
webContents.session.clearCache().then(webContents.reload);
}
focusOnWebView = () => {

View file

@ -1123,10 +1123,7 @@ function wasUpdated(lastAppVersion) {
function clearAppCache() {
if (mainWindow) {
console.log('Clear cache after update');
mainWindow.webContents.session.clearCache(() => {
//Restart after cache clear
mainWindow.reload();
});
mainWindow.webContents.session.clearCache().then(mainWindow.reload);
} else {
//Wait for mainWindow
setTimeout(clearAppCache, 100);

View file

@ -4,10 +4,8 @@
import {app} from 'electron';
function flushCookiesStore(session) {
session.cookies.flushStore((err) => {
if (err) {
console.log(err);
}
session.cookies.flushStore().catch((err) => {
console.log(`There was a problem flushing cookies:\n${err}`);
});
}

View file

@ -17,10 +17,17 @@ export default function downloadURL(browserWindow, URL, callback) {
const dialogOptions = {
defaultPath: path.join(app.getPath('downloads'), file),
};
dialog.showSaveDialog(browserWindow, dialogOptions, (filename) => {
if (filename) {
saveResponseBody(response, filename, callback);
dialog.showSaveDialog(
browserWindow,
dialogOptions
).then(
(filename) => {
if (filename) {
saveResponseBody(response, filename, callback);
}
}
).catch((err) => {
callback(err);
});
}).on('error', callback);
request.end();

View file

@ -144,9 +144,7 @@ function createTemplate(mainWindow, config, isDev) {
if (focusedWindow === mainWindow) {
mainWindow.webContents.send('clear-cache-and-reload-tab');
} else {
focusedWindow.webContents.session.clearCache(() => {
focusedWindow.reload();
});
focusedWindow.webContents.session.clearCache().then(focusedWindow.reload);
}
}
},