2019-11-23 17:22:24 +01:00
import QtQuick 2.0
import QtWebEngine 1.8
2019-11-23 18:20:32 +01:00
import ScreenPlay . Wallpaper 1.0
2019-11-23 17:22:24 +01:00
Item {
2020-02-06 18:39:48 +01:00
id: root
2019-11-23 18:20:32 +01:00
property alias url: webView . url
2019-11-23 17:22:24 +01:00
2020-02-08 13:36:19 +01:00
signal requestFadeIn
2019-11-23 17:22:24 +01:00
Component.onCompleted: {
2020-02-06 18:39:48 +01:00
WebEngine . settings . localContentCanAccessFileUrls = true
WebEngine . settings . localContentCanAccessRemoteUrls = true
2019-11-23 17:22:24 +01:00
WebEngine . settings . allowRunningInsecureContent = true
WebEngine . settings . accelerated2dCanvasEnabled = true
WebEngine . settings . javascriptCanOpenWindows = false
WebEngine . settings . printElementBackgrounds = false
WebEngine . settings . showScrollBars = false
WebEngine . settings . playbackRequiresUserGesture = false
}
WebEngineView {
id: webView
anchors.fill: parent
2020-02-06 18:39:48 +01:00
url: {
2020-02-08 13:36:19 +01:00
2020-02-06 18:39:48 +01:00
if ( window . type === Wallpaper . WallpaperType . Video ) {
2020-02-08 13:36:19 +01:00
return Qt . resolvedUrl ( window . getApplicationPath ( ) + "/index.html" )
2020-02-06 18:39:48 +01:00
}
if ( window . type === Wallpaper . WallpaperType . Html ) {
2020-02-08 13:36:19 +01:00
return Qt . resolvedUrl ( window . fullContentPath + "/index.html" )
2020-02-06 18:39:48 +01:00
}
}
2019-11-23 18:20:32 +01:00
onJavaScriptConsoleMessage: print ( lineNumber , message )
2019-11-23 17:22:24 +01:00
onLoadProgressChanged: {
2019-11-23 18:20:32 +01:00
if ( ( loadProgress === 100 ) ) {
2019-11-23 17:22:24 +01:00
2020-02-08 13:36:19 +01:00
if ( window . type === Wallpaper . WallpaperType . Video ) {
2019-11-23 18:20:32 +01:00
// TODO 30:
// Currently wont work. Commit anyways til QtCreator and Qt work with js template literals
var src = ""
src += "var videoPlayer = document.getElementById('videoPlayer');"
src += "var videoSource = document.getElementById('videoSource');"
src += "videoSource.src = '" + window . fullContentPath + "';"
src += "videoPlayer.load();"
src += "videoPlayer.volume = " + window . volume + ";"
2020-02-08 13:36:19 +01:00
src += "videoPlayer.setAttribute('style', 'object-fit :"
+ window . fillMode + ";');"
2019-11-23 18:20:32 +01:00
src += "videoPlayer.play();"
2019-11-23 17:22:24 +01:00
2019-11-23 18:20:32 +01:00
webView . runJavaScript ( src , function ( result ) {
fadeInTimer . start ( )
} )
} else {
2019-11-23 17:22:24 +01:00
fadeInTimer . start ( )
2019-11-23 18:20:32 +01:00
}
2019-11-23 17:22:24 +01:00
}
}
}
Timer {
id: fadeInTimer
interval: 500
onTriggered: requestFadeIn ( )
}
2020-03-21 13:07:27 +01:00
Text {
id: txtVisualsPaused
text: qsTr ( "If you can read this, then the VisualsPaused optimization does not work on your system. You can fix this by disable this in: \n Settings -> Perfromance -> Pause wallpaper video rendering while another app is in the foreground " )
font.pointSize: 32
2020-03-28 12:39:53 +01:00
visible: false
2020-03-21 13:07:27 +01:00
horizontalAlignment: Text . AlignHCenter
verticalAlignment: Text . AlignVCenter
wrapMode: Text . WrapAtWordBoundaryOrAnywhere
2020-03-28 12:39:53 +01:00
anchors.centerIn: parent
2020-03-21 13:07:27 +01:00
width: parent . width * . 8
color: "white"
}
2020-03-28 12:39:53 +01:00
Timer {
id: timerCover
interval: 300
onTriggered: {
webView . visible = ! window . visualsPaused
txtVisualsPaused . visible = window . visualsPaused
}
}
2019-11-23 17:22:24 +01:00
Connections {
target: window
2020-03-25 21:29:01 +01:00
function onQmlExit ( ) {
2019-11-23 17:22:24 +01:00
webView . runJavaScript (
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.volume = 0;" )
}
2020-03-25 21:29:01 +01:00
function onMutedChanged ( muted ) {
2019-11-23 17:22:24 +01:00
if ( muted ) {
webView . runJavaScript (
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.volume = 0;" )
} else {
webView . runJavaScript (
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.volume = " + window . volume + ";" )
}
}
2020-03-25 21:29:01 +01:00
function onFillModeChanged ( fillMode ) {
2019-11-23 17:22:24 +01:00
if ( webView . loadProgress === 100 ) {
webView . runJavaScript (
2020-03-25 21:29:01 +01:00
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.setAttribute('style', 'object-fit :" + fillMode + ";');" )
2019-11-23 17:22:24 +01:00
}
}
2020-03-25 21:29:01 +01:00
function onLoopsChanged ( loops ) {
2019-11-23 17:22:24 +01:00
if ( webView . loadProgress === 100 ) {
webView . runJavaScript (
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.loop = " + loops + ";" )
}
}
2020-03-25 21:29:01 +01:00
function onVolumeChanged ( volume ) {
2019-11-23 17:22:24 +01:00
if ( webView . loadProgress === 100 ) {
webView . runJavaScript (
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.volume = " + volume + ";" )
}
}
2020-03-25 21:29:01 +01:00
function onCurrentTimeChanged ( currentTime ) {
2019-11-23 17:22:24 +01:00
if ( webView . loadProgress === 100 ) {
webView . runJavaScript (
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.currentTime = "
+ currentTime + " * videoPlayer.duration;" )
}
}
2020-03-25 21:29:01 +01:00
function onPlaybackRateChanged ( playbackRate ) {
2019-11-23 17:22:24 +01:00
if ( webView . loadProgress === 100 ) {
webView . runJavaScript (
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.playbackRate = " + playbackRate + ";" )
}
}
2020-03-28 12:39:53 +01:00
function onVisualsPausedChanged ( visualsPaused ) {
if ( visualsPaused ) {
// Wait until window animation is finsihed
timerCover . restart ( )
} else {
webView . visible = true
txtVisualsPaused . visible = false
2020-02-15 17:49:48 +01:00
}
}
2020-03-25 21:29:01 +01:00
function onIsPlayingChanged ( isPlaying ) {
2019-11-23 17:22:24 +01:00
if ( webView . loadProgress === 100 ) {
if ( isPlaying ) {
webView . runJavaScript (
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.play();" )
} else {
webView . runJavaScript (
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.pause();" )
}
}
}
}
}