forked from webosbrew/custom-screensaver
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathscreensaver-main.qml
371 lines (364 loc) · 12.4 KB
/
screensaver-main.qml
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
/*
* Aerial screensaver.
*
* Usage:
* mount --bind ./screensaver-main.qml /usr/palm/applications/com.webos.app.screensaver/qml/main.qml
*
* Test launch (no way to trigger on "No signal" screen)
* luna-send -n 1 'luna://com.webos.service.tvpower/power/turnOnScreenSaver' '{}'
*/
import QtQuick 2.4
import QtMultimedia 5.6
import Eos.Window 0.1
import Eos.Items 0.1
import WebOS.Global 1.0
import QtQuick.Window 2.2
import WebOSServices 1.0
import iLib 1.0 as I
WebOSWindow {
id : window
width : 1920
height : 1080
windowType : "_WEBOS_WINDOW_TYPE_SCREENSAVER"
color : "black"
appId : "com.webos.app.screensaver"
visible : true
property var poi
property var poiIndex: 0
property var settings
property var playList
property int randomIndex
property int stalledCounter : 0
property string sourceAlt
property string basePath : "file:///media/developer/apps/usr/palm/applications/org.aabytt.webos.custom-screensaver-aerial/assets/"
Component.onCompleted : {
init()
notificationsService.set('disable')
playRandomVideo()
}
I.ILib {
id : ilib
}
FontLoader {
id : segoeUILight
source : basePath + 'SegoeUI-Light.ttf'
}
Timer {
id : refreshOSD
interval : 1000
running : true
repeat : true
onTriggered : {
checkError()
checkStatus()
updateOSD()
}
}
Video {
id : videoOutput
fillMode : VideoOutput.PreserveAspectCrop
width : parent.width
height : parent.height - 1 // non fullscreen to avoid screensaver automatic disabling
source : ""
visible : true
autoPlay : true
onStopped : {
punchThroughArea.visible = false
osd.visible = false
fadeOutVideo.running = false
}
onPaused : {
punchThroughArea.visible = false
playRandomVideo()
osd.visible = false
fadeOutVideo.running = false
}
onPlaying : {
punchThroughArea.visible = true
fadeInVideo.running = true
fadeInOsd.running = true
osd.visible = true
}
PunchThrough {
id : punchThroughArea
visible : false
x : 0
y : 0
z : -1
width : parent.width
height : parent.height
Rectangle {
id : opacityBox
width : 1920
height : 1080
z : 1
color : "black"
OpacityAnimator {
id : fadeInVideo
target : opacityBox
from : 1
to : 0
duration : 3000
running : false
}
OpacityAnimator {
id : fadeOutVideo
target : opacityBox
from : 0
to : 1
duration : 5000
running : false
}
}
}
}
Rectangle {
id : osd
opacity : 0
visible : true
color : "transparent"
anchors.fill : parent
anchors.margins : 65
OpacityAnimator {
id : fadeInOsd
target : osd
from : 0
to : 1
duration : 3000
running : false
}
OpacityAnimator {
id : fadeOutOsd
target : osd
from : 1
to : 0
duration : 5000
running : false
}
Text {
id : name
opacity : settings.osdOpacity / 100
text : poi.strings[playList.assets[randomIndex].localizedNameKey]
font.family : segoeUILight.name
font.letterSpacing : -1
fontSizeMode : Text.Fit
font.pixelSize : 56
y : parent.height * 0.9
color : "white"
style : Text.Raised
styleColor : "black"
}
Text {
id : poiOSD
opacity : name.opacity
text : poi.strings[playList.assets[randomIndex].pointsOfInterest[poiIndex]]
font.family : name.font.family
font.letterSpacing : name.font.letterSpacing
fontSizeMode : name.fontSizeMode
font.pixelSize : name.font.pixelSize - 16
y : name.y + name.font.pixelSize + 10
color : name.color
style : name.style
styleColor : name.styleColor
}
Text {
id : timeOSD
horizontalAlignment : Text.AlignRight
anchors.right : parent.right
opacity : name.opacity
font.family : name.font.family
font.letterSpacing : name.font.letterSpacing
font.pixelSize : name.font.pixelSize + 23
y : dateOSD.y - name.font.pixelSize - 40
color : name.color
style : name.style
styleColor : name.styleColor
fontSizeMode : name.fontSizeMode
}
Text {
id : dateOSD
horizontalAlignment : Text.AlignRight
anchors.right : parent.right
opacity : name.opacity
font.family : name.font.family
font.letterSpacing : name.font.letterSpacing
font.pixelSize : name.font.pixelSize - 16
y : name.y + name.font.pixelSize + 5
color : name.color
style : name.style
styleColor : name.styleColor
fontSizeMode : name.fontSizeMode
}
}
Text {
id : debug
visible : settings.debug
horizontalAlignment : Text.AlignRight
anchors.right : parent.right
anchors.margins : 25
opacity : 0.7
font.family : name.font.family
font.pixelSize : name.font.pixelSize - 30
color : name.color
style : name.style
styleColor : name.styleColor
fontSizeMode : name.fontSizeMode
}
function init() {
loadJSONData(basePath + 'settings.json', 'settings', loadResources)
}
function loadResources() {
loadJSONData(basePath + 'videos.json', 'playList')
loadJSONData(basePath + 'locales/' + settings.localeLang + '.json', 'poi', playRandomVideo)
}
function playRandomVideo() {
stalledCounter = 0
randomIndex = Math.floor(Math.random() * playList.assets.length)
if (!playList.assets[randomIndex].viewed) {
if (playList.assets[randomIndex][settings.sourceType]) {
sourceAlt = ""
videoOutput.source = playList.assets[randomIndex][settings.sourceType]
notificationsService.set('disable')
videoOutput.play()
} else if(settings.sourceType == "url-4K-HDR" && settings.playLowerQuality){
sourceAlt = " - n/a, trying url-4K-SDR"
videoOutput.source = playList.assets[randomIndex]["url-4K-SDR"]
videoOutput.play()
} else if(settings.sourceType == "url-1080-HDR" && settings.playLowerQuality){
if(playList.assets[randomIndex]["url-1080-SDR"]){
sourceAlt = " - n/a, trying url-1080-SDR"
videoOutput.source = playList.assets[randomIndex]["url-1080-SDR"]
videoOutput.play()
} else if(playList.assets[randomIndex]["url-1080-H264"]){
sourceAlt = " - n/a, trying url-1080-H264"
videoOutput.source = playList.assets[randomIndex]["url-1080-H264"]
videoOutput.play()
} else playRandomVideo()
} else playRandomVideo()
} else
playRandomVideo()
}
function checkError() {
if (videoOutput.error !== 0) {
notificationsService.set('enable')
punchThroughArea.visible = false
playRandomVideo()
}
}
function checkStatus() {
if (videoOutput.position > 2000) {
notificationsService.set('enable')
playList.assets[randomIndex].viewed = true
}
if (Math.floor(videoOutput.position / 1000) == Math.floor(videoOutput.duration / 1000) - 5) {
fadeOutVideo.running = true
fadeOutOsd.running = true
}
if (videoOutput.status == MediaPlayer.EndOfMedia)
playRandomVideo()
if (videoOutput.status === 1)
var status = 'NoMedia'
else if (videoOutput.status === 2) {
var status = 'Loading'
stalledCounter ++
if (stalledCounter > 25) {
punchThroughArea.visible = false
playRandomVideo()
}
}
else if (videoOutput.status === 3)
var status = 'Loaded'
else if (videoOutput.status === 4)
var status = 'Buffering'
else if (videoOutput.status === 5) {
var status = 'Stalled'
stalledCounter ++
if (stalledCounter > 25) {
punchThroughArea.visible = false
playRandomVideo()
}
}
else if (videoOutput.status === 6)
var status = 'Buffered'
else if (videoOutput.status === 7)
var status = 'EndOfMedia'
else if (videoOutput.status === 8)
var status = 'InvalidMedia'
else if (videoOutput.status === 0)
var status = 'UnknownStatus'
if (videoOutput.playbackState === 1)
var playbackState = 'playing'
else if (videoOutput.playbackState === 2)
var playbackState = 'paused'
else if (videoOutput.playbackState === 0){
var playbackState = 'stopped'
stalledCounter ++
if (stalledCounter > 5) {
punchThroughArea.visible = false
playRandomVideo()
}
}
debug.text = "Video " + randomIndex + " of " + playList.assets.length +
"\n Source Type: " + settings.sourceType + sourceAlt +
"\n Try Other Source: " + settings.playLowerQuality +
"\n Locale: " + settings.localeLang +
"\n OSD opacity: " + settings.osdOpacity + "%" +
"\n Timecode: " + Math.floor(videoOutput.position / 1000) + " / " + Math.floor(videoOutput.duration / 1000) +
"\n Media Status: " + status +
"\n Stalled Timeout: " + (25 - stalledCounter) +
"\n Error: " + videoOutput.error + " " + videoOutput.errorString +
"\n Playback State: " + playbackState +
"\n Buffer Progress : " + (
videoOutput.bufferProgress * 33.334).toFixed(0) + "%"
}
function updateOSD() {
var DateFmt = ilib.require("DateFmt.js")
var now = new Date()
var time = new DateFmt({
locale: settings.localeLang,
timezone: "local",
type: "time",
length: "full"
})
var day = new DateFmt({
locale: settings.localeLang,
timezone: "local",
type: "date",
date: "dmw",
length: "full"
})
timeOSD.text = time.format(now)
if (poi.date)
dateOSD.text = poi.date.daysOfWeek[now.getDay()
] + ", " + now.getDate() + " " + poi.date.months[now.getMonth()
]
else
dateOSD.text = day.format(now)
if (playList.assets[randomIndex].pointsOfInterest[Math.floor(videoOutput.position / 1000)])
poiIndex = Math.floor(videoOutput.position / 1000)
}
Service {
id : notificationsService
appId : globalVars.appId
function set(param) {
call("luna://com.webos.notification/", param)
}
}
function loadJSONData(url, targetVar, callback) {
var xhr = new XMLHttpRequest()
xhr.onreadystatechange = function () {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
var jsonData = JSON.parse(xhr.responseText)
eval(targetVar + " = jsonData")
callback()
} else {
console.error("Error loading JSON data:", xhr.statusText)
name.text = xhr.statusText
}
}
}
xhr.open("GET", url)
xhr.send()
}
}