mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-11-06 19:12:30 +01:00
Refactor KDE plugin to work at any state...
... ScreenPlay no longer needs to run before the wallpaper. This paves the way to start the wallpaper from QSettings even when the main application is not running. Add quit command and action
This commit is contained in:
parent
b6b134a81b
commit
e6272e0db5
@ -83,7 +83,8 @@ void ScreenPlayManager::init(
|
||||
|
||||
if (m_settings->desktopEnvironment() == Settings::DesktopEnvironment::KDE) {
|
||||
m_websocketServer = std::make_unique<QWebSocketServer>(QStringLiteral("ScreenPlayWebSocket"), QWebSocketServer::SslMode::NonSecureMode);
|
||||
m_websocketServer->listen(QHostAddress::Any, m_webSocketPort);
|
||||
const bool success = m_websocketServer->listen(QHostAddress::Any, m_webSocketPort);
|
||||
qInfo() << "Open Websocket:" << success << "port:" <<m_webSocketPort;
|
||||
QObject::connect(m_websocketServer.get(), &QWebSocketServer::newConnection, this, [this]() {
|
||||
qInfo() << "New Websocket Connection";
|
||||
auto* socket = m_websocketServer->nextPendingConnection();
|
||||
@ -97,7 +98,7 @@ void ScreenPlayManager::init(
|
||||
|
||||
|
||||
m_connections.push_back(socket);
|
||||
socket->flush();
|
||||
// socket->flush();
|
||||
});
|
||||
}
|
||||
|
||||
@ -127,6 +128,7 @@ bool ScreenPlayManager::createWallpaper(
|
||||
const QJsonObject& properties,
|
||||
const bool saveToProfilesConfigFile)
|
||||
{
|
||||
|
||||
const int screenCount = QGuiApplication::screens().count();
|
||||
|
||||
QJsonArray monitors;
|
||||
@ -283,6 +285,16 @@ bool ScreenPlayManager::removeAllWallpapers()
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(m_settings->desktopEnvironment() == Settings::DesktopEnvironment::KDE){
|
||||
for(auto& connection : m_connections){
|
||||
QJsonObject obj;
|
||||
obj.insert("command", "quit");
|
||||
connection->sendTextMessage(QJsonDocument(obj).toJson(QJsonDocument::Compact));
|
||||
connection->flush();
|
||||
connection->close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
emit requestSaveProfiles();
|
||||
|
||||
@ -456,6 +468,8 @@ bool ScreenPlayManager::removeWallpaper(const QString& appID)
|
||||
if (wallpaper->appID() != appID) {
|
||||
return false;
|
||||
}
|
||||
if(m_settings->desktopEnvironment() == Settings::DesktopEnvironment::Windows ||
|
||||
m_settings->desktopEnvironment() == Settings::DesktopEnvironment::OSX)
|
||||
wallpaper->messageQuit();
|
||||
|
||||
qInfo() << "Remove wallpaper " << wallpaper->file() << "at monitor " << wallpaper->screenNumber();
|
||||
|
@ -3,6 +3,7 @@ import QtQuick.Controls 2.12
|
||||
import QtWebSockets 1.1
|
||||
import QtWebEngine 1.8
|
||||
import QtMultimedia 5.12
|
||||
import Qt.labs.settings 1.1
|
||||
|
||||
|
||||
Rectangle {
|
||||
@ -17,14 +18,38 @@ Rectangle {
|
||||
property string projectSourceFileAbsolute
|
||||
property bool loops: true
|
||||
|
||||
function stop(){
|
||||
player1.stop()
|
||||
player2.stop()
|
||||
videoOutput1.visible = false
|
||||
videoOutput2.visible = false
|
||||
root.enabled = false
|
||||
}
|
||||
|
||||
function play(){
|
||||
root.enabled = true
|
||||
videoOutput2.visible = false
|
||||
videoOutput1.visible = true
|
||||
|
||||
//if(wallpaper.configuration.DualPlayback){
|
||||
player2.source = root.projectSourceFileAbsolute
|
||||
player2.play()
|
||||
player2.pause()
|
||||
//}
|
||||
player1.play()
|
||||
}
|
||||
|
||||
MediaPlayer {
|
||||
id: player1
|
||||
volume: root.volume
|
||||
source: root.projectSourceFileAbsolute
|
||||
onStopped: {
|
||||
if(!root.enabled)
|
||||
return
|
||||
|
||||
videoOutput1.visible = false
|
||||
videoOutput2.visible = true
|
||||
if(player2.source != root.projectSourceFileAbsolute){
|
||||
if(player2.source !== root.projectSourceFileAbsolute){
|
||||
player2.source = root.projectSourceFileAbsolute
|
||||
}
|
||||
player1.play()
|
||||
@ -37,6 +62,8 @@ Rectangle {
|
||||
id: player2
|
||||
volume: root.volume
|
||||
onStopped: {
|
||||
if(!root.enabled)
|
||||
return
|
||||
videoOutput2.visible = false
|
||||
videoOutput1.visible = true
|
||||
player2.play()
|
||||
@ -60,51 +87,6 @@ Rectangle {
|
||||
source: player2
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
print("test")
|
||||
}
|
||||
|
||||
WebSocket {
|
||||
id: socket
|
||||
|
||||
url: "ws://127.0.0.1:16395"
|
||||
active: true
|
||||
onStatusChanged: {
|
||||
if (socket.status === WebSocket.Open)
|
||||
socket.sendTextMessage("Hello World from QML wallpaper")
|
||||
}
|
||||
|
||||
onTextMessageReceived: (message)=> {
|
||||
socket.sendTextMessage(message)
|
||||
print(message)
|
||||
|
||||
var obj = JSON.parse(message)
|
||||
wp.connected = true
|
||||
|
||||
if (obj.command === "replace") {
|
||||
socket.sendTextMessage("replace")
|
||||
root.type = obj.type
|
||||
root.fillMode = obj.fillMode
|
||||
root.volume = obj.volume
|
||||
root.projectSourceFileAbsolute = "file://" + obj.absolutePath + "/" + obj.file
|
||||
print("got: " + root.projectSourceFileAbsolute)
|
||||
//mediaplayer.source = root.projectSourceFileAbsolute
|
||||
//mediaplayer.play()
|
||||
//videplayer.source = root.projectSourceFileAbsolute
|
||||
//playlist.addItem(root.projectSourceFileAbsolute)
|
||||
//playlist.addItem(root.projectSourceFileAbsolute)
|
||||
//videplayer.play()
|
||||
|
||||
videoOutput2.visible = false
|
||||
videoOutput1.visible = true
|
||||
|
||||
//if(wallpaper.configuration.DualPlayback){
|
||||
player2.source = root.projectSourceFileAbsolute
|
||||
player2.play()
|
||||
player2.pause()
|
||||
//}
|
||||
player1.play()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,114 @@
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Window 2.15
|
||||
import QtQuick 2.0
|
||||
import QtQuick.Controls 2.12
|
||||
import QtWebSockets 1.1
|
||||
import QtWebEngine 1.8
|
||||
import QtMultimedia 5.12
|
||||
import Qt.labs.settings 1.1
|
||||
|
||||
|
||||
WallpaperContainer {
|
||||
Rectangle {
|
||||
id:root
|
||||
color:"orange"
|
||||
property bool connected: false
|
||||
|
||||
Settings {
|
||||
id:settings
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
wallpaper.projectSourceFileAbsolute = settings.value("SP_projectSourceFileAbsolute","NULL")
|
||||
// if(root.projectSourceFileAbsolute === "NULL")
|
||||
// return
|
||||
|
||||
wallpaper.type = settings.value("SP_type")
|
||||
wallpaper.fillMode = settings.value("SP_fillMode")
|
||||
wallpaper.volume = settings.value("SP_volume")
|
||||
wallpaper.play()
|
||||
}
|
||||
|
||||
|
||||
Wallpaper {
|
||||
id:wallpaper
|
||||
anchors.fill: parent
|
||||
// visible: root.connected
|
||||
|
||||
onFullContentPathChanged: settings.setValue("SP_fullContentPath",fullContentPath)
|
||||
onVolumeChanged: settings.setValue("SP_volume",volume)
|
||||
onFillModeChanged: settings.setValue("SP_fillMode",fillMode)
|
||||
onTypeChanged: settings.setValue("SP_type",type)
|
||||
onProjectSourceFileAbsoluteChanged: settings.setValue("SP_projectSourceFileAbsolute",projectSourceFileAbsolute)
|
||||
onLoopsChanged: settings.setValue("SP_loops",loops)
|
||||
|
||||
}
|
||||
|
||||
Timer {
|
||||
id:reconnectTimer
|
||||
interval: 1000
|
||||
running: true
|
||||
repeat: true
|
||||
onTriggered: {
|
||||
if (socket.status === WebSocket.Open)
|
||||
return
|
||||
socket.active = false
|
||||
socket.active = true
|
||||
reconnectTimer.retryCounter += 1
|
||||
}
|
||||
property int retryCounter: 0
|
||||
}
|
||||
|
||||
WebSocket {
|
||||
id: socket
|
||||
url: "ws://127.0.0.1:16395"
|
||||
onStatusChanged: {
|
||||
if (socket.status === WebSocket.Open)
|
||||
socket.sendTextMessage("Hello World from QML wallpaper")
|
||||
}
|
||||
|
||||
onTextMessageReceived: (message)=> {
|
||||
|
||||
var obj = JSON.parse(message)
|
||||
root.connected = true
|
||||
txtCommand.text = obj.command
|
||||
|
||||
if (obj.command === "replace") {
|
||||
socket.sendTextMessage("replace")
|
||||
wallpaper.type = obj.type
|
||||
wallpaper.fillMode = obj.fillMode
|
||||
wallpaper.volume = obj.volume
|
||||
wallpaper.projectSourceFileAbsolute = "file://" + obj.absolutePath + "/" + obj.file
|
||||
print("got: " + root.projectSourceFileAbsolute)
|
||||
wallpaper.play()
|
||||
return;
|
||||
}
|
||||
if(obj.command === "quit"){
|
||||
wallpaper.stop()
|
||||
}
|
||||
}
|
||||
}
|
||||
// WaitingForScreenplay {
|
||||
// anchors.fill: parent
|
||||
// visible: !root.connected
|
||||
// }
|
||||
Column {
|
||||
anchors {
|
||||
horizontalCenter: parent.horizontalCenter
|
||||
bottom: parent.bottom
|
||||
margins: 60
|
||||
}
|
||||
Text {
|
||||
id:txtCommand
|
||||
color: "white"
|
||||
}
|
||||
Text {
|
||||
color: "white"
|
||||
text:wallpaper.type + wallpaper.projectSourceFileAbsolute
|
||||
}
|
||||
Text {
|
||||
color: "white"
|
||||
text:"Actitve: " +socket.active +" status: "+ socket.status + " reconnectTimer.retryCounter : "+ reconnectTimer.retryCounter
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -92,6 +92,6 @@ if(APPLE)
|
||||
else()
|
||||
if(${SCREENPLAY_STEAM})
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/steam_appid.txt ${CMAKE_BINARY_DIR}/bin/steam_appid.txt COPYONLY)
|
||||
endif()
|
||||
configure_file(${STEAM_BIN} ${CMAKE_BINARY_DIR}/bin/ COPYONLY)
|
||||
endif()
|
||||
endif()
|
||||
|
Loading…
Reference in New Issue
Block a user