Skip to content

Commit

Permalink
fix: clear cache in menu
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirPal committed Mar 21, 2018
1 parent a3f3362 commit ae57962
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 57 deletions.
13 changes: 13 additions & 0 deletions app/containers/AuthForm/AuthDebugger/AuthDebugger.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import type {
Connector,
} from 'react-redux';

import {
settingsActions,
} from 'actions';
import {
getUiState,
} from 'selectors';
Expand All @@ -32,6 +35,7 @@ import CopyIcon from '@atlaskit/icon/glyph/copy';
import FileIcon from '@atlaskit/icon/glyph/file';
import CrossIcon from '@atlaskit/icon/glyph/cross';
import ShortcutIcon from '@atlaskit/icon/glyph/shortcut';
import EditorRemoveIcon from '@atlaskit/icon/glyph/editor/remove';

import {
AuthDebuggerContainer,
Expand Down Expand Up @@ -59,6 +63,15 @@ const AuthDebugger: StatelessFunctionalComponent<Props> = ({
Auth debug console 📺
</DebugHeaderTitle>
<DebugActions>
<Tooltip content="Clear cache">
<EditorRemoveIcon
onClick={() => {
dispatch(
settingsActions.clearElectronCache(),
);
}}
/>
</Tooltip>
<Tooltip content="Copy to clipboard">
<CopyIcon onClick={() => ipcRenderer.send('copy-login-debug', messages)} />
</Tooltip>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const GeneralSettings: StatelessFunctionalComponent<Props> = ({
<br />
<ButtonGroup>
<Button
appearance="danger"
appearance="primary"
onClick={clearChache}
>
Clear cache
Expand Down
39 changes: 38 additions & 1 deletion app/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import {
shell,
BrowserWindow,
} from 'electron';
import {
CLEAR_ELECTRON_CACHE,
} from './actions/actionTypes/settings';


export default class MenuBuilder {
Expand Down Expand Up @@ -58,6 +61,19 @@ export default class MenuBuilder {
{ label: 'Hide Others', accelerator: 'Command+Shift+H', role: 'hideothers' },
{ label: 'Show All', role: 'unhide' },
{ type: 'separator' },
{
label: 'Clear cache',
click: (menu, win) => {
if (win) {
win.webContents.send(
'dispatch',
{
type: CLEAR_ELECTRON_CACHE,
},
);
}
},
},
{
label: 'Quit',
accelerator: 'Command+Q',
Expand Down Expand Up @@ -183,8 +199,29 @@ export default class MenuBuilder {
shell.openExternal('https://web-pal.atlassian.net/servicedesk/customer/portal/2');
},
}],
}, {
label: 'Clear cache',
click: (menu, win) => {
if (win) {
win.webContents.send(
'dispatch',
{
type: CLEAR_ELECTRON_CACHE,
},
);
}
},
}, {
label: 'Quit',
accelerator: 'Ctrl+Q',
click: (menu, win) => {
if (win && win.id !== 1) {
win.hide();
} else {
app.quit();
}
},
}];

return templateDefault;
}
}
2 changes: 2 additions & 0 deletions app/sagas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ import * as traySagas from './tray';

import {
initializeApp,
createDispatchActionListener,
} from './initializeApp';


export default function* rootSaga(): Generator<*, void, *> {
yield all([
// INITIALIZATION
fork(initializeApp),
fork(createDispatchActionListener),

// auth
fork(authSagas.createIpcAuthListeners),
Expand Down
19 changes: 19 additions & 0 deletions app/sagas/initializeApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import {
call,
put,
take,
fork,
} from 'redux-saga/effects';
import {
Expand Down Expand Up @@ -45,6 +46,7 @@ import {
infoLog,
notify,
} from './ui';
import createIpcChannel from './ipc';

import jira from '../utils/jiraClient';
import {
Expand Down Expand Up @@ -292,3 +294,20 @@ export function* initializeApp(): Generator<*, *, *> {
yield put(uiActions.setUiState('initializeInProcess', false));
}
}


function getDispatchActionListener(channel) {
return function* listenReFetchIssue() {
while (true) {
const {
payload,
} = yield take(channel);
yield put(payload[0]);
}
};
}

export function* createDispatchActionListener(): Generator<*, *, *> {
const dispatchChannel = yield call(createIpcChannel, 'dispatch');
yield fork(getDispatchActionListener(dispatchChannel));
}
1 change: 0 additions & 1 deletion app/sagas/issues.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ function* fetchAdditionalWorklogsForIssues(issues) {
'filled issues with lacking worklogs: ',
withAdditionalWorklogs,
);
trackMixpanel('Additional worklogs was fetched');
return withAdditionalWorklogs;
}
return issues;
Expand Down
43 changes: 20 additions & 23 deletions app/sagas/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import * as Api from 'api';
import {
actionTypes,
uiActions,
authActions,
} from 'actions';
import {
getSettingsState,
Expand Down Expand Up @@ -95,24 +94,18 @@ export function* watchLocalDesktopSettingsChange(): Generator<*, *, *> {
yield takeEvery(actionTypes.SET_LOCAL_DESKTOP_SETTING, onChangeLocalDesktopSettings);
}

function* clearElectronCacheSaga(): Generator<*, *, *> {
try {
const appDir = remote.getGlobal('appDir');
yield call(removeDir, appDir);
yield put(authActions.logoutRequest({ dontForget: true }));
}
catch(e) {
console.log(`@@ Error while removing appDir (${appDir})`, e);
function* removeAllIn(dir, pathName) {
const p = path.join(dir, pathName);
const stat = yield cps(fs.lstat, p);
if (stat.isDirectory()) {
yield call(removeDir, p); // eslint-disable-line
} else {
yield cps(fs.unlink, p);
console.log(`Removed file ${p}`);
}
}

export function* watchClearElectronChanheRequest(): Generator<*, *, *> {
yield takeEvery(actionTypes.CLEAR_ELECTRON_CACHE, clearElectronCacheSaga);
}


function* removeDir(dir) {
const ex = fs.existsSync(dir);
const exists = yield cps(fs.lstat, dir);
if (exists) {
const files = yield cps(fs.readdir, dir);
Expand All @@ -124,13 +117,17 @@ function* removeDir(dir) {
}
}

function* removeAllIn(dir, pathName) {
const p = path.join(dir, pathName);
const stat = yield cps(fs.lstat, p);
if (stat.isDirectory()) {
yield call(removeDir, p);
} else {
yield cps(fs.unlink, p);
console.log(`Removed file ${p}`);
function* clearElectronCacheSaga(): Generator<*, *, *> {
try {
const appDir = remote.getGlobal('appDir');
yield call(removeDir, appDir);
remote.app.relaunch();
remote.app.exit(0);
} catch (err) {
console.log('@@ Error while removing appDir', err);
}
}

export function* watchClearElectronChanheRequest(): Generator<*, *, *> {
yield takeEvery(actionTypes.CLEAR_ELECTRON_CACHE, clearElectronCacheSaga);
}
Loading

0 comments on commit ae57962

Please sign in to comment.