Skip to content
This repository has been archived by the owner on Apr 11, 2020. It is now read-only.

Commit

Permalink
some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
asmagill committed Nov 13, 2016
1 parent 95d7f6f commit 4ae6e27
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 16 deletions.
1 change: 1 addition & 0 deletions hammer-build
Expand Up @@ -18,6 +18,7 @@ if [[ $1 != doc* ]]; then
make || exit

# signing with self-signed cert so I no longer have to reset accessibility all the time
xattr -cr "build/Hammerspoon.app" # codesign has become more anal in 10.12
codesign --verbose --sign "Internal Code Signing" "build/Hammerspoon.app/Contents/Frameworks/LuaSkin.framework/Versions/A"
codesign --verbose --sign "Internal Code Signing" "build/Hammerspoon.app"

Expand Down
60 changes: 44 additions & 16 deletions utils/_actions/location.lua
@@ -1,9 +1,15 @@
local module = {}
local location = require("hs.location")
local settings = require("hs.settings")
local canvas = require("hs._asm.canvas")
local screen = require("hs.screen")
local stext = require("hs.styledtext")
-- i have a date/time format for logging that I like, but others copying this may not
local timestamp = timestamp
if not timestamp then timestamp = os.date end

local module = {}
local location = require("hs.location")
local settings = require("hs.settings")
local canvas = require("hs._asm.canvas")
local screen = require("hs.screen")
local stext = require("hs.styledtext")
local timer = require("hs.timer")
local reachability = require("hs.network.reachability")

-- _asm.monitoredLocations should be an array of the format:
-- {
Expand Down Expand Up @@ -65,14 +71,40 @@ local updateLabel = function(err)
label[2].text = text
end

local geocoderRequest = function()
if module._geocoder then module._geocoder = module._geocoder:cancel() end
module._geocoder = location.geocoder.lookupLocation(location.get(), function(state, result)
module.addressInfo = result
module._geocoder = nil
end)
local notifiedAboutInternet = false

local geocoderRequest
geocoderRequest = function()
if not module._geocoder then
if location.get() then
module._geocoder = location.geocoder.lookupLocation(location.get(), function(good, result)
module.addressInfo = result
if good then
notifiedAboutInternet = false
module._geocoder = nil
else
if module.internetCheck:status() & reachability.flags.reachable > 0 then
print("~~ " .. timestamp() .. " geocoder error: " .. result .. ", will try again in 60 seconds")
elseif not notifiedAboutInternet then
print("~~ " .. timestamp() .. " geocoder requires internet access, waiting until reachability changes")
notifiedAboutInternet = true
end
module._geocoder = timer.doAfter(60, function()
module._geocoder = nil
geocoderRequest()
end)
end
end)
else
module._geocoder = timer.doAfter(60, function()
module._geocoder = nil
geocoderRequest()
end)
end
end
end

module.internetCheck = reachability.internet()
module.label = label
module.labelWatcher = location.new():callback(function(self, message, ...)
if message:match("Region$") then updateLabel(table.pack(...)[2]) end -- will be nil unless error
Expand All @@ -85,10 +117,6 @@ geocoderRequest()
-- interface to hs.location was to allow different code to monitor for different region changes, but as a
-- proof-of-concept, it'll do for now...

-- i have a date/time format for logging that I like, but others copying this may not
local timestamp = timestamp
if not timestamp then timestamp = os.date end

module.manager = location.new():callback(function(self, message, ...)
print(string.format("~~ %s:%s\n %s", timestamp(), message, (inspecta(table.pack(...)):gsub("%s+", " "))))
end)
Expand Down

0 comments on commit 4ae6e27

Please sign in to comment.