2021-10-23 10:35:15 +02:00
import QtQuick
import QtWebEngine
2022-05-05 13:02:54 +02:00
import ScreenPlay . Enums . InstalledType
import ScreenPlayWallpaper
2021-10-23 10:35:15 +02:00
/ * !
* The native macOS multimedia stack does not support VP8 / VP9 . For this we must use the WebEngine .
* /
Item {
id: root
2021-11-01 18:25:46 +01:00
signal requestFadeIn
2021-10-23 10:35:15 +02:00
function getSetVideoCommand ( ) {
// TODO 30:
// Currently wont work. Commit anyways til QtCreator and Qt work with js template literals
2023-02-02 15:25:26 +01: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();" ;
print ( src ) ;
return src ;
2021-10-23 10:35:15 +02:00
}
Component.onCompleted: {
2023-02-02 15:25:26 +01: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 ;
2021-10-23 10:35:15 +02:00
}
WebEngineView {
id: webView
anchors.fill: parent
2023-02-02 15:25:26 +01:00
url: Qt . resolvedUrl ( "file://" + Wallpaper . getApplicationPath ( ) + "/index.html" )
2022-01-20 16:37:07 +01:00
onJavaScriptConsoleMessage: function ( lineNumber , message ) {
2023-02-02 15:25:26 +01:00
print ( lineNumber , message ) ;
2022-01-20 16:37:07 +01:00
}
2021-10-23 10:35:15 +02:00
onLoadProgressChanged: {
if ( loadProgress === 100 ) {
2023-02-02 15:25:26 +01:00
webView . runJavaScript ( root . getSetVideoCommand ( ) , function ( result ) {
requestFadeIn ( ) ;
} ) ;
2021-10-23 10:35:15 +02: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
visible: false
horizontalAlignment: Text . AlignHCenter
verticalAlignment: Text . AlignVCenter
wrapMode: Text . WrapAtWordBoundaryOrAnywhere
anchors.centerIn: parent
width: parent . width * 0.8
color: "white"
}
Timer {
id: timerCover
interval: 300
onTriggered: {
2023-02-02 15:25:26 +01:00
webView . visible = ! Wallpaper . visualsPaused ;
txtVisualsPaused . visible = Wallpaper . visualsPaused ;
2021-10-23 10:35:15 +02:00
}
}
Connections {
function onReloadVideo ( oldType ) {
2023-02-02 15:25:26 +01:00
webView . runJavaScript ( root . getSetVideoCommand ( ) ) ;
2021-10-23 10:35:15 +02:00
}
function onQmlExit ( ) {
2023-02-02 15:25:26 +01:00
webView . runJavaScript ( "var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.volume = 0;" ) ;
2021-10-23 10:35:15 +02:00
}
function onMutedChanged ( muted ) {
if ( muted )
2023-02-02 15:25:26 +01:00
webView . runJavaScript ( "var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.volume = 0;" ) ;
2021-10-23 10:35:15 +02:00
else
2023-02-02 15:25:26 +01:00
webView . runJavaScript ( "var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.volume = " + Wallpaper . volume + ";" ) ;
2021-10-23 10:35:15 +02:00
}
function onFillModeChanged ( fillMode ) {
if ( webView . loadProgress === 100 )
2023-02-02 15:25:26 +01:00
webView . runJavaScript ( "var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.setAttribute('style', 'object-fit :" + fillMode + ";');" ) ;
2021-10-23 10:35:15 +02:00
}
function onLoopsChanged ( loops ) {
if ( webView . loadProgress === 100 )
2023-02-02 15:25:26 +01:00
webView . runJavaScript ( "var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.loop = " + loops + ";" ) ;
2021-10-23 10:35:15 +02:00
}
function onVolumeChanged ( volume ) {
if ( webView . loadProgress === 100 )
2023-02-02 15:25:26 +01:00
webView . runJavaScript ( "var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.volume = " + volume + ";" ) ;
2021-10-23 10:35:15 +02:00
}
function onCurrentTimeChanged ( currentTime ) {
if ( webView . loadProgress === 100 )
2023-02-02 15:25:26 +01:00
webView . runJavaScript ( "var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.currentTime = " + currentTime + " * videoPlayer.duration;" ) ;
2021-10-23 10:35:15 +02:00
}
function onPlaybackRateChanged ( playbackRate ) {
if ( webView . loadProgress === 100 )
2023-02-02 15:25:26 +01:00
webView . runJavaScript ( "var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.playbackRate = " + playbackRate + ";" ) ;
2021-10-23 10:35:15 +02:00
}
function onVisualsPausedChanged ( visualsPaused ) {
if ( visualsPaused ) {
// Wait until Wallpaper animation is finsihed
2023-02-02 15:25:26 +01:00
timerCover . restart ( ) ;
2021-10-23 10:35:15 +02:00
} else {
2023-02-02 15:25:26 +01:00
webView . visible = true ;
txtVisualsPaused . visible = false ;
2021-10-23 10:35:15 +02:00
}
}
function onIsPlayingChanged ( isPlaying ) {
if ( webView . loadProgress === 100 ) {
if ( isPlaying )
2023-02-02 15:25:26 +01:00
webView . runJavaScript ( "var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.play();" ) ;
2021-10-23 10:35:15 +02:00
else
2023-02-02 15:25:26 +01:00
webView . runJavaScript ( "var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.pause();" ) ;
2021-10-23 10:35:15 +02:00
}
}
target: Wallpaper
}
}