Refresh and timeout commands reset the timer.
This commit is contained in:
@@ -17,6 +17,7 @@ type
|
|||||||
var
|
var
|
||||||
imageProvider: ImageProvider ## Gets images from the chosen source
|
imageProvider: ImageProvider ## Gets images from the chosen source
|
||||||
args: Args ## The parsed command line args
|
args: Args ## The parsed command line args
|
||||||
|
updateTimeout: int ## ID of the timeout that updates the images
|
||||||
# Widgets
|
# Widgets
|
||||||
window: ApplicationWindow
|
window: ApplicationWindow
|
||||||
label: Label
|
label: Label
|
||||||
@@ -89,18 +90,21 @@ proc updateImage(image: Image): bool =
|
|||||||
log "Got exception ", repr(e), " with message ", msg
|
log "Got exception ", repr(e), " with message ", msg
|
||||||
return false
|
return false
|
||||||
|
|
||||||
proc forceUpdate(action: SimpleAction; parameter: Variant; image: Image) =
|
|
||||||
discard updateImage(image)
|
|
||||||
|
|
||||||
proc timedUpdate(image: Image): bool =
|
proc timedUpdate(image: Image): bool =
|
||||||
let ok = updateImage(image);
|
let ok = updateImage(image);
|
||||||
if not ok:
|
if not ok:
|
||||||
label.notify "Error while refreshing image, retrying..."
|
label.notify "Error while refreshing image, retrying..."
|
||||||
else:
|
else:
|
||||||
label.notify
|
label.notify
|
||||||
discard timeoutAdd(uint32(args.timeout), timedUpdate, image)
|
updateTimeout = int(timeoutAdd(uint32(args.timeout), timedUpdate, image))
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
proc forceUpdate(action: SimpleAction; parameter: Variant; image: Image): void =
|
||||||
|
log "Force refreshing image now"
|
||||||
|
if updateTimeout > 0:
|
||||||
|
discard updateTimeout.remove
|
||||||
|
discard image.timedUpdate()
|
||||||
|
|
||||||
proc checkServerChannel(image: Image): bool =
|
proc checkServerChannel(image: Image): bool =
|
||||||
## Check the channel from the control server for incomming commands
|
## Check the channel from the control server for incomming commands
|
||||||
let tried = chan.tryRecv()
|
let tried = chan.tryRecv()
|
||||||
@@ -111,11 +115,13 @@ proc checkServerChannel(image: Image): bool =
|
|||||||
|
|
||||||
case msg.command
|
case msg.command
|
||||||
of cRefresh:
|
of cRefresh:
|
||||||
discard updateImage(image)
|
forceUpdate(nil, nil, image)
|
||||||
of cTimeout:
|
of cTimeout:
|
||||||
let val = msg.parameter.parseInt * 1000
|
let val = msg.parameter.parseInt * 1000
|
||||||
log "Setting timeout to ", val
|
log "Setting timeout to ", val
|
||||||
args.timeout = val
|
args.timeout = val
|
||||||
|
discard updateTimeout.remove
|
||||||
|
updateTimeout = int(timeoutAdd(uint32(args.timeout), timedUpdate, image))
|
||||||
else:
|
else:
|
||||||
log "Command ignored: ", msg.command
|
log "Command ignored: ", msg.command
|
||||||
|
|
||||||
@@ -197,8 +203,8 @@ proc appActivate(app: Application) =
|
|||||||
|
|
||||||
window.showAll
|
window.showAll
|
||||||
|
|
||||||
var timerId = timeoutAdd(500, timedUpdate, image)
|
# Setting the inital image
|
||||||
|
forceUpdate(nil, nil, image)
|
||||||
## open communication channel from the control server
|
## open communication channel from the control server
|
||||||
chan.open()
|
chan.open()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user