Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MM-37379] Add "Clear Data" options in the menu to allow users to force Electron to blow away session data. #3185

Merged
merged 3 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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",
Expand Down
51 changes: 51 additions & 0 deletions src/main/app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
1 change: 1 addition & 0 deletions src/main/menus/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
13 changes: 13 additions & 0 deletions src/main/menus/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down
Loading