Add "timeout" command.
This commit is contained in:
@@ -3,9 +3,10 @@ const
|
||||
defaultPort* = 5555 ## Default port at which the control server will run
|
||||
|
||||
type
|
||||
Command* {.pure.} = enum
|
||||
Close = "close" ## Closes the control server and exists the applicaiton
|
||||
Refresh = "refresh" ## Force refresh of the image now
|
||||
Command* = enum
|
||||
cClose = "close" ## Closes the control server and exists the applicaiton
|
||||
cRefresh = "refresh" ## Force refresh of the image now
|
||||
cTimeout = "timeout" ## Set image timeout to a new value
|
||||
|
||||
CommandMessage* = object
|
||||
command*: Command ## Command that the application should execute
|
||||
|
||||
@@ -15,8 +15,15 @@ var p = newParser("pixctrl"):
|
||||
option("-s", "--server", help="Host running the randopix server", default="127.0.0.1")
|
||||
option("-p", "--port", help="Port to connect to the randopix server", default = $defaultPort)
|
||||
command("refresh"):
|
||||
help("Force image refresh now")
|
||||
run:
|
||||
let c = newCommand(Command.Refresh)
|
||||
let c = newCommand(cRefresh)
|
||||
sendCommand(opts.parentOpts.server, opts.parentOpts.port, c)
|
||||
command("timeout"):
|
||||
help("Set timeout in seconds before a new image is displayed")
|
||||
arg("seconds", default = "300")
|
||||
run:
|
||||
let c = newCommand(cTimeout, opts.seconds)
|
||||
sendCommand(opts.parentOpts.server, opts.parentOpts.port, c)
|
||||
|
||||
p.run(commandLineParams())
|
||||
@@ -11,7 +11,7 @@ const
|
||||
version = "0.1"
|
||||
|
||||
type
|
||||
Args = object
|
||||
Args = ref object
|
||||
fullscreen: bool ## Applicaion is show in fullscreen mode
|
||||
verbose: bool ## More debug information in notification label
|
||||
timeout: int ## Milliseconds between image refreshes
|
||||
@@ -43,7 +43,7 @@ proc newArgs(): Option[Args] =
|
||||
let p = newParser("randopix"):
|
||||
help(fmt"Version {version} - Display random images from different sources")
|
||||
option("-m", "--mode", help="The image source mode.", choices=enumToStrings(ProviderKind))
|
||||
option("-p", "--path", help="Path to a directory with images ('file' mode only)")
|
||||
option("-p", "--path", help="Path to a directory with images for the 'file' mode")
|
||||
option("-t", "--timeout", help="Seconds before the image is refreshed", default="300")
|
||||
flag("-w", "--windowed", help="Do not start in fullscreen mode")
|
||||
flag("-v", "--verbose", help="Show more information")
|
||||
@@ -124,10 +124,14 @@ proc checkServerChannel(parameter: string): bool =
|
||||
echo "Main app got message: ", msg.command
|
||||
|
||||
case msg.command
|
||||
of Command.Refresh:
|
||||
of cRefresh:
|
||||
discard updateImage()
|
||||
of cTimeout:
|
||||
let val = msg.parameter.parseInt * 1000
|
||||
echo "Setting timeout to ", val
|
||||
args.timeout = val
|
||||
else:
|
||||
echo "Command ignored", msg.command
|
||||
echo "Command ignored: ", msg.command
|
||||
|
||||
sleep(100)
|
||||
result = false
|
||||
|
||||
@@ -8,7 +8,7 @@ proc closeServer*() =
|
||||
## Sends a "Close" command to the server
|
||||
var socket = newSocket()
|
||||
socket.connect("127.0.0.1", Port(defaultPort))
|
||||
let c = newCommand(Command.Close)
|
||||
let c = newCommand(cClose)
|
||||
socket.send(c.wrap)
|
||||
socket.close()
|
||||
|
||||
@@ -32,7 +32,7 @@ proc runServer*() =
|
||||
var jsonData = parseJson(line)
|
||||
let msg = jsonData.to(CommandMessage)
|
||||
case msg.command
|
||||
of Command.Close:
|
||||
of cClose:
|
||||
echo "Server recieved termination command. Exiting."
|
||||
break
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user