Fix instance existing check for application spawn (#2774)
User defined matcher now has higher priority while checking existing instance for application spawn.
This commit is contained in:
parent
900cca54a4
commit
5fef354892
|
@ -547,18 +547,18 @@ local function is_running(hash, matcher)
|
||||||
local status = spawn.single_instance_manager.by_uid[hash]
|
local status = spawn.single_instance_manager.by_uid[hash]
|
||||||
if not status then return false end
|
if not status then return false end
|
||||||
|
|
||||||
if #status.instances == 0 then return false end
|
|
||||||
|
|
||||||
for _, c in ipairs(status.instances) do
|
|
||||||
if c.valid then return true end
|
|
||||||
end
|
|
||||||
|
|
||||||
if matcher then
|
if matcher then
|
||||||
for _, c in ipairs(client.get()) do
|
for _, c in ipairs(client.get()) do
|
||||||
if matcher(c) then return true end
|
if matcher(c) then return true end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if #status.instances == 0 then return false end
|
||||||
|
|
||||||
|
for _, c in ipairs(status.instances) do
|
||||||
|
if c.valid then return true end
|
||||||
|
end
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -37,8 +37,6 @@ app:run {''}
|
||||||
]]}
|
]]}
|
||||||
end
|
end
|
||||||
|
|
||||||
local matcher_called = false
|
|
||||||
|
|
||||||
local steps = {
|
local steps = {
|
||||||
function()
|
function()
|
||||||
-- Test various error conditions. There are quite a number of them...
|
-- Test various error conditions. There are quite a number of them...
|
||||||
|
@ -321,19 +319,47 @@ local steps = {
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
-- Test the matcher
|
-- Test the matcher
|
||||||
|
function()
|
||||||
|
-- pre spawn client
|
||||||
|
if #client.get() ~= 0 then return end
|
||||||
|
spawn(tiny_client("client1"))
|
||||||
|
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
function()
|
||||||
|
-- test matcher
|
||||||
|
if #client.get() ~= 1 then return end
|
||||||
|
|
||||||
|
local matcher = function(c)
|
||||||
|
return c.class == "client1" or c.class == "client2"
|
||||||
|
end
|
||||||
|
|
||||||
|
-- This should do nothing
|
||||||
|
spawn.once(tiny_client("client2"), {tag=screen[1].tags[5]}, matcher)
|
||||||
|
spawn.single_instance(tiny_client("client2"), {tag=screen[1].tags[5]}, matcher)
|
||||||
|
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
function()
|
||||||
|
-- clean up
|
||||||
|
if #client.get() ~= 1 then return end
|
||||||
|
client.get()[1]:kill()
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
-- Test rules works with matcher if client doesn't support startup id
|
||||||
|
-- Can this test be performed using '_client' module without external 'xterm' application?
|
||||||
function()
|
function()
|
||||||
if #client.get() ~= 0 then return end
|
if #client.get() ~= 0 then return end
|
||||||
|
|
||||||
spawn.single_instance("xterm", {tag=screen[1].tags[5]}, function(c)
|
spawn.single_instance("xterm", {tag=screen[1].tags[5]}, function(c)
|
||||||
matcher_called = true
|
return c.class == "XTerm"
|
||||||
return c.class == "xterm"
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
function()
|
function()
|
||||||
if #client.get() ~= 1 then return end
|
if #client.get() ~= 1 then return end
|
||||||
assert(matcher_called)
|
assert(client.get()[1]:tags()[1] == screen[1].tags[5])
|
||||||
client.get()[1]:kill()
|
client.get()[1]:kill()
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
|
|
Loading…
Reference in New Issue