From f650c3296b1ffdcf538cc5ffa690408282c5868c Mon Sep 17 00:00:00 2001 From: Icedream Jenkins Date: Mon, 2 Nov 2015 12:18:36 +0100 Subject: [PATCH] Make xdotool optional. --- require_bin.iced | 12 +++++++++--- x11.iced | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/require_bin.iced b/require_bin.iced index 66158f2..1a6a77f 100644 --- a/require_bin.iced +++ b/require_bin.iced @@ -2,7 +2,9 @@ which = require("which").sync path = require "path" log = require("./logger")("RequireBin") -module.exports = (binName) => +module.exports = (binName, doErrorIfNotFound) => + doErrorIfNotFound = true unless doErrorIfNotFound? + # check if xvfb is findable from here if path.resolve(binName) == path.normalize(binName) # this is an absolute path @@ -14,5 +16,9 @@ module.exports = (binName) => log.debug "#{binName} detected:", binPath return binPath catch err - log.error "#{binName} could not be found.", err - throw new Error "#{binName} could not be found." + if doErrorIfNotFound + log.error "#{binName} could not be found." + throw new Error "#{binName} could not be found." + else + log.warn "#{binName} could not be found." + return null diff --git a/x11.iced b/x11.iced index c679dca..05ce1f1 100644 --- a/x11.iced +++ b/x11.iced @@ -6,13 +6,18 @@ services = require("./services") StreamSplitter = require("stream-splitter") require_bin = require("./require_bin") -xdotoolBinPath = require_bin "xdotool" +xdotoolBinPath = require_bin "xdotool", false # Just some tools to work with the X11 windows module.exports = getWindowIdByProcessId: (pid, cb) => wid = null + # Return null instantly if xdotool is not available + if not xdotoolBinPath? + cb? new Error "xdotool is not available" + return + # We provide --name due to the bug mentioned at https://github.com/jordansissel/xdotool/issues/14 xdoproc = spawn xdotoolBinPath, [ "search", "--any", "--pid", pid, "--name", "xdosearch" ], env: @@ -43,6 +48,11 @@ module.exports = getWindowIdByProcessIdSync: (pid) => Sync() => @getWindowIdByProcessId.sync @, pid sendKeys: (wid, keys, cb) => + # Do not bother trying if xdotool is not available + if not xdotoolBinPath? + cb? new Error "xdotool not available." + return + # blackbox needs to be running for windowactivate to work blackboxService = services.find("BlackBox") if blackboxService.state != "started" @@ -73,4 +83,4 @@ module.exports = err = new Error "Failed to send keys." cb? err - sendKeysSync: (keys) => Sync () => @sendKeys.sync @, keys \ No newline at end of file + sendKeysSync: (keys) => Sync () => @sendKeys.sync @, keys