2019-11-23 17:22:24 +01:00
import QtQuick 2.0
import QtWebEngine 1.8
2021-01-31 16:21:32 +01:00
import ScreenPlay . Enums . InstalledType 1.0
2020-07-18 20:21:47 +02:00
import ScreenPlayWallpaper 1.0
2019-11-23 18:20:32 +01:00
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 . showScrollBars = false
WebEngine . settings . playbackRequiresUserGesture = false
2020-06-21 16:07:10 +02:00
WebEngine . settings . focusOnNavigationEnabled = true
}
function getSetVideoCommand ( ) {
// 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');"
2020-07-18 20:21:47 +02:00
src += "videoSource.src = '" + Wallpaper . fullContentPath + "';"
2020-06-21 16:07:10 +02:00
src += "videoPlayer.load();"
2020-07-18 20:21:47 +02:00
src += "videoPlayer.volume = " + Wallpaper . volume + ";"
src += "videoPlayer.setAttribute('style', 'object-fit :" + Wallpaper . fillMode + ";');"
2020-06-21 16:07:10 +02:00
src += "videoPlayer.play();"
return src
2019-11-23 17:22:24 +01:00
}
WebEngineView {
id: webView
anchors.fill: parent
2020-08-22 12:14:05 +02:00
url: "qrc:/index.html"
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 ) ) {
2021-01-31 16:21:32 +01:00
if ( Wallpaper . type === InstalledType . VideoWallpaper ) {
2020-06-21 16:07:10 +02:00
webView . runJavaScript ( root . getSetVideoCommand ( ) ,
function ( result ) {
fadeInTimer . start ( )
} )
2019-11-23 18:20:32 +01:00
} 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: {
2020-07-18 20:21:47 +02:00
webView . visible = ! Wallpaper . visualsPaused
txtVisualsPaused . visible = Wallpaper . visualsPaused
2020-03-28 12:39:53 +01:00
}
}
2019-11-23 17:22:24 +01:00
Connections {
2020-07-18 20:21:47 +02:00
target: Wallpaper
2020-08-11 20:18:34 +02:00
function onReloadVideo ( oldType ) {
2020-07-18 20:21:47 +02:00
webView . runJavaScript ( root . getSetVideoCommand ( ) )
}
2019-11-23 17:22:24 +01:00
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 (
2020-07-18 20:21:47 +02:00
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.volume = " + Wallpaper . volume + ";" )
2019-11-23 17:22:24 +01:00
}
}
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 ) {
2020-07-18 20:21:47 +02:00
// Wait until Wallpaper animation is finsihed
2020-03-28 12:39:53 +01:00
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();" )
}
}
}
}
}