[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:
@@ -32,6 +32,12 @@
|
||||
"main.app.app.handleAppCertificateError.certNotTrusted.dialog.title": "Certificate Not Trusted",
|
||||
"main.app.app.handleAppCertificateError.dialog.extraDetail": "Certificate is different from previous one.\n\n",
|
||||
"main.app.initialize.downloadBox.allFiles": "All files",
|
||||
"main.app.utils.clearAllData.cancel": "Cancel",
|
||||
"main.app.utils.clearAllData.confirm": "Clear All Data",
|
||||
"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?",
|
||||
"main.app.utils.clearDataForServer.cancel": "Cancel",
|
||||
"main.app.utils.clearDataForServer.confirm": "Clear Data",
|
||||
"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?",
|
||||
"main.app.utils.migrateMacAppStore.button.dontImport": "Don't Import",
|
||||
"main.app.utils.migrateMacAppStore.button.selectAndImport": "Select Directory and Import",
|
||||
"main.app.utils.migrateMacAppStore.dialog.detail": "It appears that an existing {appName} configuration exists, would you like to import it? You will be asked to pick the correct configuration directory.",
|
||||
@@ -82,7 +88,9 @@
|
||||
"main.menus.app.history.forward": "Forward",
|
||||
"main.menus.app.view": "&View",
|
||||
"main.menus.app.view.actualSize": "Actual Size",
|
||||
"main.menus.app.view.clearAllData": "Clear All Data",
|
||||
"main.menus.app.view.clearCacheAndReload": "Clear Cache and Reload",
|
||||
"main.menus.app.view.clearDataForServer": "Clear Data for Current Server",
|
||||
"main.menus.app.view.developerModeBrowserOnly": "Browser Only Mode",
|
||||
"main.menus.app.view.developerModeDisableContextMenu": "Disable Context Menu",
|
||||
"main.menus.app.view.developerModeDisableNotificationStorage": "Disable Notification Storage",
|
||||
|
@@ -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