[MM-37379] Add "Clear Data" options in the menu to allow users to force Electron to blow away session data. (#3185)
* [MM-37379] Add "Clear Data" options in the menu to allow users to force Electron to blow away session data. * Fix i18n --------- Co-authored-by: Mattermost Build <build@mattermost.com>
This commit is contained in:
@@ -258,3 +258,54 @@ export async function updateServerInfos(servers: MattermostServer[]) {
|
||||
}));
|
||||
ServerManager.updateRemoteInfos(map);
|
||||
}
|
||||
|
||||
export async function clearDataForServer(server: MattermostServer) {
|
||||
const mainWindow = MainWindow.get();
|
||||
if (!mainWindow) {
|
||||
return;
|
||||
}
|
||||
|
||||
const response = await dialog.showMessageBox(mainWindow, {
|
||||
type: 'warning',
|
||||
buttons: [
|
||||
localizeMessage('main.app.utils.clearDataForServer.confirm', 'Clear Data'),
|
||||
localizeMessage('main.app.utils.clearDataForServer.cancel', 'Cancel'),
|
||||
],
|
||||
defaultId: 1,
|
||||
message: localizeMessage('main.app.utils.clearDataForServer.message', 'This action will erase all session, cache, cookie and storage data for the server "{serverName}". Are you sure you want to clear data for this server?', {serverName: server.name}),
|
||||
});
|
||||
|
||||
if (response.response === 0) {
|
||||
await session.defaultSession.clearData({
|
||||
origins: [server.url.origin],
|
||||
});
|
||||
ViewManager.reload();
|
||||
}
|
||||
}
|
||||
|
||||
export async function clearAllData() {
|
||||
const mainWindow = MainWindow.get();
|
||||
if (!mainWindow) {
|
||||
return;
|
||||
}
|
||||
|
||||
const response = await dialog.showMessageBox(mainWindow, {
|
||||
title: app.name,
|
||||
type: 'warning',
|
||||
buttons: [
|
||||
localizeMessage('main.app.utils.clearAllData.confirm', 'Clear All Data'),
|
||||
localizeMessage('main.app.utils.clearAllData.cancel', 'Cancel'),
|
||||
],
|
||||
defaultId: 1,
|
||||
message: localizeMessage('main.app.utils.clearAllData.message', 'This action will erase all session, cache, cookie and storage data for all server. Performing this action will restart the application. Are you sure you want to clear all data?'),
|
||||
});
|
||||
|
||||
if (response.response === 0) {
|
||||
await session.defaultSession.clearAuthCache();
|
||||
await session.defaultSession.clearCodeCaches({});
|
||||
await session.defaultSession.clearHostResolverCache();
|
||||
await session.defaultSession.clearData();
|
||||
app.relaunch();
|
||||
app.exit();
|
||||
}
|
||||
}
|
||||
|
@@ -74,6 +74,7 @@ jest.mock('app/serverViewState', () => ({
|
||||
switchServer: jest.fn(),
|
||||
getCurrentServer: jest.fn(),
|
||||
}));
|
||||
jest.mock('main/app/utils', () => ({}));
|
||||
jest.mock('main/diagnostics', () => ({}));
|
||||
jest.mock('main/downloadsManager', () => ({
|
||||
hasDownloads: jest.fn(),
|
||||
|
@@ -15,6 +15,7 @@ import ServerManager from 'common/servers/serverManager';
|
||||
import {t} from 'common/utils/util';
|
||||
import {getViewDisplayName} from 'common/views/View';
|
||||
import type {ViewType} from 'common/views/View';
|
||||
import {clearAllData, clearDataForServer} from 'main/app/utils';
|
||||
import type {UpdateManager} from 'main/autoUpdater';
|
||||
import DeveloperMode from 'main/developerMode';
|
||||
import Diagnostics from 'main/diagnostics';
|
||||
@@ -274,6 +275,18 @@ export function createTemplate(config: Config, updateManager: UpdateManager) {
|
||||
click() {
|
||||
return downloadsManager.openDownloadsDropdown();
|
||||
},
|
||||
}, separatorItem, {
|
||||
id: 'clear-data-for-server',
|
||||
label: localizeMessage('main.menus.app.view.clearDataForServer', 'Clear Data for Current Server'),
|
||||
async click() {
|
||||
return clearDataForServer(ServerViewState.getCurrentServer());
|
||||
},
|
||||
}, {
|
||||
id: 'clear-data',
|
||||
label: localizeMessage('main.menus.app.view.clearAllData', 'Clear All Data'),
|
||||
async click() {
|
||||
return clearAllData();
|
||||
},
|
||||
}, separatorItem, {
|
||||
label: localizeMessage('main.menus.app.view.devToolsSubMenu', 'Developer Tools'),
|
||||
submenu: devToolsSubMenu,
|
||||
|
Reference in New Issue
Block a user