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
2021-05-16 19:37:55 +02:00
2019-11-23 18:20:32 +01:00
property alias url: webView . url
2019-11-23 17:22:24 +01:00
2021-08-14 13:38:24 +02:00
signal requestFadeIn
2020-06-21 16:07:10 +02:00
function getSetVideoCommand ( ) {
// TODO 30:
// Currently wont work. Commit anyways til QtCreator and Qt work with js template literals
2021-08-14 13:38:24 +02:00
var src = ""
src += "var videoPlayer = document.getElementById('videoPlayer');"
src += "var videoSource = document.getElementById('videoSource');"
src += "videoSource.src = '" + Wallpaper . projectSourceFileAbsolute + "';"
src += "videoPlayer.load();"
src += "videoPlayer.volume = " + Wallpaper . volume + ";"
src += "videoPlayer.setAttribute('style', 'object-fit :" + Wallpaper . fillMode + ";');"
src += "videoPlayer.play();"
return src
2021-05-16 19:37:55 +02:00
}
Component.onCompleted: {
2021-08-14 13:38:24 +02:00
WebEngine . settings . localContentCanAccessFileUrls = true
WebEngine . settings . localContentCanAccessRemoteUrls = true
WebEngine . settings . allowRunningInsecureContent = true
WebEngine . settings . accelerated2dCanvasEnabled = true
WebEngine . settings . javascriptCanOpenWindows = false
WebEngine . settings . showScrollBars = false
WebEngine . settings . playbackRequiresUserGesture = false
WebEngine . settings . focusOnNavigationEnabled = true
2019-11-23 17:22:24 +01:00
}
WebEngineView {
id: webView
2021-05-16 19:37:55 +02:00
2019-11-23 17:22:24 +01:00
anchors.fill: parent
2020-08-22 12:14:05 +02:00
url: "qrc:/index.html"
2021-02-19 17:21:17 +01:00
backgroundColor: "transparent"
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-05-16 19:37:55 +02:00
if ( Wallpaper . type === InstalledType . VideoWallpaper )
2021-08-14 13:38:24 +02:00
webView . runJavaScript ( root . getSetVideoCommand ( ) ,
function ( result ) {
requestFadeIn ( )
} )
2021-05-16 19:37:55 +02:00
else
2021-08-14 13:38:24 +02:00
requestFadeIn ( )
2019-11-23 17:22:24 +01:00
}
}
}
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
2021-05-16 19:37:55 +02:00
width: parent . width * 0.8
2020-03-21 13:07:27 +01:00
color: "white"
}
2020-03-28 12:39:53 +01:00
Timer {
id: timerCover
2021-05-16 19:37:55 +02:00
2020-03-28 12:39:53 +01:00
interval: 300
onTriggered: {
2021-08-14 13:38:24 +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-08-11 20:18:34 +02:00
function onReloadVideo ( oldType ) {
2021-08-14 13:38:24 +02:00
webView . runJavaScript ( root . getSetVideoCommand ( ) )
2020-07-18 20:21:47 +02:00
}
2019-11-23 17:22:24 +01:00
2020-03-25 21:29:01 +01:00
function onQmlExit ( ) {
2021-08-14 13:38:24 +02:00
webView . runJavaScript (
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.volume = 0;" )
2019-11-23 17:22:24 +01:00
}
2020-03-25 21:29:01 +01:00
function onMutedChanged ( muted ) {
2021-05-16 19:37:55 +02:00
if ( muted )
2021-08-14 13:38:24 +02:00
webView . runJavaScript (
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.volume = 0;" )
2021-05-16 19:37:55 +02:00
else
2021-08-14 13:38:24 +02:00
webView . runJavaScript (
"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 ) {
2021-05-16 19:37:55 +02:00
if ( webView . loadProgress === 100 )
2021-08-14 13:38:24 +02:00
webView . runJavaScript (
"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 ) {
2021-05-16 19:37:55 +02:00
if ( webView . loadProgress === 100 )
2021-08-14 13:38:24 +02:00
webView . runJavaScript (
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.loop = " + loops + ";" )
2019-11-23 17:22:24 +01:00
}
2020-03-25 21:29:01 +01:00
function onVolumeChanged ( volume ) {
2021-05-16 19:37:55 +02:00
if ( webView . loadProgress === 100 )
2021-08-14 13:38:24 +02:00
webView . runJavaScript (
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.volume = " + volume + ";" )
2019-11-23 17:22:24 +01:00
}
2020-03-25 21:29:01 +01:00
function onCurrentTimeChanged ( currentTime ) {
2021-05-16 19:37:55 +02:00
if ( webView . loadProgress === 100 )
2021-08-14 13:38:24 +02:00
webView . runJavaScript (
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.currentTime = "
+ currentTime + " * videoPlayer.duration;" )
2019-11-23 17:22:24 +01:00
}
2020-03-25 21:29:01 +01:00
function onPlaybackRateChanged ( playbackRate ) {
2021-05-16 19:37:55 +02:00
if ( webView . loadProgress === 100 )
2021-08-14 13:38:24 +02:00
webView . runJavaScript (
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.playbackRate = " + playbackRate + ";" )
2019-11-23 17:22:24 +01:00
}
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
2021-08-14 13:38:24 +02:00
timerCover . restart ( )
2020-03-28 12:39:53 +01:00
} else {
2021-08-14 13:38:24 +02:00
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 ) {
2021-05-16 19:37:55 +02:00
if ( isPlaying )
2021-08-14 13:38:24 +02:00
webView . runJavaScript (
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.play();" )
2021-05-16 19:37:55 +02:00
else
2021-08-14 13:38:24 +02:00
webView . runJavaScript (
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.pause();" )
2019-11-23 17:22:24 +01:00
}
}
2021-05-16 19:37:55 +02:00
target: Wallpaper
2019-11-23 17:22:24 +01:00
}
}