Recast: Added Ability to have a couter in the menu
This commit is contained in:
+18
-10
@@ -30,6 +30,7 @@ if cfgData then
|
||||
end
|
||||
|
||||
obj.saveInterval = 300
|
||||
obj.saveCountdown = obj.saveInterval
|
||||
obj.isRescued = false
|
||||
obj.isTransitioning = false
|
||||
obj.isRestoring = false
|
||||
@@ -227,18 +228,17 @@ end
|
||||
-- ==========================================
|
||||
-- MENUBAR & WATCHERS
|
||||
-- ==========================================
|
||||
local saveCountdown = obj.saveInterval
|
||||
local timerMenu = hs.menubar.new()
|
||||
|
||||
function updateMenu()
|
||||
if timerMenu then
|
||||
local screens = hs.screen.allScreens()
|
||||
timerMenu:setTitle(string.format("💠 %d:%02d", math.floor(saveCountdown / 60), saveCountdown % 60))
|
||||
timerMenu:setTitle(string.format("💠 %d:%02d", math.floor(obj.saveCountdown / 60), obj.saveCountdown % 60))
|
||||
local menuTable = {
|
||||
{ title = "📅 Last Saved: " .. (obj.lastSavedTime or "Never"), disabled = true },
|
||||
{ title = ((#screens > 1) and "🖥️ Docked" or "💻 Laptop") .. " (" .. #screens .. " Screens)", disabled = true },
|
||||
{ title = "-" },
|
||||
{ title = "📸 Save Layout (⇧⌘W)", fn = function() obj.saveLayout(false); saveCountdown = obj.saveInterval end },
|
||||
{ title = "📸 Save Layout (⇧⌘W)", fn = function() obj.saveLayout(false); obj.saveCountdown = obj.saveInterval end },
|
||||
{ title = "🔄 Restore Layout (⇧⌘R)", fn = function() obj.restoreLayout() end },
|
||||
{ title = "🚀 Rescue Windows (Cascade on Laptop) (⇧⌘⌃L)", fn = obj.rescueWindowsToLaptop },
|
||||
{ title = "-" },
|
||||
@@ -266,7 +266,7 @@ obj.powerWatcher = hs.caffeinate.watcher.new(function(event)
|
||||
if obj.autoSaveTimer then obj.autoSaveTimer:stop() end
|
||||
elseif event == hs.caffeinate.watcher.systemDidWake or event == hs.caffeinate.watcher.screensDidWake or event == hs.caffeinate.watcher.screensDidUnlock then
|
||||
log("POWER: Wake event.")
|
||||
saveCountdown = obj.saveInterval
|
||||
obj.saveCountdown = obj.saveInterval
|
||||
if obj.autoSaveTimer then obj.autoSaveTimer:start() end
|
||||
if obj.wakeTimer then obj.wakeTimer:stop() end
|
||||
|
||||
@@ -289,7 +289,7 @@ obj.powerWatcher = hs.caffeinate.watcher.new(function(event)
|
||||
end
|
||||
end):start()
|
||||
|
||||
hs.hotkey.bind({"shift", "cmd"}, "W", function() obj.saveLayout(false); saveCountdown = obj.saveInterval end)
|
||||
hs.hotkey.bind({"shift", "cmd"}, "W", function() obj.saveLayout(false); obj.saveCountdown = obj.saveInterval end)
|
||||
hs.hotkey.bind({"shift", "cmd"}, "R", function() obj.restoreLayout() end)
|
||||
hs.hotkey.bind({"shift", "cmd", "ctrl"}, "L", obj.rescueWindowsToLaptop)
|
||||
|
||||
@@ -326,12 +326,12 @@ end):start()
|
||||
|
||||
obj.autoSaveTimer = hs.timer.doEvery(obj.saveInterval, function()
|
||||
obj.saveLayout(true)
|
||||
saveCountdown = obj.saveInterval
|
||||
obj.saveCountdown = obj.saveInterval
|
||||
end)
|
||||
|
||||
obj.clockTimer = hs.timer.doEvery(1, function()
|
||||
saveCountdown = saveCountdown - 1
|
||||
if saveCountdown < 0 then saveCountdown = obj.saveInterval end
|
||||
obj.saveCountdown = obj.saveCountdown - 1
|
||||
if obj.saveCountdown < 0 then obj.saveCountdown = obj.saveInterval end
|
||||
updateMenu()
|
||||
end)
|
||||
|
||||
@@ -341,7 +341,15 @@ updateMenu()
|
||||
-- RAYCAST INTERACTIVE CHOOSER MENU
|
||||
-- ==========================================
|
||||
function obj.showMenu()
|
||||
local min = math.floor(obj.saveCountdown / 60)
|
||||
local sec = obj.saveCountdown % 60
|
||||
|
||||
local choices = {
|
||||
{
|
||||
text = string.format("⏱️ Next Autosave: %d:%02d", min, sec),
|
||||
subText = "📅 Last Saved Profile State: " .. obj.lastSavedTime,
|
||||
action = "info"
|
||||
},
|
||||
{
|
||||
text = "📸 Save State Layout",
|
||||
subText = "Snapshot active positions to saved_layout.json (Resets auto-timer)",
|
||||
@@ -365,7 +373,7 @@ function obj.showMenu()
|
||||
if choice then
|
||||
if choice.action == "save" then
|
||||
obj.saveLayout(false)
|
||||
saveCountdown = obj.saveInterval
|
||||
obj.saveCountdown = obj.saveInterval
|
||||
elseif choice.action == "restore" then
|
||||
obj.restoreLayout()
|
||||
elseif choice.action == "rescue" then
|
||||
@@ -374,7 +382,7 @@ function obj.showMenu()
|
||||
end
|
||||
end)
|
||||
|
||||
obj.instanceChooser:placeholderText("Workspace Manager Actions...")
|
||||
obj.instanceChooser:placeholderText("Select a background workspace operation...")
|
||||
obj.instanceChooser:choices(choices)
|
||||
obj.instanceChooser:show()
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user