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

feat(developer): reset application #1405

Merged
merged 1 commit into from
Jul 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
22 changes: 0 additions & 22 deletions src/context/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -304,28 +304,6 @@ describe('context/App.tsx', () => {
});
});

it('should call logout', async () => {
const clearStateMock = jest.spyOn(storage, 'clearState');

const TestComponent = () => {
const { logout } = useContext(AppContext);

return (
<button type="button" onClick={logout}>
Test Case
</button>
);
};

const { getByText } = customRender(<TestComponent />);

act(() => {
fireEvent.click(getByText('Test Case'));
});

expect(clearStateMock).toHaveBeenCalledTimes(1);
});

describe('settings methods', () => {
const fetchNotificationsMock = jest.fn();

Expand Down
16 changes: 8 additions & 8 deletions src/context/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { webFrame } from 'electron';
import { ipcRenderer, webFrame } from 'electron';
import {
type ReactNode,
createContext,
Expand Down Expand Up @@ -97,7 +97,6 @@ interface AppContextState {
loginWithOAuthApp: (data: LoginOAuthAppOptions) => void;
loginWithPersonalAccessToken: (data: LoginPersonalAccessTokenOptions) => void;
logoutFromAccount: (account: Account) => void;
logout: () => void;

notifications: AccountNotifications[];
status: Status;
Expand Down Expand Up @@ -163,6 +162,13 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
setKeyboardShortcut(settings.keyboardShortcut);
}, [settings.keyboardShortcut]);

useEffect(() => {
ipcRenderer.on('gitify:reset-app', () => {
setAuth(defaultAuth);
clearState();
});
}, []);

const clearFilters = useCallback(() => {
const newSettings = { ...settings, ...defaultFilters };
setSettings(newSettings);
Expand Down Expand Up @@ -239,11 +245,6 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
[auth, settings],
);

const logout = useCallback(() => {
setAuth(defaultAuth);
clearState();
}, []);

const restoreSettings = useCallback(async () => {
await migrateAuthenticatedAccounts();

Expand Down Expand Up @@ -307,7 +308,6 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
loginWithOAuthApp,
loginWithPersonalAccessToken,
logoutFromAccount,
logout,

notifications,
status,
Expand Down
44 changes: 36 additions & 8 deletions src/electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const {
nativeTheme,
globalShortcut,
Menu,
dialog,
} = require('electron/main');
const { menubar } = require('menubar');
const { autoUpdater } = require('electron-updater');
Expand Down Expand Up @@ -50,6 +51,12 @@ const contextMenu = Menu.buildFromTemplate([
accelerator:
process.platform === 'darwin' ? 'Alt+Cmd+I' : 'Ctrl+Shift+I',
},
{
label: 'Reset App',
click: () => {
resetApp();
},
},
],
},
{ type: 'separator' },
Expand All @@ -62,17 +69,17 @@ const contextMenu = Menu.buildFromTemplate([
},
]);

const mb = menubar({
icon: idleIcon,
index: `file://${__dirname}/index.html`,
browserWindow: browserWindowOpts,
preloadWindow: true,
showDockIcon: false,
});

app.whenReady().then(async () => {
await onFirstRunMaybe();

const mb = menubar({
icon: idleIcon,
index: `file://${__dirname}/index.html`,
browserWindow: browserWindowOpts,
preloadWindow: true,
showDockIcon: false,
});

mb.on('ready', () => {
autoUpdater.checkForUpdatesAndNotify();

Expand Down Expand Up @@ -168,3 +175,24 @@ app.whenReady().then(async () => {
app.setLoginItemSettings(settings);
});
});

function resetApp() {
const cancelButtonId = 0;

const response = dialog.showMessageBoxSync(mb.window, {
type: 'warning',
title: 'Reset Gitify',
message:
'Are you sure you want to reset Gitify? You will be logged out of all accounts',
buttons: ['Cancel', 'Reset'],
defaultId: cancelButtonId,
cancelId: cancelButtonId,
});

if (response === cancelButtonId) {
return;
}

mb.window.webContents.send('gitify:reset-app');
mb.app.quit();
}