everything got fixed ?

This commit is contained in:
Soph :3 2024-08-03 04:06:32 +03:00
parent e3ef3f76c7
commit 9e907f6d77
Signed by: sophie
GPG key ID: EDA5D222A0C270F2
2 changed files with 33 additions and 35 deletions

23
main.py
View file

@ -6,15 +6,16 @@ def is_port_in_use(port: int) -> bool:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
return s.connect_ex(('localhost', port)) == 0 return s.connect_ex(('localhost', port)) == 0
def main():
if(is_port_in_use(52121)):
return
if(is_port_in_use(52121)): rpc = discordrpc.RPC(app_id="863873014587326494")
exit(1) rpc.set_activity(details="Not doing.. anything..", large_image="small")
global lastMessage;
lastMessage = 0;
rpc = discordrpc.RPC(app_id="863873014587326494") async def echo(websocket):
rpc.set_activity(details="Not doing.. anything..", large_image="small")
lastMessage = 0;
async def echo(websocket):
global lastMessage; global lastMessage;
async for message in websocket: async for message in websocket:
data = json.loads(message); data = json.loads(message);
@ -22,9 +23,8 @@ async def echo(websocket):
lastMessage = time.time() lastMessage = time.time()
async def main(): async def main2():
print("started ws") print("started ws")
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
async def heartbeatChecker(): async def heartbeatChecker():
@ -38,4 +38,7 @@ async def main():
async with await serve(echo, "localhost", 52121): async with await serve(echo, "localhost", 52121):
await asyncio.Future() await asyncio.Future()
asyncio.run(main()) asyncio.run(main2())
if __name__ == "__main__":
main()

View file

@ -3,15 +3,13 @@ import QtQml 2.0
import QtWebSockets 1.1 import QtWebSockets 1.1
Script { Script {
//socket.active
property string scriptDirPath property string scriptDirPath
property QtObject timer property QtObject timer
property QtObject delay property QtObject delay
property QtObject websocket property QtObject websocket
function init() { function init() {
script.startDetachedProcess("/usr/bin/python", [scriptDirPath + "/main.py"], 0, 0, 0, scriptDirPath); script.startDetachedProcess("/usr/bin/python3", [scriptDirPath + "/main.py"]);
} }
websocket: WebSocket { websocket: WebSocket {
@ -28,11 +26,9 @@ Script {
script.log("Open!"); script.log("Open!");
} else if (socket.status == WebSocket.Closed) { } else if (socket.status == WebSocket.Closed) {
this.active = false; this.active = false;
delay.setTimeout(() => { delay.setTimeout(() => {
socket.active = true; socket.active = true;
}, 2000); }, 2000);
script.log("Socket closed"); script.log("Socket closed");
} }
} }
@ -60,7 +56,6 @@ Script {
running: true running: true
repeat: true repeat: true
onTriggered: { onTriggered: {
script.log(websocket.active);
if (websocket.active) { if (websocket.active) {
var note = script.currentNote(); var note = script.currentNote();
websocket.sendTextMessage(JSON.stringify({ websocket.sendTextMessage(JSON.stringify({