Skip to content

Commit

Permalink
Limit emco notifications to when Mudlet does not have focus, unless n…
Browse files Browse the repository at this point in the history
…otifyWithFocus is true. (#37)

Title says it all.
  • Loading branch information
demonnic committed Jun 23, 2022
1 parent 2a621b9 commit 29615d6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion mfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"package": "MDK",
"version": "2.6.0",
"version": "2.6.1",
"author": "Demonnic",
"title": "Collection of useful objects/classes",
"icon": "computer.png",
Expand Down
25 changes: 23 additions & 2 deletions src/resources/emco.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ local EMCO = Geyser.Container:new({
logFormat = "h",
gags = {},
notifyTabs = {},
notifyWithFocus = false,
})

-- patch Geyser.MiniConsole if it does not have its own display method defined
Expand Down Expand Up @@ -344,6 +345,11 @@ end
-- <td class="tg-odd">Tables containing the names of all tabs you want to send notifications. IE {"Says", "Tells", "Org"}</td>
-- <td class="tg-odd">{}</td>
-- </tr>
-- <tr>
-- <td class="tg-even">notifyWithFocus</td>
-- <td class="tg-even">If true, EMCO will send notifications even if Mudlet has focus. If false, it will only send them when Mudlet does NOT have focus.</td>
-- <td class="tg-even">false</td>
-- </tr>
-- </tbody>
-- </table>
-- @tparam GeyserObject container The container to use as the parent for the EMCO
Expand Down Expand Up @@ -451,6 +457,9 @@ function EMCO:new(cons, container)
for _,tname in ipairs(cons.notifyTabs or {}) do
me:addNotifyTab(tname)
end
if me:fuzzyBoolean(cons.notifyWithFocus) then
self:enableNotifyWithFocus()
end
me:reset()
if me.allTab then
me:setAllTabName(me.allTabName or me.consoles[1])
Expand Down Expand Up @@ -1636,6 +1645,16 @@ function EMCO:matchesGag(str)
return false
end

--- Enables sending OS notifications even if Mudlet has focus
function EMCO:enableNotifyWithFocus()
self.notifyWithFocus = true
end

--- Disables sending OS notifications if Mudlet has focus
function EMCO:disableNotifyWithFocus()
self.notifyWithFocus = false
end

function EMCO:strip(message, xtype)
local strippers = {
a = function(msg) return msg end,
Expand All @@ -1648,8 +1667,10 @@ function EMCO:strip(message, xtype)
end

function EMCO:sendNotification(tabName, msg)
if self.notifyTabs[tabName] then
showNotification(f'{self.name}:{tabName}', msg)
if self.notifyWithFocus or not hasFocus() then
if self.notifyTabs[tabName] then
showNotification(f'{self.name}:{tabName}', msg)
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/resources/mdkversion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.6.0
2.6.1

0 comments on commit 29615d6

Please sign in to comment.