diff options
author | 2021-08-13 00:45:01 +0530 | |
---|---|---|
committer | 2021-08-13 00:45:01 +0530 | |
commit | 2d27d5e66649d4f5baf127a53ee5ae524eae3a59 (patch) | |
tree | c592ea219ac8cd987fc367f57b54034c450ab2ab /src/features/delayApp/index.js | |
parent | Ferdi v5.6.0 (diff) | |
parent | 5.6.1-nightly.24 [skip ci] (diff) | |
download | ferdium-app-2d27d5e66649d4f5baf127a53ee5ae524eae3a59.tar.gz ferdium-app-2d27d5e66649d4f5baf127a53ee5ae524eae3a59.tar.zst ferdium-app-2d27d5e66649d4f5baf127a53ee5ae524eae3a59.zip |
chore: merge from nightly branch into release branch in prep for next beta
Diffstat (limited to 'src/features/delayApp/index.js')
-rw-r--r-- | src/features/delayApp/index.js | 80 |
1 files changed, 0 insertions, 80 deletions
diff --git a/src/features/delayApp/index.js b/src/features/delayApp/index.js deleted file mode 100644 index f0c2bdc82..000000000 --- a/src/features/delayApp/index.js +++ /dev/null | |||
@@ -1,80 +0,0 @@ | |||
1 | import { autorun, observable, reaction } from 'mobx'; | ||
2 | import moment from 'moment'; | ||
3 | import DelayAppComponent from './Component'; | ||
4 | import { config } from './constants'; | ||
5 | import { DEFAULT_FEATURES_CONFIG } from '../../config'; | ||
6 | import { getUserWorkspacesRequest } from '../workspaces/api'; | ||
7 | |||
8 | const debug = require('debug')('Ferdi:feature:delayApp'); | ||
9 | |||
10 | export const state = observable({ | ||
11 | isDelayAppScreenVisible: DEFAULT_FEATURES_CONFIG.needToWaitToProceed, | ||
12 | }); | ||
13 | |||
14 | function setVisibility(value) { | ||
15 | Object.assign(state, { | ||
16 | isDelayAppScreenVisible: value, | ||
17 | }); | ||
18 | } | ||
19 | |||
20 | export default function init(stores) { | ||
21 | debug('Initializing `delayApp` feature'); | ||
22 | |||
23 | let shownAfterLaunch = false; | ||
24 | let timeLastDelay = moment(); | ||
25 | |||
26 | window.ferdi.features.delayApp = { | ||
27 | state, | ||
28 | }; | ||
29 | |||
30 | reaction( | ||
31 | () => ( | ||
32 | stores.user.isLoggedIn | ||
33 | && stores.services.allServicesRequest.wasExecuted | ||
34 | && getUserWorkspacesRequest.wasExecuted | ||
35 | && stores.features.features.needToWaitToProceed | ||
36 | && !stores.user.data.isPremium | ||
37 | ), | ||
38 | (isEnabled) => { | ||
39 | if (isEnabled) { | ||
40 | debug('Enabling `delayApp` feature'); | ||
41 | |||
42 | const { needToWaitToProceedConfig: globalConfig } = stores.features.features; | ||
43 | |||
44 | config.delayOffset = globalConfig.delayOffset !== undefined ? globalConfig.delayOffset : DEFAULT_FEATURES_CONFIG.needToWaitToProceedConfig.delayOffset; | ||
45 | config.delayDuration = globalConfig.wait !== undefined ? globalConfig.wait : DEFAULT_FEATURES_CONFIG.needToWaitToProceedConfig.wait; | ||
46 | |||
47 | autorun(() => { | ||
48 | const { isAnnouncementShown } = stores.announcements; | ||
49 | if (stores.services.allDisplayed.length === 0 || isAnnouncementShown) { | ||
50 | shownAfterLaunch = true; | ||
51 | setVisibility(false); | ||
52 | return; | ||
53 | } | ||
54 | |||
55 | const diff = moment().diff(timeLastDelay); | ||
56 | const itsTimeToWait = diff >= config.delayOffset; | ||
57 | if (!isAnnouncementShown && ((stores.app.isFocused && itsTimeToWait) || !shownAfterLaunch)) { | ||
58 | debug(`App will be delayed for ${config.delayDuration / 1000}s`); | ||
59 | |||
60 | setVisibility(true); | ||
61 | |||
62 | setTimeout(() => { | ||
63 | debug('Resetting app delay'); | ||
64 | |||
65 | shownAfterLaunch = true; | ||
66 | timeLastDelay = moment(); | ||
67 | setVisibility(false); | ||
68 | }, config.delayDuration + 1000); // timer needs to be able to hit 0 | ||
69 | } else { | ||
70 | setVisibility(false); | ||
71 | } | ||
72 | }); | ||
73 | } else { | ||
74 | setVisibility(false); | ||
75 | } | ||
76 | }, | ||
77 | ); | ||
78 | } | ||
79 | |||
80 | export const Component = DelayAppComponent; | ||