[hammerspoon] add a toggle function for Quitter

pull/41/head
Alpha Chen 2 years ago
parent 7b98546ab5
commit e23c227b65

@ -14,6 +14,7 @@ obj.license = "MIT - https://opensource.org/licenses/MIT"
obj.logger = hs.logger.new("quitter", "warning") obj.logger = hs.logger.new("quitter", "warning")
obj.lastFocused = {} obj.lastFocused = {}
obj.state = "stopped"
--- Quitter.quitAppsAfter --- Quitter.quitAppsAfter
--- Variable --- Variable
@ -27,6 +28,8 @@ obj.quitAppsAfter = {}
--- Parameters: --- Parameters:
--- * None --- * None
function obj:start() function obj:start()
if self.state == "started" then return end
self:reset() self:reset()
-- Reset if we're waking from sleep -- Reset if we're waking from sleep
@ -51,6 +54,8 @@ function obj:start()
self:reap() self:reap()
end):start() end):start()
self.state = "started"
return self return self
end end
@ -61,9 +66,27 @@ end
--- Parameters: --- Parameters:
--- * None --- * None
function obj:stop() function obj:stop()
if self.state == "stopped" then return end
self.watcher:stop() self.watcher:stop()
self.windowFilter:unsubscribe(hs.window.filter.windowFocused) self.windowFilter:unsubscribeAll()
self.timer:stop() 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 end
function obj:reset() function obj:reset()

Loading…
Cancel
Save