@@ -21,6 +21,7 @@ Module.register('MMM-Screen-Powersave-Notification', {
21
21
displayHours : false ,
22
22
animationSpeed : 0 ,
23
23
hideInsteadShutoff : false ,
24
+ changeToProfile : null ,
24
25
hideAnimationSpeed : 500 ,
25
26
} ,
26
27
@@ -54,31 +55,33 @@ Module.register('MMM-Screen-Powersave-Notification', {
54
55
clearTimeout ( this . currentDelayTimer )
55
56
56
57
const wrapper = document . createElement ( 'div' )
57
- const textWrapper = document . createElement ( 'span' )
58
+
59
+ if ( ( ! this . delayDisabled ) || ( this . config . disabledText !== null ) ) {
60
+ const textWrapper = document . createElement ( 'span' )
58
61
textWrapper . className = 'textWrapper'
59
62
60
- textWrapper . innerHTML = this . config . countDownText
61
- wrapper . appendChild ( textWrapper )
63
+ textWrapper . innerHTML = this . config . countDownText
64
+ wrapper . appendChild ( textWrapper )
62
65
63
66
64
- const valueWrapper = document . createElement ( 'span' )
65
- valueWrapper . className = 'valueWrapper'
67
+ const valueWrapper = document . createElement ( 'span' )
68
+ valueWrapper . className = 'valueWrapper'
66
69
67
- if ( this . delayDisabled ) {
68
- valueWrapper . innerHTML = this . config . disabledText
69
- } else {
70
- //valueWrapper.innerHTML = moment("1900-01-01 00:00:00").add(this.currentDelay, 'seconds').format(this.config.countDownFormatString)
71
- valueWrapper . innerHTML = this . getTimeString ( this . currentDelay )
72
- }
70
+ if ( this . delayDisabled ) {
71
+ valueWrapper . innerHTML = this . config . disabledText
72
+ } else {
73
+ //valueWrapper.innerHTML = moment("1900-01-01 00:00:00").add(this.currentDelay, 'seconds').format(this.config.countDownFormatString)
74
+ valueWrapper . innerHTML = this . getTimeString ( this . currentDelay )
75
+ }
73
76
74
- wrapper . appendChild ( valueWrapper )
77
+ wrapper . appendChild ( valueWrapper )
75
78
76
- const self = this
77
- self . currentDelayTimer = setTimeout ( function ( ) {
78
- console . log ( "UPDATING currentDelay" ) ;
79
- self . currentDelay = self . currentDelay - ( self . config . countDownUpdateInterval / 1000 ) ;
80
- self . updateDom ( self . config . animationSpeed )
81
- } , self . config . countDownUpdateInterval ) ;
79
+ const self = this
80
+ self . currentDelayTimer = setTimeout ( function ( ) {
81
+ self . currentDelay = self . currentDelay - ( self . config . countDownUpdateInterval / 1000 ) ;
82
+ self . updateDom ( self . config . animationSpeed )
83
+ } , self . config . countDownUpdateInterval ) ;
84
+ }
82
85
83
86
return wrapper ;
84
87
} ,
@@ -89,13 +92,13 @@ Module.register('MMM-Screen-Powersave-Notification', {
89
92
this . currentDelay = this . config . delay
90
93
this . delayDisabled = false
91
94
this . hiddenModules = null
95
+ this . profileHistory = [ ]
92
96
} ,
93
97
94
98
hideModules : function ( ) {
95
99
const self = this
96
100
self . hiddenModules = [ ]
97
101
var allModules = MM . getModules ( )
98
- self . sendNotification ( "DISABLE_PROFILE_TIMERS" )
99
102
allModules . enumerate ( function ( curModule ) {
100
103
var callback = function ( ) { }
101
104
var options = { lockString : self . identifier }
@@ -106,7 +109,6 @@ Module.register('MMM-Screen-Powersave-Notification', {
106
109
107
110
showModules : function ( ) {
108
111
const self = this
109
- self . sendNotification ( "ENABLE_PROFILE_TIMERS" )
110
112
if ( self . hiddenModules ) {
111
113
for ( var curModule in self . hiddenModules ) {
112
114
var callback = function ( ) { }
@@ -128,9 +130,22 @@ Module.register('MMM-Screen-Powersave-Notification', {
128
130
}
129
131
this . updateDom ( )
130
132
} else if ( notification === 'SCREEN_HIDE_MODULES' ) {
131
- self . hideModules ( )
133
+ self . sendNotification ( "DISABLE_PROFILE_TIMERS" )
134
+ if ( self . changeToProfile !== null ) {
135
+ if ( self . profileHistory [ 1 ] === self . config . changeToProfile ) {
136
+ self . profileHistory [ 0 ] = self . profileHistory [ 1 ]
137
+ }
138
+ self . sendNotification ( "CURRENT_PROFILE" , self . config . changeToProfile )
139
+ } else {
140
+ self . hideModules ( )
141
+ }
132
142
} else if ( notification === 'SCREEN_SHOW_MODULES' ) {
133
- self . showModules ( )
143
+ self . sendNotification ( "ENABLE_PROFILE_TIMERS" )
144
+ if ( self . changeToProfile !== null ) {
145
+ self . sendNotification ( "CURRENT_PROFILE" , self . profileHistory [ 0 ] )
146
+ } else {
147
+ self . showModules ( )
148
+ }
134
149
} else if (
135
150
( notification === 'SCREENSAVE_ENABLED' ) ||
136
151
( notification === 'SCREENSAVE_DISABLED' )
@@ -140,15 +155,25 @@ Module.register('MMM-Screen-Powersave-Notification', {
140
155
} ,
141
156
142
157
notificationReceived : function ( notification , payload ) {
158
+ const self = this
143
159
if (
144
160
( notification === 'USER_PRESENCE' ) ||
145
- ( notification === 'CHANGED_PROFILE' ) ||
146
161
( notification === 'SCREEN_TOGGLE' ) ||
147
162
( notification === 'SCREEN_ON' ) ||
148
163
( notification === 'SCREEN_OFF' ) ||
149
164
( notification === 'SCREEN_POWERSAVE' )
150
165
) {
151
166
this . sendSocketNotification ( notification , payload )
152
167
}
168
+ else if ( notification === 'CHANGED_PROFILE' ) {
169
+ if ( self . profileHistory . length > 1 ) {
170
+ self . profileHistory [ 0 ] = self . profileHistory [ 1 ]
171
+ self . profileHistory [ 1 ] = payload . to
172
+ } else {
173
+ self . profileHistory [ 0 ] = payload . to
174
+ self . profileHistory [ 1 ] = payload . to
175
+ }
176
+ this . sendSocketNotification ( notification , payload )
177
+ }
153
178
}
154
179
} )
0 commit comments