Skip to content

Commit 7f280d8

Browse files
authored
feat(developer): reset application (#1405)
1 parent e61abc0 commit 7f280d8

File tree

3 files changed

+44
-38
lines changed

3 files changed

+44
-38
lines changed

src/context/App.test.tsx

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -304,28 +304,6 @@ describe('context/App.tsx', () => {
304304
});
305305
});
306306

307-
it('should call logout', async () => {
308-
const clearStateMock = jest.spyOn(storage, 'clearState');
309-
310-
const TestComponent = () => {
311-
const { logout } = useContext(AppContext);
312-
313-
return (
314-
<button type="button" onClick={logout}>
315-
Test Case
316-
</button>
317-
);
318-
};
319-
320-
const { getByText } = customRender(<TestComponent />);
321-
322-
act(() => {
323-
fireEvent.click(getByText('Test Case'));
324-
});
325-
326-
expect(clearStateMock).toHaveBeenCalledTimes(1);
327-
});
328-
329307
describe('settings methods', () => {
330308
const fetchNotificationsMock = jest.fn();
331309

src/context/App.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { webFrame } from 'electron';
1+
import { ipcRenderer, webFrame } from 'electron';
22
import {
33
type ReactNode,
44
createContext,
@@ -97,7 +97,6 @@ interface AppContextState {
9797
loginWithOAuthApp: (data: LoginOAuthAppOptions) => void;
9898
loginWithPersonalAccessToken: (data: LoginPersonalAccessTokenOptions) => void;
9999
logoutFromAccount: (account: Account) => void;
100-
logout: () => void;
101100

102101
notifications: AccountNotifications[];
103102
status: Status;
@@ -163,6 +162,13 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
163162
setKeyboardShortcut(settings.keyboardShortcut);
164163
}, [settings.keyboardShortcut]);
165164

165+
useEffect(() => {
166+
ipcRenderer.on('gitify:reset-app', () => {
167+
setAuth(defaultAuth);
168+
clearState();
169+
});
170+
}, []);
171+
166172
const clearFilters = useCallback(() => {
167173
const newSettings = { ...settings, ...defaultFilters };
168174
setSettings(newSettings);
@@ -239,11 +245,6 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
239245
[auth, settings],
240246
);
241247

242-
const logout = useCallback(() => {
243-
setAuth(defaultAuth);
244-
clearState();
245-
}, []);
246-
247248
const restoreSettings = useCallback(async () => {
248249
await migrateAuthenticatedAccounts();
249250

@@ -307,7 +308,6 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
307308
loginWithOAuthApp,
308309
loginWithPersonalAccessToken,
309310
logoutFromAccount,
310-
logout,
311311

312312
notifications,
313313
status,

src/electron/main.js

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const {
44
nativeTheme,
55
globalShortcut,
66
Menu,
7+
dialog,
78
} = require('electron/main');
89
const { menubar } = require('menubar');
910
const { autoUpdater } = require('electron-updater');
@@ -50,6 +51,12 @@ const contextMenu = Menu.buildFromTemplate([
5051
accelerator:
5152
process.platform === 'darwin' ? 'Alt+Cmd+I' : 'Ctrl+Shift+I',
5253
},
54+
{
55+
label: 'Reset App',
56+
click: () => {
57+
resetApp();
58+
},
59+
},
5360
],
5461
},
5562
{ type: 'separator' },
@@ -62,17 +69,17 @@ const contextMenu = Menu.buildFromTemplate([
6269
},
6370
]);
6471

72+
const mb = menubar({
73+
icon: idleIcon,
74+
index: `file://${__dirname}/index.html`,
75+
browserWindow: browserWindowOpts,
76+
preloadWindow: true,
77+
showDockIcon: false,
78+
});
79+
6580
app.whenReady().then(async () => {
6681
await onFirstRunMaybe();
6782

68-
const mb = menubar({
69-
icon: idleIcon,
70-
index: `file://${__dirname}/index.html`,
71-
browserWindow: browserWindowOpts,
72-
preloadWindow: true,
73-
showDockIcon: false,
74-
});
75-
7683
mb.on('ready', () => {
7784
autoUpdater.checkForUpdatesAndNotify();
7885

@@ -168,3 +175,24 @@ app.whenReady().then(async () => {
168175
app.setLoginItemSettings(settings);
169176
});
170177
});
178+
179+
function resetApp() {
180+
const cancelButtonId = 0;
181+
182+
const response = dialog.showMessageBoxSync(mb.window, {
183+
type: 'warning',
184+
title: 'Reset Gitify',
185+
message:
186+
'Are you sure you want to reset Gitify? You will be logged out of all accounts',
187+
buttons: ['Cancel', 'Reset'],
188+
defaultId: cancelButtonId,
189+
cancelId: cancelButtonId,
190+
});
191+
192+
if (response === cancelButtonId) {
193+
return;
194+
}
195+
196+
mb.window.webContents.send('gitify:reset-app');
197+
mb.app.quit();
198+
}

0 commit comments

Comments
 (0)