diff options
author | 2018-11-24 20:20:31 +0100 | |
---|---|---|
committer | 2018-11-24 20:20:31 +0100 | |
commit | df4d195ec7135c76f8f5de54c3939d2e74e80d4a (patch) | |
tree | 9a669462fa769d47e7be055b2026be7b58dc14a7 /src/helpers | |
parent | feat(App): Lay groundwork for general themeing support (diff) | |
download | ferdium-app-df4d195ec7135c76f8f5de54c3939d2e74e80d4a.tar.gz ferdium-app-df4d195ec7135c76f8f5de54c3939d2e74e80d4a.tar.zst ferdium-app-df4d195ec7135c76f8f5de54c3939d2e74e80d4a.zip |
Delay app based on featureAPI settings
Diffstat (limited to 'src/helpers')
-rw-r--r-- | src/helpers/visibility-helper.js | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/helpers/visibility-helper.js b/src/helpers/visibility-helper.js new file mode 100644 index 000000000..8456c4ecf --- /dev/null +++ b/src/helpers/visibility-helper.js | |||
@@ -0,0 +1,27 @@ | |||
1 | export function onVisibilityChange(cb) { | ||
2 | let isVisible = true; | ||
3 | |||
4 | if (!cb) { | ||
5 | throw new Error('no callback given'); | ||
6 | } | ||
7 | |||
8 | function focused() { | ||
9 | if (!isVisible) { | ||
10 | cb(isVisible = true); | ||
11 | } | ||
12 | } | ||
13 | |||
14 | function unfocused() { | ||
15 | if (isVisible) { | ||
16 | cb(isVisible = false); | ||
17 | } | ||
18 | } | ||
19 | |||
20 | document.addEventListener('visibilitychange', () => { (document.hidden ? unfocused : focused)(); }); | ||
21 | |||
22 | window.onpageshow = focused; | ||
23 | window.onfocus = focused; | ||
24 | |||
25 | window.onpagehid = unfocused; | ||
26 | window.onblur = unfocused; | ||
27 | } | ||