autoreconnect
This commit is contained in:
parent
0480c2ddd0
commit
e3ef3f76c7
51
main.qml
51
main.qml
|
@ -3,10 +3,17 @@ 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 websocket
|
property QtObject websocket
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
script.startDetachedProcess("/usr/bin/python", [scriptDirPath + "/main.py"], 0, 0, 0, scriptDirPath);
|
||||||
|
}
|
||||||
|
|
||||||
websocket: WebSocket {
|
websocket: WebSocket {
|
||||||
id: socket
|
id: socket
|
||||||
|
|
||||||
|
@ -15,18 +22,37 @@ Script {
|
||||||
script.log("Received message: " + message);
|
script.log("Received message: " + message);
|
||||||
}
|
}
|
||||||
onStatusChanged: {
|
onStatusChanged: {
|
||||||
if (socket.status == WebSocket.Error)
|
if (socket.status == WebSocket.Error) {
|
||||||
script.log("Error: " + socket.errorString);
|
script.log("Error: " + socket.errorString);
|
||||||
else if (socket.status == WebSocket.Open)
|
} else if (socket.status == WebSocket.Open) {
|
||||||
script.log("Open!");
|
script.log("Open!");
|
||||||
else if (socket.status == WebSocket.Closed)
|
} else if (socket.status == WebSocket.Closed) {
|
||||||
|
this.active = false;
|
||||||
|
|
||||||
|
delay.setTimeout(() => {
|
||||||
|
socket.active = true;
|
||||||
|
}, 2000);
|
||||||
|
|
||||||
script.log("Socket closed");
|
script.log("Socket closed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
active: true
|
active: true
|
||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
delay: Timer {
|
||||||
script.startDetachedProcess("/usr/bin/python", [scriptDirPath + "/main.py"], 0, 0, 0, scriptDirPath);
|
id: timer
|
||||||
|
|
||||||
|
function setTimeout(cb, delayTime) {
|
||||||
|
timer.interval = delayTime;
|
||||||
|
timer.repeat = false;
|
||||||
|
timer.triggered.connect(cb);
|
||||||
|
timer.triggered.connect(function release() {
|
||||||
|
timer.triggered.disconnect(cb);
|
||||||
|
timer.triggered.disconnect(release);
|
||||||
|
});
|
||||||
|
timer.start();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
timer: Timer {
|
timer: Timer {
|
||||||
|
@ -34,13 +60,14 @@ Script {
|
||||||
running: true
|
running: true
|
||||||
repeat: true
|
repeat: true
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
var note = script.currentNote();
|
script.log(websocket.active);
|
||||||
|
if (websocket.active) {
|
||||||
websocket.sendTextMessage(JSON.stringify({
|
var note = script.currentNote();
|
||||||
name: note.name,
|
websocket.sendTextMessage(JSON.stringify({
|
||||||
cursorPosition: script.noteTextEditCursorPosition(),
|
"name": note.name,
|
||||||
|
"cursorPosition": script.noteTextEditCursorPosition()
|
||||||
}))
|
}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue