[ui] TextFileViewer: wait for request completion before sending a new one

On auto-realod mode, only trigger a new request when the last one has been completed. Avoids requests loops on slow filesystems that can lead to UI freezes.
This commit is contained in:
Yann Lanthony 2019-07-08 20:04:22 +02:00
parent 88b0297660
commit 52361d0b86
No known key found for this signature in database
GPG key ID: 519FAE6DF7A70642

View file

@ -22,6 +22,7 @@ Item {
property bool loading: false property bool loading: false
onSourceChanged: loadSource() onSourceChanged: loadSource()
onAutoReloadChanged: loadSource()
onVisibleChanged: if(visible) loadSource() onVisibleChanged: if(visible) loadSource()
RowLayout { RowLayout {
@ -307,11 +308,10 @@ Item {
// Auto-reload current file timer // Auto-reload current file timer
Timer { Timer {
id: reloadTimer
running: root.autoReload running: root.autoReload
interval: root.autoReloadInterval interval: root.autoReloadInterval
repeat: true repeat: false // timer is restarted in request's callback (see loadSource)
// reload file on start and stop
onRunningChanged: loadSource()
onTriggered: loadSource() onTriggered: loadSource()
} }
@ -333,6 +333,9 @@ Item {
if(xhr.readyState === XMLHttpRequest.DONE) { if(xhr.readyState === XMLHttpRequest.DONE) {
textView.setText(xhr.status === 200 ? xhr.responseText : ""); textView.setText(xhr.status === 200 ? xhr.responseText : "");
loading = false; loading = false;
// re-trigger reload source file
if(autoReload)
reloadTimer.restart();
} }
}; };
xhr.send(); xhr.send();