mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-21 15:56:10 +08:00
Reset the local cache for an account when removing it #724
This commit is contained in:
parent
46cbc15833
commit
efb3a04bb4
|
@ -200,7 +200,7 @@ export default class MailsyncBridge {
|
|||
this._clients[accountId].sendMessage(json);
|
||||
}
|
||||
|
||||
async resetCacheForAccount(account) {
|
||||
async resetCacheForAccount(account, { silent } = {}) {
|
||||
// grab the existing client, if there is one
|
||||
const syncingClient = this._clients[account.id];
|
||||
|
||||
|
@ -208,6 +208,11 @@ export default class MailsyncBridge {
|
|||
const resetClient = new MailsyncProcess(this._getClientConfiguration());
|
||||
resetClient.account = (await KeyManager.insertAccountSecrets(account)).toJSON();
|
||||
resetClient.identity = IdentityStore.identity();
|
||||
|
||||
// no-op - do not allow us to kill this client - we may be reseting the cache of an
|
||||
// account which does not exist anymore, but we don't want to interrupt this process
|
||||
resetClient.kill = () => {};
|
||||
|
||||
this._clients[account.id] = resetClient;
|
||||
|
||||
// kill the old client, ensureClients will be a no-op because the
|
||||
|
@ -216,24 +221,28 @@ export default class MailsyncBridge {
|
|||
syncingClient.kill();
|
||||
}
|
||||
|
||||
AppEnv.showErrorDialog({
|
||||
title: `Cleanup Started`,
|
||||
message: `Mailspring is clearing it's cache for ${
|
||||
account.emailAddress
|
||||
}. Depending on the size of the mailbox, this may take a few seconds or a few minutes. An alert will appear when cleanup is complete.`,
|
||||
});
|
||||
if (!silent) {
|
||||
AppEnv.showErrorDialog({
|
||||
title: `Cleanup Started`,
|
||||
message: `Mailspring is clearing it's cache for ${
|
||||
account.emailAddress
|
||||
}. Depending on the size of the mailbox, this may take a few seconds or a few minutes. An alert will appear when cleanup is complete.`,
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
const start = Date.now();
|
||||
|
||||
await resetClient.resetCache();
|
||||
|
||||
AppEnv.showErrorDialog({
|
||||
title: `Cleanup Complete`,
|
||||
message: `Mailspring reset the local cache for ${account.emailAddress} in ${Math.ceil(
|
||||
(Date.now() - start) / 1000
|
||||
)} seconds. Your mailbox will now begin to sync again.`,
|
||||
});
|
||||
if (!silent) {
|
||||
AppEnv.showErrorDialog({
|
||||
title: `Cleanup Complete`,
|
||||
message: `Mailspring reset the local cache for ${account.emailAddress} in ${Math.ceil(
|
||||
(Date.now() - start) / 1000
|
||||
)} seconds. Your mailbox will now begin to sync again.`,
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
AppEnv.showErrorDialog({
|
||||
title: `Cleanup Error`,
|
||||
|
|
|
@ -174,7 +174,6 @@ class AccountStore extends MailspringStore {
|
|||
_onRemoveAccount = id => {
|
||||
const account = this._accounts.find(a => a.id === id);
|
||||
if (!account) return;
|
||||
KeyManager.deleteAccountSecrets(account);
|
||||
|
||||
this._caches = {};
|
||||
|
||||
|
@ -193,10 +192,17 @@ class AccountStore extends MailspringStore {
|
|||
this._save();
|
||||
|
||||
if (remainingAccounts.length === 0) {
|
||||
// Clear everything and logout
|
||||
const ipc = require('electron').ipcRenderer;
|
||||
ipc.send('command', 'application:relaunch-to-initial-windows', {
|
||||
resetDatabase: true,
|
||||
});
|
||||
} else {
|
||||
// Clear the cached data for the account and reset secrets once that has completed
|
||||
AppEnv.mailsyncBridge.resetCacheForAccount(account, { silent: true }).then(() => {
|
||||
console.log('Account removal complete.');
|
||||
KeyManager.deleteAccountSecrets(account);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue