feat(screenshot): capture authentic about system and fastfetch window
This commit is contained in:
1 parent
feddc61aaa
commit
71053feaf8
2 files changed
+80
-15
No files matched your search
+65
-11
@@ -4,6 +4,18 @@ import time
|
||||
import socket
|
||||
import json
|
||||
|
||||
def qmp_execute(sock_path, cmd_dict):
|
||||
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
s.settimeout(10)
|
||||
s.connect(sock_path)
|
||||
s.recv(4096) # Greeting
|
||||
s.sendall(json.dumps({"execute": "qmp_capabilities"}).encode() + b"\n")
|
||||
s.recv(4096) # Ack
|
||||
s.sendall(json.dumps(cmd_dict).encode() + b"\n")
|
||||
resp = s.recv(4096)
|
||||
s.close()
|
||||
return resp
|
||||
|
||||
def qmp_send_keys(sock_path, key_names):
|
||||
try:
|
||||
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
@@ -16,24 +28,61 @@ def qmp_send_keys(sock_path, key_names):
|
||||
cmd = json.dumps({"execute": "send-key", "arguments": {"keys": [{"type": "qcode", "data": k}]}})
|
||||
s.sendall(cmd.encode() + b"\n")
|
||||
s.recv(4096)
|
||||
time.sleep(0.1)
|
||||
time.sleep(0.08)
|
||||
s.close()
|
||||
print(f"Sent keys {key_names} successfully.")
|
||||
except Exception as e:
|
||||
print(f"Failed to send keys: {e}")
|
||||
|
||||
def qmp_send_combo(sock_path, combo_keys):
|
||||
try:
|
||||
keys_payload = [{"type": "qcode", "data": k} for k in combo_keys]
|
||||
cmd = {"execute": "send-key", "arguments": {"keys": keys_payload}}
|
||||
qmp_execute(sock_path, cmd)
|
||||
print(f"Sent combo {combo_keys} successfully.")
|
||||
except Exception as e:
|
||||
print(f"Failed to send combo {combo_keys}: {e}")
|
||||
|
||||
def qmp_type_string(sock_path, text):
|
||||
try:
|
||||
for ch in text:
|
||||
if ch == ' ':
|
||||
qmp_send_keys(sock_path, ['spc'])
|
||||
elif ch == '\n':
|
||||
qmp_send_keys(sock_path, ['ret'])
|
||||
elif ch == '-':
|
||||
qmp_send_keys(sock_path, ['minus'])
|
||||
else:
|
||||
qmp_send_keys(sock_path, [ch.lower()])
|
||||
time.sleep(0.05)
|
||||
print(f"Typed string '{text}' successfully.")
|
||||
except Exception as e:
|
||||
print(f"Failed to type string: {e}")
|
||||
|
||||
def qmp_open_about_terminal(sock_path):
|
||||
try:
|
||||
print("Opening Application / Terminal for About System...")
|
||||
# 1. First try KRunner (Alt+F2)
|
||||
qmp_send_combo(sock_path, ["alt", "f2"])
|
||||
time.sleep(1.5)
|
||||
qmp_type_string(sock_path, "konsole\n")
|
||||
time.sleep(4)
|
||||
|
||||
# 2. Also try standard shortcut Ctrl+Alt+T
|
||||
qmp_send_combo(sock_path, ["ctrl", "alt", "t"])
|
||||
time.sleep(3)
|
||||
|
||||
# 3. Type fastfetch in Konsole terminal
|
||||
qmp_type_string(sock_path, "fastfetch\n")
|
||||
time.sleep(4)
|
||||
print("Executed fastfetch command in live terminal.")
|
||||
except Exception as e:
|
||||
print(f"Failed to open About system: {e}")
|
||||
|
||||
def qmp_screendump(sock_path, out_file):
|
||||
try:
|
||||
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
s.settimeout(10)
|
||||
s.connect(sock_path)
|
||||
s.recv(4096) # QMP greeting
|
||||
s.sendall(json.dumps({"execute": "qmp_capabilities"}).encode() + b"\n")
|
||||
s.recv(4096) # Capabilities accepted
|
||||
cmd = json.dumps({"execute": "screendump", "arguments": {"filename": out_file}})
|
||||
s.sendall(cmd.encode() + b"\n")
|
||||
s.recv(4096) # Screendump completed
|
||||
s.close()
|
||||
cmd = {"execute": "screendump", "arguments": {"filename": out_file}}
|
||||
qmp_execute(sock_path, cmd)
|
||||
print(f"Successfully captured screenshot to: {out_file}")
|
||||
except Exception as e:
|
||||
print(f"Failed to capture {out_file}: {e}")
|
||||
@@ -50,5 +99,10 @@ if __name__ == "__main__":
|
||||
qmp_send_keys(sock, ["a", "i", "r", "l", "y", "s", "ret"])
|
||||
elif arg == "start" or arg == "super":
|
||||
qmp_send_keys(sock, ["meta_l"])
|
||||
elif arg == "esc":
|
||||
qmp_send_keys(sock, ["esc"])
|
||||
elif arg == "about":
|
||||
qmp_open_about_terminal(sock)
|
||||
else:
|
||||
qmp_screendump(sock, arg)
|
||||
|
||||
Reference in new issue
Block a user