Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
cmsj authored Aug 7, 2024
2 parents d0926fe + 95e6382 commit d45dd71
Show file tree
Hide file tree
Showing 55 changed files with 9,620 additions and 672 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/PR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ jobs:
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Check-out the Spoons PR
- uses: actions/checkout@v2
- uses: actions/checkout@v4

# Check-out the Hammerspoon repository we need for doc building
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
repository: 'Hammerspoon/hammerspoon'
path: 'hammerspoon'
Expand All @@ -40,7 +40,7 @@ jobs:
/usr/bin/python3 -m pip install -r requirements.txt
# Find files modified by this PR
- uses: lots0logs/gh-action-get-changed-files@2.1.4
- uses: lots0logs/gh-action-get-changed-files@2.2.2
with:
token: ${{ secrets.GITHUB_TOKEN }}

Expand Down
16 changes: 8 additions & 8 deletions Source/AClock.spoon/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"doc": "Hide AClock.\n\nParameters:\n * None\n\nReturns:\n * The AClock object",
"examples": [],
"file": "Source/AClock.spoon//init.lua",
"lineno": "116",
"lineno": "130",
"name": "hide",
"notes": [],
"parameters": [
Expand Down Expand Up @@ -51,7 +51,7 @@
"doc": "Show AClock.\n\nParameters:\n * None\n\nReturns:\n * The AClock object",
"examples": [],
"file": "Source/AClock.spoon//init.lua",
"lineno": "97",
"lineno": "111",
"name": "show",
"notes": [],
"parameters": [
Expand All @@ -70,7 +70,7 @@
"doc": "Show AClock for 4 seconds. If already showing, hide it.\n\nParameters:\n * None",
"examples": [],
"file": "Source/AClock.spoon//init.lua",
"lineno": "133",
"lineno": "147",
"name": "toggleShow",
"notes": [],
"parameters": [
Expand All @@ -87,7 +87,7 @@
"doc": "Show AClock. If already showing, hide it.\n\nParameters:\n * None",
"examples": [],
"file": "Source/AClock.spoon//init.lua",
"lineno": "154",
"lineno": "168",
"name": "toggleShowPersistent",
"notes": [],
"parameters": [
Expand All @@ -109,7 +109,7 @@
"doc": "Hide AClock.\n\nParameters:\n * None\n\nReturns:\n * The AClock object",
"examples": [],
"file": "Source/AClock.spoon//init.lua",
"lineno": "116",
"lineno": "130",
"name": "hide",
"notes": [],
"parameters": [
Expand Down Expand Up @@ -147,7 +147,7 @@
"doc": "Show AClock.\n\nParameters:\n * None\n\nReturns:\n * The AClock object",
"examples": [],
"file": "Source/AClock.spoon//init.lua",
"lineno": "97",
"lineno": "111",
"name": "show",
"notes": [],
"parameters": [
Expand All @@ -166,7 +166,7 @@
"doc": "Show AClock for 4 seconds. If already showing, hide it.\n\nParameters:\n * None",
"examples": [],
"file": "Source/AClock.spoon//init.lua",
"lineno": "133",
"lineno": "147",
"name": "toggleShow",
"notes": [],
"parameters": [
Expand All @@ -183,7 +183,7 @@
"doc": "Show AClock. If already showing, hide it.\n\nParameters:\n * None",
"examples": [],
"file": "Source/AClock.spoon//init.lua",
"lineno": "154",
"lineno": "168",
"name": "toggleShowPersistent",
"notes": [],
"parameters": [
Expand Down
26 changes: 20 additions & 6 deletions Source/AClock.spoon/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ for k, v in pairs(obj._attribs) do obj[k] = v end
---
--- Returns:
--- * The AClock object
function getframe(width, height)
local mainScreen = hs.screen.primaryScreen()
local mainRes = mainScreen:fullFrame()
return {
x = (mainRes.w - width) / 2,
y = (mainRes.h - height) / 2,
w = width,
h = height
}
end

function obj:init()
if not self.canvas then self.canvas = hs.canvas.new({x=0, y=0, w=0, h=0}) end
self.canvas[1] = {
Expand All @@ -72,16 +83,19 @@ function obj:init()
}
local mainScreen = hs.screen.primaryScreen()
local mainRes = mainScreen:fullFrame()
self.canvas:frame({
x = (mainRes.w-self.width)/2,
y = (mainRes.h-self.height)/2,
w = self.width,
h = self.height,
})
self.canvas:frame(getframe(self.width, self.height))
self._screen_watcher = hs.screen.watcher.new(function()
self:update_canvas()
end)
self._screen_watcher:start()
self._init_done = true
return self
end

function obj:update_canvas()
self.canvas:frame(getframe(self.width, self.height))
end

function obj:update_clock_text()
self.canvas[1].text = os.date(self.format)
end
Expand Down
2 changes: 1 addition & 1 deletion Source/ArrangeDesktop.spoon/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ function obj:createArrangement()
return
end

hs.dialog.blockAlert("We will now record each of your application windows.", "Each will window will flash into focus. The first focus on each monitor will prompt you to name the monitor.")
hs.dialog.blockAlert("We will now record each of your application windows.", "Each window will flash into focus. The first focus on each monitor will prompt you to name the monitor.")

config[arrangementName] = obj:_buildArrangement(arrangementName)

Expand Down
19 changes: 19 additions & 0 deletions Source/AutoMuteOnSleep.spoon/docs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[
{
"Command": [],
"Constant": [],
"Constructor": [],
"Deprecated": [],
"Field": [],
"Function": [],
"Method": [],
"Variable": [],
"desc": "Automatically set to 0 the volume of all output audio devices except Bluetooth devices when Mac goes to sleep.",
"doc": "Automatically set to 0 the volume of all output audio devices except Bluetooth devices when Mac goes to sleep.\nUseful to avoid blasting sound when opening a Macbook in the public transport.\nNote: This is primarily intended for portable Mac devices, which have internal speakers.\n\nDownload: [https://github.com/Hammerspoon/Spoons/raw/master/Spoons/AutoMuteOnSleep.spoon.zip](https://github.com/Hammerspoon/Spoons/raw/master/Spoons/AutoMuteOnSleep.spoon.zip)",
"items": [],
"name": "AutoMuteOnSleep",
"stripped_doc": "Useful to avoid blasting sound when opening a Macbook in the public transport.\nNote: This is primarily intended for portable Mac devices, which have internal speakers.\n\nDownload: [https://github.com/Hammerspoon/Spoons/raw/master/Spoons/AutoMuteOnSleep.spoon.zip](https://github.com/Hammerspoon/Spoons/raw/master/Spoons/AutoMuteOnSleep.spoon.zip)",
"submodules": [],
"type": "Module"
}
]
47 changes: 47 additions & 0 deletions Source/AutoMuteOnSleep.spoon/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
--- === AutoMuteOnSleep ===
---
--- Automatically set to 0 the volume of all output audio devices except Bluetooth devices when Mac goes to sleep.
--- Useful to avoid blasting sound when opening a Macbook in the public transport.
--- Note: This is primarily intended for portable Mac devices, which have internal speakers.
---
--- Download: [https://github.com/Hammerspoon/Spoons/raw/master/Spoons/AutoMuteOnSleep.spoon.zip](https://github.com/Hammerspoon/Spoons/raw/master/Spoons/AutoMuteOnSleep.spoon.zip)


local obj={}
obj.__index = obj

-- Metadata
obj.name = "AutoMuteOnSleep"
obj.version = "1.0"
obj.author = "devnoname120 <[email protected]"
obj.homepage = "https://github.com/Hammerspoon/Spoons"
obj.license = "MIT - https://opensource.org/licenses/MIT"

obj.sleepWatcher = nil

local function muteNonBluetoothOutputDevices(state)
if state == hs.caffeinate.watcher.systemDidWake or state == hs.caffeinate.watcher.systemWillSleep then
local devices = hs.audiodevice.allOutputDevices()

for _, device in ipairs(devices) do
if device and device:transportType() ~= 'Bluetooth' then
_ = device:setVolume(0) or device:setMuted(true)
end
end
end
end


function obj:init()
self.sleepWatcher = hs.caffeinate.watcher.new(muteNonBluetoothOutputDevices)
end

function obj:start()
self.sleepWatcher:start()
end

function obj:stop()
self.sleepWatcher:stop()
end

return obj
52 changes: 49 additions & 3 deletions Source/EmmyLua.spoon/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ M.name = "EmmyLua"
M.version = "1.0"
M.author = "http://github.com/folke"
M.license = "MIT - https://opensource.org/licenses/MIT"
M.logger = hs.logger.new("EmmyLua")


local options = {
annotations = hs.spoons.resourcePath("annotations"),
timestampsFilename = hs.spoons.resourcePath("annotations").."/timestamps.json",
timestamps = {},
timestampsChanged = false,
types = {
bool = "boolean",
boolean = "boolean",
Expand Down Expand Up @@ -185,28 +190,69 @@ function M.create(jsonDocs, prefix)
module.name = prefix .. module.name
local fname = options.annotations .. "/" .. module.name .. ".lua"
local fmtime = hs.fs.attributes(fname, "modification")

if fmtime == nil or mtime > fmtime then
-- print("creating " .. fname)
M.logger.i("creating " .. fname)
local fd = io.open(fname, "w+")
io.output(fd)
M.processModule(module)
io.close(fd)
else
M.logger.i("skipping " .. fname)
end
end
end

function M.createWhenChanged(jsonDocs, prefix)
local mtime = hs.fs.attributes(jsonDocs, "modification")
local timestamp = options.timestamps[jsonDocs]

if(timestamp == nil or mtime ~= timestamp) then
M.logger.i("reading "..jsonDocs)
M.create(jsonDocs, prefix)
options.timestamps[jsonDocs] = mtime
options.timestampsChanged = true
else
M.logger.i("skipping "..jsonDocs)
end
end

function M.readTimestamps()
timestamps = hs.json.read(options.timestampsFilename)

if timestamps then
options.timestamps = timestamps
end

M.logger.d(hs.inspect(options.timestamps))
end

function M.writeTimestamps()
M.logger.d(hs.inspect(options.timestamps))
if options.timestampsChanged then
hs.json.write(options.timestamps, options.timestampsFilename, true, true)
end
end

function M:init()

hs.fs.mkdir(options.annotations)

M.readTimestamps()

-- Load hammerspoon docs
M.create(hs.docstrings_json_file)
M.createWhenChanged(hs.docstrings_json_file)

-- Load Spoons
for _, spoon in ipairs(hs.spoons.list()) do
local doc = hs.configdir .. "/Spoons/" .. spoon.name .. ".spoon/docs.json"
if hs.fs.attributes(doc, "modification") then
M.create(doc, "spoon.")
M.createWhenChanged(doc, "spoon.")
end
end

M.writeTimestamps()

end

return M
Loading

0 comments on commit d45dd71

Please sign in to comment.