Browse Source

Hammerspoon: add Caffeine

ubuntu_ci
Ein Verne 4 years ago
parent
commit
34f609176e
No known key found for this signature in database
GPG Key ID: 926634D64ACAD792
  1. 234
      hammerspoon/Spoons/Caffeine.spoon/caffeine-off.pdf
  2. 238
      hammerspoon/Spoons/Caffeine.spoon/caffeine-on.pdf
  3. 143
      hammerspoon/Spoons/Caffeine.spoon/docs.json
  4. 119
      hammerspoon/Spoons/Caffeine.spoon/init.lua
  5. 67
      hammerspoon/init.lua

234
hammerspoon/Spoons/Caffeine.spoon/caffeine-off.pdf

File diff suppressed because one or more lines are too long

238
hammerspoon/Spoons/Caffeine.spoon/caffeine-on.pdf

File diff suppressed because one or more lines are too long

143
hammerspoon/Spoons/Caffeine.spoon/docs.json

@ -0,0 +1,143 @@
[
{
"Command": [],
"Constant": [],
"Constructor": [],
"Deprecated": [],
"Field": [],
"Function": [],
"Method": [
{
"def": "Caffeine:bindHotkeys(mapping)",
"desc": "Binds hotkeys for Caffeine",
"doc": "Binds hotkeys for Caffeine\n\nParameters:\n * mapping - A table containing hotkey modifier/key details for the following items:\n * toggle - This will toggle the state of display sleep prevention, and update the menubar graphic\n\nReturns:\n * The Caffeine object",
"name": "bindHotkeys",
"parameters": [
" * mapping - A table containing hotkey modifier/key details for the following items:",
" * toggle - This will toggle the state of display sleep prevention, and update the menubar graphic"
],
"returns": [
" * The Caffeine object"
],
"signature": "Caffeine:bindHotkeys(mapping)",
"stripped_doc": "",
"type": "Method"
},
{
"def": "Caffeine:setState(on)",
"desc": "Sets whether or not caffeination should be enabled",
"doc": "Sets whether or not caffeination should be enabled\n\nParameters:\n * on - A boolean, true if screens should be kept awake, false to let macOS send them to sleep\n\nReturns:\n * None",
"name": "setState",
"parameters": [
" * on - A boolean, true if screens should be kept awake, false to let macOS send them to sleep"
],
"returns": [
" * None"
],
"signature": "Caffeine:setState(on)",
"stripped_doc": "",
"type": "Method"
},
{
"def": "Caffeine:start()",
"desc": "Starts Caffeine",
"doc": "Starts Caffeine\n\nParameters:\n * None\n\nReturns:\n * The Caffeine object",
"name": "start",
"parameters": [
" * None"
],
"returns": [
" * The Caffeine object"
],
"signature": "Caffeine:start()",
"stripped_doc": "",
"type": "Method"
},
{
"def": "Caffeine:stop()",
"desc": "Stops Caffeine",
"doc": "Stops Caffeine\n\nParameters:\n * None\n\nReturns:\n * The Caffeine object",
"name": "stop",
"parameters": [
" * None"
],
"returns": [
" * The Caffeine object"
],
"signature": "Caffeine:stop()",
"stripped_doc": "",
"type": "Method"
}
],
"Variable": [],
"desc": "Prevent the screen from going to sleep",
"doc": "Prevent the screen from going to sleep\nDownload: [https://github.com/Hammerspoon/Spoons/raw/master/Spoons/Caffeine.spoon.zip](https://github.com/Hammerspoon/Spoons/raw/master/Spoons/Caffeine.spoon.zip)",
"items": [
{
"def": "Caffeine:bindHotkeys(mapping)",
"desc": "Binds hotkeys for Caffeine",
"doc": "Binds hotkeys for Caffeine\n\nParameters:\n * mapping - A table containing hotkey modifier/key details for the following items:\n * toggle - This will toggle the state of display sleep prevention, and update the menubar graphic\n\nReturns:\n * The Caffeine object",
"name": "bindHotkeys",
"parameters": [
" * mapping - A table containing hotkey modifier/key details for the following items:",
" * toggle - This will toggle the state of display sleep prevention, and update the menubar graphic"
],
"returns": [
" * The Caffeine object"
],
"signature": "Caffeine:bindHotkeys(mapping)",
"stripped_doc": "",
"type": "Method"
},
{
"def": "Caffeine:setState(on)",
"desc": "Sets whether or not caffeination should be enabled",
"doc": "Sets whether or not caffeination should be enabled\n\nParameters:\n * on - A boolean, true if screens should be kept awake, false to let macOS send them to sleep\n\nReturns:\n * None",
"name": "setState",
"parameters": [
" * on - A boolean, true if screens should be kept awake, false to let macOS send them to sleep"
],
"returns": [
" * None"
],
"signature": "Caffeine:setState(on)",
"stripped_doc": "",
"type": "Method"
},
{
"def": "Caffeine:start()",
"desc": "Starts Caffeine",
"doc": "Starts Caffeine\n\nParameters:\n * None\n\nReturns:\n * The Caffeine object",
"name": "start",
"parameters": [
" * None"
],
"returns": [
" * The Caffeine object"
],
"signature": "Caffeine:start()",
"stripped_doc": "",
"type": "Method"
},
{
"def": "Caffeine:stop()",
"desc": "Stops Caffeine",
"doc": "Stops Caffeine\n\nParameters:\n * None\n\nReturns:\n * The Caffeine object",
"name": "stop",
"parameters": [
" * None"
],
"returns": [
" * The Caffeine object"
],
"signature": "Caffeine:stop()",
"stripped_doc": "",
"type": "Method"
}
],
"name": "Caffeine",
"stripped_doc": "Download: [https://github.com/Hammerspoon/Spoons/raw/master/Spoons/Caffeine.spoon.zip](https://github.com/Hammerspoon/Spoons/raw/master/Spoons/Caffeine.spoon.zip)",
"submodules": [],
"type": "Module"
}
]

119
hammerspoon/Spoons/Caffeine.spoon/init.lua

@ -0,0 +1,119 @@
--- === Caffeine ===
---
--- Prevent the screen from going to sleep
--- Download: [https://github.com/Hammerspoon/Spoons/raw/master/Spoons/Caffeine.spoon.zip](https://github.com/Hammerspoon/Spoons/raw/master/Spoons/Caffeine.spoon.zip)
local obj = { __gc = true }
--obj.__index = obj
setmetatable(obj, obj)
obj.__gc = function(t)
t:stop()
end
-- Metadata
obj.name = "Caffeine"
obj.version = "1.0"
obj.author = "Chris Jones <[email protected]>"
obj.homepage = "https://github.com/Hammerspoon/Spoons"
obj.license = "MIT - https://opensource.org/licenses/MIT"
obj.menuBarItem = nil
obj.hotkeyToggle = nil
-- Internal function used to find our location, so we know where to load files from
local function script_path()
local str = debug.getinfo(2, "S").source:sub(2)
return str:match("(.*/)")
end
obj.spoonPath = script_path()
function obj:init()
end
--- Caffeine:bindHotkeys(mapping)
--- Method
--- Binds hotkeys for Caffeine
---
--- Parameters:
--- * mapping - A table containing hotkey modifier/key details for the following items:
--- * toggle - This will toggle the state of display sleep prevention, and update the menubar graphic
---
--- Returns:
--- * The Caffeine object
function obj:bindHotkeys(mapping)
if (self.hotkeyToggle) then
self.hotkeyToggle:delete()
end
local toggleMods = mapping["toggle"][1]
local toggleKey = mapping["toggle"][2]
self.hotkeyToggle = hs.hotkey.new(toggleMods, toggleKey, function() self.clicked() end)
return self
end
--- Caffeine:start()
--- Method
--- Starts Caffeine
---
--- Parameters:
--- * None
---
--- Returns:
--- * The Caffeine object
function obj:start()
if self.menuBarItem then self:stop() end
self.menuBarItem = hs.menubar.new()
self.menuBarItem:setClickCallback(self.clicked)
if (self.hotkeyToggle) then
self.hotkeyToggle:enable()
end
self.setDisplay(hs.caffeinate.get("displayIdle"))
return self
end
--- Caffeine:stop()
--- Method
--- Stops Caffeine
---
--- Parameters:
--- * None
---
--- Returns:
--- * The Caffeine object
function obj:stop()
if self.menuBarItem then self.menuBarItem:delete() end
if (self.hotkeyToggle) then
self.hotkeyToggle:disable()
end
self.menuBarItem = nil
return self
end
function obj.setDisplay(state)
local result
if state then
result = obj.menuBarItem:setIcon(obj.spoonPath.."/caffeine-on.pdf")
else
result = obj.menuBarItem:setIcon(obj.spoonPath.."/caffeine-off.pdf")
end
end
function obj.clicked()
obj.setDisplay(hs.caffeinate.toggle("displayIdle"))
end
--- Caffeine:setState(on)
--- Method
--- Sets whether or not caffeination should be enabled
---
--- Parameters:
--- * on - A boolean, true if screens should be kept awake, false to let macOS send them to sleep
---
--- Returns:
--- * None
function obj:setState(on)
hs.caffeinate.set("displayIdle", on)
obj.setDisplay(on)
end
return obj

67
hammerspoon/init.lua

@ -25,53 +25,6 @@ f18 = hs.hotkey.bind({}, 'F18', pressedF18, releasedF18)
hyper = {"ctrl", "alt", "cmd", "shift"} hyper = {"ctrl", "alt", "cmd", "shift"}
function moveWindow(direction)
return function()
local win = hs.window.focusedWindow()
local app = win:application()
local app_name = app:name()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
if direction == "left" then
f.x = max.x
f.y = max.y
f.w = (max.w / 2)
f.h = max.h
elseif direction == "right" then
f.x = (max.x + (max.w / 2))
f.y = max.y
f.w = (max.w / 2)
f.h = max.h
elseif direction == "full" then
f.x = max.x
f.y = max.y
f.w = max.w
f.h = max.h
elseif direction == "up" then
f.x = max.x
f.y = max.y
f.w = max.w
f.h = (max.h / 2)
elseif direction == "down" then
f.x = max.x
f.y = max.y + (max.h / 2)
f.w = max.w
f.h = max.h / 2
elseif direction == "normal" then
f.x = (max.x + (max.w / 8)) + 6
f.y = max.y
f.w = (max.w * 3 / 4) - 12
f.h = max.h
end
win:setFrame(f, 0.0)
end
end
hs.hotkey.bind(hyper, "H", moveWindow("left"))
hs.hotkey.bind(hyper, "L", moveWindow("right"))
hs.hotkey.bind(hyper, "K", moveWindow("up"))
hs.hotkey.bind(hyper, "J", moveWindow("down"))
hs.hotkey.bind(hyper, "F", moveWindow("full"))
-- hs.hotkey.bind(hyper, "C", function() hs.application.launchOrFocus("Google Chrome") end) -- hs.hotkey.bind(hyper, "C", function() hs.application.launchOrFocus("Google Chrome") end)
function moveWindowToDisplay(d) function moveWindowToDisplay(d)
@ -234,11 +187,14 @@ if not hspoon_list then
"BingDaily", "BingDaily",
"CircleClock", "CircleClock",
"ClipShow", "ClipShow",
"CountDown", --"CountDown",
"HCalendar", "HCalendar",
--"HSaria2", --"HSaria2",
"SpeedMenu", "SpeedMenu",
"WinWin", "WinWin",
"WifiNotifier",
"WinRectangle",
"Caffeine",
} }
end end
@ -270,6 +226,7 @@ if not hsapp_list then
hsapp_list = { hsapp_list = {
{key = 'f', name = 'Finder'}, {key = 'f', name = 'Finder'},
{key = 'c', name = 'Google Chrome'}, {key = 'c', name = 'Google Chrome'},
{key = 'o', name = 'Obsidian'},
{key = 's', name = 'Safari'}, {key = 's', name = 'Safari'},
{key = 't', name = 'Terminal'}, {key = 't', name = 'Terminal'},
{key = 'v', id = 'com.apple.ActivityMonitor'}, {key = 'v', id = 'com.apple.ActivityMonitor'},
@ -537,6 +494,20 @@ if spoon.AClock then
end end
end end
-- Register WinRectangle
if spoon.WinRectangle then
spoon.WinRectangle:bindHotkeys(spoon.WinRectangle.defaultHotkeys)
end
-- Register Caffeine
if spoon.Caffeine then
spoon.Caffeine:start()
end
if spoon.wifiNotifier then
spoon.wifiNotifier:start()
end
---------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------
-- Register browser tab typist: Type URL of current tab of running browser in markdown format. i.e. [title](link) -- Register browser tab typist: Type URL of current tab of running browser in markdown format. i.e. [title](link)
hstype_keys = hstype_keys or {"alt", "V"} hstype_keys = hstype_keys or {"alt", "V"}

Loading…
Cancel
Save