From e23c227b654a2fea2132ffd6b4b12f8d36d4651c Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Wed, 22 Jun 2022 19:47:11 -0700 Subject: [PATCH] [hammerspoon] add a toggle function for Quitter --- .hammerspoon/Spoons/Quitter.spoon/init.lua | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/.hammerspoon/Spoons/Quitter.spoon/init.lua b/.hammerspoon/Spoons/Quitter.spoon/init.lua index fe04108..8c665da 100644 --- a/.hammerspoon/Spoons/Quitter.spoon/init.lua +++ b/.hammerspoon/Spoons/Quitter.spoon/init.lua @@ -14,6 +14,7 @@ obj.license = "MIT - https://opensource.org/licenses/MIT" obj.logger = hs.logger.new("quitter", "warning") obj.lastFocused = {} +obj.state = "stopped" --- Quitter.quitAppsAfter --- Variable @@ -27,6 +28,8 @@ obj.quitAppsAfter = {} --- Parameters: --- * None function obj:start() + if self.state == "started" then return end + self:reset() -- Reset if we're waking from sleep @@ -51,6 +54,8 @@ function obj:start() self:reap() end):start() + self.state = "started" + return self end @@ -61,9 +66,27 @@ end --- Parameters: --- * None function obj:stop() + if self.state == "stopped" then return end + self.watcher:stop() - self.windowFilter:unsubscribe(hs.window.filter.windowFocused) + self.windowFilter:unsubscribeAll() self.timer:stop() + + self.state = "stopped" +end + +--- Quitter:toggle() +--- Method +--- Toggle Quitter +--- +--- Parameters: +--- * None +function obj:toggle() + if self.state == "started" then + self:stop() + else + self:start() + end end function obj:reset()