From feed29ec5bbae8c13b45f9a34791e76f460455db Mon Sep 17 00:00:00 2001 From: Dmytro Shaforostov Date: Wed, 21 Mar 2018 14:40:57 +0200 Subject: [PATCH] feat: add clear cache button to settings and error message of ErrorBoundary --- app/actions/actionTypes/settings.js | 2 + app/actions/settings.js | 4 + .../ErrorBoundary/ErrorBoundary.jsx | 29 ++++- .../SettingsModal/General/GeneralSettings.jsx | 18 ++++ .../Modals/SettingsModal/SettingsModal.jsx | 3 + app/sagas/index.js | 1 + app/sagas/settings.js | 45 ++++++++ app/types/settings.js | 3 + yarn.lock | 102 +++--------------- 9 files changed, 117 insertions(+), 90 deletions(-) diff --git a/app/actions/actionTypes/settings.js b/app/actions/actionTypes/settings.js index 684a8ad9e..43fce7959 100644 --- a/app/actions/actionTypes/settings.js +++ b/app/actions/actionTypes/settings.js @@ -3,3 +3,5 @@ export const FILL_LOCAL_DESKTOP_SETTINGS = 'settings/FILL_LOCAL'; export const SET_LOCAL_DESKTOP_SETTING = 'settings/SET_LOCAL'; export const SET_SETTINGS_MODAL_TAB = 'settings/SET_MODAL_TAB'; + +export const CLEAR_ELECTRON_CACHE = 'settings/CLEAR_ELECTRON_CACHE'; diff --git a/app/actions/settings.js b/app/actions/settings.js index 8246ca8d2..405531c5c 100644 --- a/app/actions/settings.js +++ b/app/actions/settings.js @@ -29,3 +29,7 @@ export const setSettingsModalTab = ( type: types.SET_SETTINGS_MODAL_TAB, tabName, }); + +export const clearElectronCache = (): SettingsAction => ({ + type: types.CLEAR_ELECTRON_CACHE, +}); diff --git a/app/components/ErrorBoundary/ErrorBoundary.jsx b/app/components/ErrorBoundary/ErrorBoundary.jsx index 21b564cab..d28f5768b 100644 --- a/app/components/ErrorBoundary/ErrorBoundary.jsx +++ b/app/components/ErrorBoundary/ErrorBoundary.jsx @@ -2,6 +2,15 @@ import React, { Component } from 'react'; import Raven from 'raven-js'; +import { connect } from 'react-redux'; + + +import Button from '@atlaskit/button'; + +import { + settingsActions, +} from 'actions'; + class ErrorBoundary extends Component { state = { @@ -26,10 +35,26 @@ class ErrorBoundary extends Component { render() { if (this.state.hasError) { - return

Something went wrong.

; + return ( +
+

Something went wrong.

+ You may try to + +
+ ); } return this.props.children; } } -export default ErrorBoundary; +export default connect( + null, + dispatch => ({ dispatch }), +)(ErrorBoundary); diff --git a/app/containers/Modals/SettingsModal/General/GeneralSettings.jsx b/app/containers/Modals/SettingsModal/General/GeneralSettings.jsx index d70b64e46..ea89229ed 100644 --- a/app/containers/Modals/SettingsModal/General/GeneralSettings.jsx +++ b/app/containers/Modals/SettingsModal/General/GeneralSettings.jsx @@ -11,6 +11,10 @@ import { CheckboxGroup, } from '@atlaskit/checkbox'; +import Button, { + ButtonGroup, +} from '@atlaskit/button'; + import { H100, } from 'styles/typography'; @@ -31,11 +35,13 @@ import { type Props = { settings: SettingsGeneral, setTraySettings: (value: any) => void, + clearChache: () => void, } const GeneralSettings: StatelessFunctionalComponent = ({ settings, setTraySettings, + clearChache, }: Props): Node => { const isIconHidden = !!settings.trayShowTimer; // const isTimerHidden = false; @@ -57,6 +63,18 @@ const GeneralSettings: StatelessFunctionalComponent = ({ onChange={() => setTraySettings(!isIconHidden)} /> +
+ + + + + Clearing cache will cause logout. + ); diff --git a/app/containers/Modals/SettingsModal/SettingsModal.jsx b/app/containers/Modals/SettingsModal/SettingsModal.jsx index bdf6f6cd0..253a53c9e 100644 --- a/app/containers/Modals/SettingsModal/SettingsModal.jsx +++ b/app/containers/Modals/SettingsModal/SettingsModal.jsx @@ -132,6 +132,9 @@ const SettingsModal: StatelessFunctionalComponent = ({ 'trayShowTimer', )); }} + clearChache={() => dispatch( + settingsActions.clearElectronCache(), + )} /> } {tab === 'Notifications' && diff --git a/app/sagas/index.js b/app/sagas/index.js index 656f359bf..badfe29ec 100644 --- a/app/sagas/index.js +++ b/app/sagas/index.js @@ -57,6 +57,7 @@ export default function* rootSaga(): Generator<*, void, *> { // settings fork(settingsSagas.watchLocalDesktopSettingsChange), + fork(settingsSagas.watchClearElectronChanheRequest), // worklogs fork(worklogsSagas.watchSaveWorklogRequest), diff --git a/app/sagas/settings.js b/app/sagas/settings.js index e1319514c..730b8a569 100644 --- a/app/sagas/settings.js +++ b/app/sagas/settings.js @@ -4,16 +4,21 @@ import { put, takeEvery, select, + cps, + all, } from 'redux-saga/effects'; import { remote, } from 'electron'; +import path from 'path'; +import fs from 'fs'; import * as Api from 'api'; import { actionTypes, uiActions, + authActions, } from 'actions'; import { getSettingsState, @@ -89,3 +94,43 @@ export function* onChangeLocalDesktopSettings({ 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); + } +} + +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); + yield all( + files.map(fileName => call(removeAllIn, dir, fileName)), + ); + yield cps(fs.rmdir, dir); + console.log(`Removed dir ${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}`); + } +} diff --git a/app/types/settings.js b/app/types/settings.js index c256db7ad..d9015b1c7 100644 --- a/app/types/settings.js +++ b/app/types/settings.js @@ -15,6 +15,9 @@ export type SettingsAction = {| type: typeof actionTypes.SET_SETTINGS_MODAL_TAB, tabName: string, + |} + {| + type: typeof actionTypes.CLEAR_ELECTRON_CACHE, |}; export type SettingsState = {| diff --git a/yarn.lock b/yarn.lock index a2786acec..aa08b60e0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -22,10 +22,6 @@ "7zip-bin-mac" "~1.0.1" "7zip-bin-win" "~2.1.1" -"7zip-bin@~3.0.0": - version "3.0.0" - resolved "https://registry.yarnpkg.com/7zip-bin/-/7zip-bin-3.0.0.tgz#17416dc542f41511b26a9667b92847d75ef150fe" - "7zip@0.0.6": version "0.0.6" resolved "https://registry.yarnpkg.com/7zip/-/7zip-0.0.6.tgz#9cafb171af82329490353b4816f03347aa150a30" @@ -1878,16 +1874,7 @@ builder-util-runtime@4.0.3: fs-extra-p "^4.5.0" sax "^1.2.4" -builder-util-runtime@^4.0.3, builder-util-runtime@^4.0.5: - version "4.1.0" - resolved "https://registry.yarnpkg.com/builder-util-runtime/-/builder-util-runtime-4.1.0.tgz#7dcd042d555d2f161a5538d7a0ea8c292daa0683" - dependencies: - bluebird-lst "^1.0.5" - debug "^3.1.0" - fs-extra-p "^4.5.2" - sax "^1.2.4" - -builder-util-runtime@~4.0.3: +builder-util-runtime@^4.0.3, builder-util-runtime@~4.0.3: version "4.0.5" resolved "https://registry.yarnpkg.com/builder-util-runtime/-/builder-util-runtime-4.0.5.tgz#5340cf9886b9283ea6e5b20dc09b5e3e461aef62" dependencies: @@ -1896,7 +1883,7 @@ builder-util-runtime@~4.0.3: fs-extra-p "^4.5.0" sax "^1.2.4" -builder-util@4.2.1: +builder-util@4.2.1, builder-util@^4.2.1: version "4.2.1" resolved "https://registry.yarnpkg.com/builder-util/-/builder-util-4.2.1.tgz#ca9f0ddb5af1da5fe432129f7c6cbd447b552016" dependencies: @@ -1916,26 +1903,6 @@ builder-util@4.2.1: temp-file "^3.1.1" tunnel-agent "^0.6.0" -builder-util@^4.2.1: - version "4.2.5" - resolved "https://registry.yarnpkg.com/builder-util/-/builder-util-4.2.5.tgz#babc190e2f2c3681497632b5cc274f1543aa9264" - dependencies: - "7zip-bin" "~3.0.0" - bluebird-lst "^1.0.5" - builder-util-runtime "^4.0.5" - chalk "^2.3.0" - debug "^3.1.0" - fs-extra-p "^4.5.0" - ini "^1.3.5" - is-ci "^1.1.0" - js-yaml "^3.10.0" - lazy-val "^1.0.3" - semver "^5.5.0" - source-map-support "^0.5.3" - stat-mode "^0.2.2" - temp-file "^3.1.1" - tunnel-agent "^0.6.0" - builtin-modules@^1.0.0, builtin-modules@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-1.1.1.tgz#270f076c5a72c02f5b65a47df94c5fe3a278892f" @@ -3953,14 +3920,10 @@ extract-zip@^1.0.3: mkdirp "0.5.0" yauzl "2.4.1" -extsprintf@1.3.0: +extsprintf@1.3.0, extsprintf@^1.2.0: version "1.3.0" resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.3.0.tgz#96918440e3041a7a414f8c52e3c574eb3c3e1e05" -extsprintf@^1.2.0: - version "1.4.0" - resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.4.0.tgz#e2689f8f356fad62cca65a3a91c5df5f9551692f" - eyes@0.1.x: version "0.1.8" resolved "https://registry.yarnpkg.com/eyes/-/eyes-0.1.8.tgz#62cf120234c683785d902348a800ef3e0cc20bc0" @@ -4257,7 +4220,7 @@ fs-exists-sync@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/fs-exists-sync/-/fs-exists-sync-0.1.0.tgz#982d6893af918e72d08dec9e8673ff2b5a8d6add" -fs-extra-p@^4.5.0, fs-extra-p@^4.5.2: +fs-extra-p@^4.5.0: version "4.5.2" resolved "https://registry.yarnpkg.com/fs-extra-p/-/fs-extra-p-4.5.2.tgz#0a22aba489284d17f375d5dc5139aa777fe2df51" dependencies: @@ -6093,7 +6056,7 @@ minimist-options@^3.0.1: arrify "^1.0.1" is-plain-obj "^1.1.0" -minimist@0.0.8: +minimist@0.0.8, minimist@~0.0.1: version "0.0.8" resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d" @@ -6101,10 +6064,6 @@ minimist@1.2.0, minimist@^1.1.0, minimist@^1.1.3, minimist@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284" -minimist@~0.0.1: - version "0.0.10" - resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf" - mixin-deep@^1.2.0: version "1.3.1" resolved "https://registry.yarnpkg.com/mixin-deep/-/mixin-deep-1.3.1.tgz#a49e7268dce1a0d9698e45326c5626df3543d0fe" @@ -6136,14 +6095,10 @@ moment-duration-format@2.2.1: version "2.2.1" resolved "https://registry.yarnpkg.com/moment-duration-format/-/moment-duration-format-2.2.1.tgz#b9ce5e5051a15282a0a6c361f0c05685c7ead47c" -moment@2.20.1: +moment@2.20.1, moment@2.x: version "2.20.1" resolved "https://registry.yarnpkg.com/moment/-/moment-2.20.1.tgz#d6eb1a46cbcc14a2b2f9434112c1ff8907f313fd" -moment@2.x: - version "2.21.0" - resolved "https://registry.yarnpkg.com/moment/-/moment-2.21.0.tgz#2a114b51d2a6ec9e6d83cf803f838a878d8a023a" - ms@0.7.3: version "0.7.3" resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.3.tgz#708155a5e44e33f5fd0fc53e81d0d40a91be1fff" @@ -6177,14 +6132,10 @@ mute-stream@0.0.7: version "0.0.7" resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab" -nan@2.8.0, nan@~2.8.0: +nan@2.8.0, nan@^2.3.0, nan@~2.8.0: version "2.8.0" resolved "https://registry.yarnpkg.com/nan/-/nan-2.8.0.tgz#ed715f3fe9de02b57a5e6252d90a96675e1f085a" -nan@^2.3.0: - version "2.10.0" - resolved "https://registry.yarnpkg.com/nan/-/nan-2.10.0.tgz#96d0cd610ebd58d4b4de9cc0c6828cda99c7548f" - nan@~2.7.0: version "2.7.0" resolved "https://registry.yarnpkg.com/nan/-/nan-2.7.0.tgz#d95bf721ec877e08db276ed3fc6eb78f9083ad46" @@ -6236,20 +6187,13 @@ node-abi@^2.1.1, node-abi@^2.2.0: dependencies: semver "^5.4.1" -node-fetch@1.6.3: +node-fetch@1.6.3, node-fetch@^1.0.1: version "1.6.3" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.6.3.tgz#dc234edd6489982d58e8f0db4f695029abcd8c04" dependencies: encoding "^0.1.11" is-stream "^1.0.1" -node-fetch@^1.0.1: - version "1.7.3" - resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.3.tgz#980f6f72d85211a5347c6b2bc18c5b84c3eb47ef" - dependencies: - encoding "^0.1.11" - is-stream "^1.0.1" - node-forge@0.7.1: version "0.7.1" resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.7.1.tgz#9da611ea08982f4b94206b3beb4cc9665f20c300" @@ -7689,14 +7633,10 @@ redux-resource-plugins@2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/redux-resource-plugins/-/redux-resource-plugins-2.1.0.tgz#e5ccc778d9db6d8fc2deef523da7090f8d4c9e8a" -redux-resource@2.4.0: +redux-resource@2.4.0, redux-resource@^2.0.0: version "2.4.0" resolved "https://registry.yarnpkg.com/redux-resource/-/redux-resource-2.4.0.tgz#9d132e2921f1ae77d8794d7c87fe16f47d237a08" -redux-resource@^2.0.0: - version "2.4.1" - resolved "https://registry.yarnpkg.com/redux-resource/-/redux-resource-2.4.1.tgz#cd12b45112ac9dc5ed42ffcb2f98ffd70fd81751" - redux-saga@0.16.0: version "0.16.0" resolved "https://registry.yarnpkg.com/redux-saga/-/redux-saga-0.16.0.tgz#0a231db0a1489301dd980f6f2f88d8ced418f724" @@ -7843,7 +7783,7 @@ request-promise@^4.1.1: stealthy-require "^1.1.0" tough-cookie ">=2.3.3" -request@2.81.0: +request@2.81.0, request@^2.45.0, request@^2.79.0: version "2.81.0" resolved "https://registry.yarnpkg.com/request/-/request-2.81.0.tgz#c6928946a0e06c5f8d6f8a9333469ffda46298a0" dependencies: @@ -7870,7 +7810,7 @@ request@2.81.0: tunnel-agent "^0.6.0" uuid "^3.0.0" -request@^2.45.0, request@^2.51.0, request@^2.79.0: +request@^2.83.0: version "2.85.0" resolved "https://registry.yarnpkg.com/request/-/request-2.85.0.tgz#5a03615a47c61420b3eb99b7dba204f83603e1fa" dependencies: @@ -8336,7 +8276,7 @@ source-map-resolve@^0.5.0: source-map-url "^0.4.0" urix "^0.1.0" -source-map-support@0.5.3: +source-map-support@0.5.3, source-map-support@^0.5.1, source-map-support@^0.5.2: version "0.5.3" resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.3.tgz#2b3d5fff298cfa4d1afd7d4352d569e9a0158e76" dependencies: @@ -8348,12 +8288,6 @@ source-map-support@^0.4.15: dependencies: source-map "^0.5.6" -source-map-support@^0.5.1, source-map-support@^0.5.2, source-map-support@^0.5.3: - version "0.5.4" - resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.4.tgz#54456efa89caa9270af7cd624cc2f123e51fbae8" - dependencies: - source-map "^0.6.0" - source-map-url@^0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/source-map-url/-/source-map-url-0.4.0.tgz#3e935d7ddd73631b97659956d55128e87b5084a3" @@ -9506,22 +9440,14 @@ winston@2.1.0: pkginfo "0.3.x" stack-trace "0.0.x" -word-wrap@1.1.0: +word-wrap@1.1.0, word-wrap@^1.0.3: version "1.1.0" resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.1.0.tgz#356153d61d10610d600785c5d701288e0ae764a6" -word-wrap@^1.0.3: - version "1.2.3" - resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c" - -wordwrap@0.0.2: +wordwrap@0.0.2, wordwrap@~0.0.2: version "0.0.2" resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.2.tgz#b79669bb42ecb409f83d583cad52ca17eaa1643f" -wordwrap@~0.0.2: - version "0.0.3" - resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.3.tgz#a3d5da6cd5c0bc0008d37234bbaf1bed63059107" - wordwrap@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb"