mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-10-06 09:17:07 +02:00
Add basic working keep alive ping and quit messages
This commit is contained in:
parent
1c152bed38
commit
bf80e2eeee
@ -232,7 +232,7 @@ void ScreenPlayWallpaper::setSDKConnection(std::unique_ptr<SDKConnection> connec
|
||||
|
||||
QObject::connect(m_connection.get(), &SDKConnection::disconnected, this, [this]() {
|
||||
setIsConnected(false);
|
||||
qInfo() << "disconnecetd;";
|
||||
qInfo() << "Wallpaper:" << m_connection->appID() << "disconnected";
|
||||
});
|
||||
QTimer::singleShot(1000, this, [this]() {
|
||||
if (playbackRate() != 1.0) {
|
||||
|
@ -18,6 +18,10 @@ void ScreenPlayGodotWallpaper::_bind_methods()
|
||||
UtilityFunctions::print("ScreenPlayGodotWallpaper _bind_methods");
|
||||
ClassDB::bind_method(godot::D_METHOD("init"), &ScreenPlayGodotWallpaper::init);
|
||||
ClassDB::bind_method(godot::D_METHOD("connect_to_named_pipe"), &ScreenPlayGodotWallpaper::connect_to_named_pipe);
|
||||
ClassDB::bind_method(godot::D_METHOD("send_welcome"), &ScreenPlayGodotWallpaper::send_welcome);
|
||||
ClassDB::bind_method(godot::D_METHOD("get_screenPlayConnected"), &ScreenPlayGodotWallpaper::get_screenPlayConnected);
|
||||
ClassDB::bind_method(godot::D_METHOD("get_pipeConnected"), &ScreenPlayGodotWallpaper::get_pipeConnected);
|
||||
ClassDB::bind_method(godot::D_METHOD("ping_alive_screenplay"), &ScreenPlayGodotWallpaper::ping_alive_screenplay);
|
||||
|
||||
ClassDB::bind_method(godot::D_METHOD("get_activeScreensList"), &ScreenPlayGodotWallpaper::get_activeScreensList);
|
||||
ClassDB::bind_method(godot::D_METHOD("set_activeScreensList", "screens"), &ScreenPlayGodotWallpaper::set_activeScreensList);
|
||||
@ -77,23 +81,6 @@ ScreenPlayGodotWallpaper::~ScreenPlayGodotWallpaper()
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenPlayGodotWallpaper::_process(double delta)
|
||||
{
|
||||
|
||||
// if (!isPipeActive) {
|
||||
// return;
|
||||
// }
|
||||
// timesinceLastRead += delta;
|
||||
// // 0.05 seconds = 50ms
|
||||
// if (timesinceLastRead >= 0.05) {
|
||||
// String data = read_from_pipe();
|
||||
// if (!data.is_empty()) {
|
||||
// UtilityFunctions::print("Received data: " + data);
|
||||
// }
|
||||
// timesinceLastRead = 0.0;
|
||||
// }
|
||||
}
|
||||
|
||||
bool ScreenPlayGodotWallpaper::configureWindowGeometry()
|
||||
{
|
||||
if (!m_hook->searchWorkerWindowToParentTo()) {
|
||||
@ -168,6 +155,7 @@ bool ScreenPlayGodotWallpaper::init(int activeScreen)
|
||||
|
||||
bool ScreenPlayGodotWallpaper::connect_to_named_pipe()
|
||||
{
|
||||
m_pipeConnected = false;
|
||||
String pipeName = "ScreenPlay";
|
||||
String fullPipeName = "\\\\.\\pipe\\" + pipeName;
|
||||
std::wstring wPipeName = std::wstring(fullPipeName.wide_string());
|
||||
@ -182,14 +170,13 @@ bool ScreenPlayGodotWallpaper::connect_to_named_pipe()
|
||||
NULL);
|
||||
|
||||
if (m_hPipe == INVALID_HANDLE_VALUE) {
|
||||
m_isPipeActive = false;
|
||||
m_pipeConnected = false;
|
||||
UtilityFunctions::print("CreateFile failed, error code: " + String::num_int64(GetLastError()));
|
||||
return false;
|
||||
}
|
||||
|
||||
m_isPipeActive = true;
|
||||
|
||||
return connected_to_screenplay();
|
||||
m_pipeConnected = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
godot::String ScreenPlayGodotWallpaper::read_from_pipe()
|
||||
@ -208,9 +195,31 @@ godot::String ScreenPlayGodotWallpaper::read_from_pipe()
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ScreenPlayGodotWallpaper::connected_to_screenplay()
|
||||
bool ScreenPlayGodotWallpaper::ping_alive_screenplay()
|
||||
{
|
||||
if (m_hPipe == INVALID_HANDLE_VALUE) {
|
||||
UtilityFunctions::print("INVALID_HANDLE_VALUE");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!m_screenPlayConnected || !m_pipeConnected) {
|
||||
UtilityFunctions::print("ScreenPlay hasn't connected to us yet!");
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string message = "ping";
|
||||
DWORD bytesWritten;
|
||||
WriteFile(m_hPipe, message.c_str(), static_cast<DWORD>(message.size()), &bytesWritten, NULL);
|
||||
|
||||
if (bytesWritten != message.size()) {
|
||||
UtilityFunctions::print("Unable to send alive ping");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ScreenPlayGodotWallpaper::send_welcome()
|
||||
{
|
||||
// Ensure you have valid appID and type
|
||||
if (m_appID.is_empty()) {
|
||||
UtilityFunctions::print("Unable to connect with empty: appid");
|
||||
@ -230,6 +239,8 @@ bool ScreenPlayGodotWallpaper::connected_to_screenplay()
|
||||
return false;
|
||||
}
|
||||
|
||||
m_screenPlayConnected = true;
|
||||
// m_pingAliveTimer->start();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -266,6 +277,14 @@ void ScreenPlayGodotWallpaper::set_checkWallpaperVisible(bool visible)
|
||||
{
|
||||
m_checkWallpaperVisible = visible;
|
||||
}
|
||||
bool ScreenPlayGodotWallpaper::get_screenPlayConnected() const
|
||||
{
|
||||
return m_screenPlayConnected;
|
||||
}
|
||||
bool ScreenPlayGodotWallpaper::get_pipeConnected() const
|
||||
{
|
||||
return m_pipeConnected;
|
||||
}
|
||||
bool ScreenPlayGodotWallpaper::get_checkWallpaperVisible() const
|
||||
{
|
||||
return m_checkWallpaperVisible;
|
||||
|
@ -24,9 +24,8 @@ public:
|
||||
|
||||
bool init(int activeScreen);
|
||||
bool connect_to_named_pipe();
|
||||
bool connected_to_screenplay();
|
||||
bool send_welcome();
|
||||
godot::String read_from_pipe();
|
||||
void _process(double delta);
|
||||
void messageReceived(const std::string& key, const std::string& value);
|
||||
|
||||
godot::PackedInt64Array get_activeScreensList() const;
|
||||
@ -39,6 +38,9 @@ public:
|
||||
void set_volume(float vol);
|
||||
bool get_checkWallpaperVisible() const;
|
||||
void set_checkWallpaperVisible(bool visible);
|
||||
bool get_screenPlayConnected() const;
|
||||
bool get_pipeConnected() const;
|
||||
bool ping_alive_screenplay();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
@ -57,10 +59,10 @@ private:
|
||||
std::unique_ptr<WindowsHook> m_hook;
|
||||
HANDLE m_hPipe;
|
||||
double m_timesinceLastRead = 0.0;
|
||||
bool m_isPipeActive = false;
|
||||
bool m_pipeConnected = false;
|
||||
bool m_screenPlayConnected = false;
|
||||
|
||||
godot::PackedInt64Array m_activeScreensList;
|
||||
float m_volume = 0.0;
|
||||
bool m_checkWallpaperVisible = false;
|
||||
godot::Timer* m_pingAliveTimer = nullptr;
|
||||
};
|
||||
|
@ -2,8 +2,22 @@ extends Node3D
|
||||
|
||||
@onready var screen_play_wallpaper = $ScreenPlayGodotWallpaper
|
||||
|
||||
@onready var alive_timer = $AliveTimer
|
||||
|
||||
func ping_alive_screenplay():
|
||||
var ping_alive_screenplay = screen_play_wallpaper.ping_alive_screenplay()
|
||||
var msg = screen_play_wallpaper.read_from_pipe()
|
||||
if not msg.isEmpty():
|
||||
print("message", msg)
|
||||
if "quit" in msg:
|
||||
get_tree().quit()
|
||||
return
|
||||
|
||||
#print("ping_alive_screenplay: ", ping_alive_screenplay)
|
||||
|
||||
func _ready():
|
||||
alive_timer.timeout.connect(ping_alive_screenplay)
|
||||
|
||||
if not screen_play_wallpaper:
|
||||
printerr("ERROR INVALID SCREENPLAY OBJECT")
|
||||
return
|
||||
@ -20,12 +34,24 @@ func _ready():
|
||||
get_tree().quit()
|
||||
return
|
||||
print(path)
|
||||
if load_scene(path):
|
||||
var ok = screen_play_wallpaper.init(screen_play_wallpaper.get_activeScreensList()[0])
|
||||
print("init ", ok)
|
||||
Engine.set_max_fps(24)
|
||||
if not load_scene(path):
|
||||
print("Failed to load the PCK file.")
|
||||
get_tree().quit()
|
||||
return
|
||||
Engine.set_max_fps(24)
|
||||
var ok = screen_play_wallpaper.init(screen_play_wallpaper.get_activeScreensList()[0])
|
||||
print("init ", ok)
|
||||
if not screen_play_wallpaper.get_pipeConnected():
|
||||
print("connect to ScreenPlay")
|
||||
var ok_connect_to_named_pipe = screen_play_wallpaper.connect_to_named_pipe()
|
||||
print("connect to ScreenPlay", ok_connect_to_named_pipe)
|
||||
print("connection: ", ok_connect_to_named_pipe)
|
||||
if not screen_play_wallpaper.get_screenPlayConnected():
|
||||
print("send_welcome")
|
||||
var send_welcome = screen_play_wallpaper.send_welcome()
|
||||
print("send_welcome: ", send_welcome)
|
||||
if send_welcome:
|
||||
alive_timer.start()
|
||||
|
||||
|
||||
func load_scene(path):
|
||||
var success = ProjectSettings.load_resource_pack(path)
|
||||
|
@ -6,3 +6,6 @@
|
||||
script = ExtResource("1_ceeuk")
|
||||
|
||||
[node name="ScreenPlayGodotWallpaper" type="ScreenPlayGodotWallpaper" parent="."]
|
||||
|
||||
[node name="AliveTimer" type="Timer" parent="."]
|
||||
wait_time = 0.5
|
||||
|
@ -1,6 +1,7 @@
|
||||
#!/usr/bin/python3
|
||||
import os
|
||||
import util
|
||||
import shutil
|
||||
import defines
|
||||
from pathlib import Path
|
||||
from execute_util import execute
|
||||
@ -39,10 +40,31 @@ def build_godot(abs_build_path: str):
|
||||
apps_path = os.path.join(util.repo_root_path(),"Tools/Apps/Godot")
|
||||
godot_executable = os.path.join(apps_path, defines.GODOT_EDITOR_EXECUTABLE)
|
||||
screenPlayWallpaperGodot_executable = Path(abs_build_path).joinpath(defines.SCREENPLAYWALLPAPER_GODOT_EXECUTABLE).resolve()
|
||||
export_command = f'"{godot_executable}" -v --headless --export-release "Windows Desktop" "{screenPlayWallpaperGodot_executable}"'
|
||||
|
||||
if 'Debug' in abs_build_path:
|
||||
export_type = " --export-debug"
|
||||
else:
|
||||
export_type = " --export-release"
|
||||
export_command = f'"{godot_executable}" -v --headless {export_type} "Windows Desktop" "{screenPlayWallpaperGodot_executable}"'
|
||||
|
||||
# We get random error on successful export, so lets ignore it
|
||||
execute(command=export_command,workingDir=project_path,ignore_error=True)
|
||||
|
||||
if 'Debug' in abs_build_path:
|
||||
lib_name = "ScreenPlayGodotWallpaper-d.dll"
|
||||
else:
|
||||
lib_name = "ScreenPlayGodotWallpaper.dll"
|
||||
|
||||
# Construct the source path for the DLL
|
||||
dll_source_path = project_path.joinpath(f"ScreenPlayGodotWallpaper/lib/Windows-AMD64/{lib_name}")
|
||||
|
||||
# Print a warning message
|
||||
print(f"⚠️ Copying {dll_source_path} to {abs_build_path}")
|
||||
|
||||
# Copy the DLL
|
||||
shutil.copy(dll_source_path, abs_build_path)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user