This repository has been archived by the owner on Sep 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
WindowDimmer.vue
110 lines (102 loc) · 2.3 KB
/
WindowDimmer.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<template>
<div
:class="{
[$style.dimmer]: true,
[$style.active]: isActive,
}"
>
<div :class="$style.screen" />
</div>
</template>
<script>
export default {
data() {
return {
delay: 5000,
timeout: null,
isActive: false,
};
},
computed: {
settingsIsDimActive() {
return this.$store.getters['Settings/byKey']('dimmer.dimIfWindowIsNotInFocus');
},
windowHasFocus() {
return this.$store.getters['Window/hasFocus'];
},
},
watch: {
windowHasFocus(value) {
clearTimeout(this.timeout);
if (!value && this.settingsIsDimActive) {
this.timeout = setTimeout(() => {
this.isActive = true;
}, this.delay);
} else {
this.isActive = false;
}
},
settingsIsDimActive(value) {
if (!value) {
clearTimeout(this.timeout);
this.isActive = false;
}
},
},
created() {
this.$electron.remote.app.on('browser-window-blur', this.onBlur);
this.$electron.remote.app.on('browser-window-focus', this.onFocus);
window.addEventListener('beforeunload', () => {
clearTimeout(this.timeout);
this.$electron.remote.app.off('browser-window-blur', this.onBlur);
this.$electron.remote.app.off('browser-window-focus', this.onFocus);
});
},
methods: {
onBlur() {
this.$store.dispatch('Window/hasFocus', false);
},
onFocus() {
this.$store.dispatch('Window/hasFocus', true);
},
},
};
</script>
<style lang="scss" module>
.dimmer {
position: fixed;
top: -400vh;
right: 0;
left: 0;
height: 400vh;
z-index: 40;
background-image: linear-gradient(
theme('colors.gray.900'),
theme('colors.gray.900') 25%,
transparent 100%,
);
&.active {
top: 0;
transition-duration: 1500ms;
transition-property: top;
transition-timing-function: ease-out;
}
}
.screen {
height: 100vh;
background-image: url(@/assets/logo/logo.png);
background-position: center;
background-repeat: no-repeat;
background-size: 192px, contain;
opacity: 0;
transform: rotate(45deg);
.active & {
opacity: 0.5;
transition-delay: 1750ms;
transition-duration: 500ms;
transition-property: opacity, transform;
transition-timing-function: ease-out;
transform: rotate(0);
}
}
</style>