diff options
Diffstat (limited to 'src/stores/RequestStore.js')
-rw-r--r-- | src/stores/RequestStore.js | 73 |
1 files changed, 0 insertions, 73 deletions
diff --git a/src/stores/RequestStore.js b/src/stores/RequestStore.js deleted file mode 100644 index 71a5360ac..000000000 --- a/src/stores/RequestStore.js +++ /dev/null | |||
@@ -1,73 +0,0 @@ | |||
1 | import { ipcRenderer } from 'electron'; | ||
2 | import { action, computed, observable } from 'mobx'; | ||
3 | import ms from 'ms'; | ||
4 | import { LOCAL_PORT } from '../config'; | ||
5 | |||
6 | import Store from './lib/Store'; | ||
7 | |||
8 | const debug = require('../preload-safe-debug')('Ferdium:RequestsStore'); | ||
9 | |||
10 | export default class RequestStore extends Store { | ||
11 | @observable userInfoRequest; | ||
12 | |||
13 | @observable servicesRequest; | ||
14 | |||
15 | @observable showRequiredRequestsError = false; | ||
16 | |||
17 | @observable localServerPort = LOCAL_PORT; | ||
18 | |||
19 | retries = 0; | ||
20 | |||
21 | retryDelay = ms('2s'); | ||
22 | |||
23 | constructor(...args) { | ||
24 | super(...args); | ||
25 | |||
26 | this.actions.requests.retryRequiredRequests.listen( | ||
27 | this._retryRequiredRequests.bind(this), | ||
28 | ); | ||
29 | |||
30 | this.registerReactions([this._autoRetry.bind(this)]); | ||
31 | } | ||
32 | |||
33 | setup() { | ||
34 | this.userInfoRequest = this.stores.user.getUserInfoRequest; | ||
35 | this.servicesRequest = this.stores.services.allServicesRequest; | ||
36 | |||
37 | ipcRenderer.on('localServerPort', (event, data) => { | ||
38 | if (data.port) { | ||
39 | this.localServerPort = data.port; | ||
40 | } | ||
41 | }); | ||
42 | } | ||
43 | |||
44 | @computed get areRequiredRequestsSuccessful() { | ||
45 | return !this.userInfoRequest.isError && !this.servicesRequest.isError; | ||
46 | } | ||
47 | |||
48 | @computed get areRequiredRequestsLoading() { | ||
49 | return this.userInfoRequest.isExecuting || this.servicesRequest.isExecuting; | ||
50 | } | ||
51 | |||
52 | @action _retryRequiredRequests() { | ||
53 | this.userInfoRequest.reload(); | ||
54 | this.servicesRequest.reload(); | ||
55 | } | ||
56 | |||
57 | // Reactions | ||
58 | _autoRetry() { | ||
59 | const delay = (this.retries <= 10 ? this.retries : 10) * this.retryDelay; | ||
60 | if (!this.areRequiredRequestsSuccessful && this.stores.user.isLoggedIn) { | ||
61 | setTimeout(() => { | ||
62 | this.retries += 1; | ||
63 | this._retryRequiredRequests(); | ||
64 | if (this.retries === 4) { | ||
65 | this.showRequiredRequestsError = true; | ||
66 | } | ||
67 | |||
68 | this._autoRetry(); | ||
69 | debug(`Retry required requests delayed in ${delay / 1000}s`); | ||
70 | }, delay); | ||
71 | } | ||
72 | } | ||
73 | } | ||