-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
202 lines (171 loc) · 5.7 KB
/
Copy pathinit.lua
File metadata and controls
202 lines (171 loc) · 5.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
-- Simplified init.lua for Hammerspoon
-- Working version with modular architecture
local hotkey_utils = require("utils.hotkey_utils")
-- Essential hotkeys (always available)
hotkey_utils.bind({"ctrl", "cmd", "alt"}, "R", {
module = "system",
id = "reload",
description = "Reload Hammerspoon configuration",
toast = {enabled = true, message = "Reloading Hammerspoon...", duration = 0.6},
pressed = function()
hs.reload()
end
})
hotkey_utils.bind({"ctrl", "cmd", "alt"}, "H", {
module = "system",
id = "console",
description = "Open Hammerspoon console",
toast = false,
pressed = function()
hs.openConsole()
end
})
local notification_utils = require("utils.notification_utils")
-- Load new modular system
local function loadModularSystem()
local modules_loaded = 0
print("Loading modules through init_system...")
-- First, require all modules so they can register themselves
-- This does NOT initialize them, just registers them
local utility_modules = {
"utils/app_utils",
"utils/display_utils",
"utils/notification_utils",
"utils/window_utils"
}
for _, module_name in ipairs(utility_modules) do
local success, module = pcall(require, module_name)
if success then
modules_loaded = modules_loaded + 1
print("Registered: " .. module_name)
else
print("Warning: Failed to register " .. module_name)
end
end
-- Determine which mouse management module to load (allows easy swapping)
local config_loader = require("core.config_loader")
local mouse_module_name = config_loader.get("mouse.management_module", "modules.mouse_management")
-- Load feature modules (excluding expose for lazy loading)
local feature_modules = {
"modules/window_management",
"modules/app_launcher",
"modules/media_controls",
"modules/display_layout",
mouse_module_name,
"modules/wifi_automation",
"modules/keystroke_visualizer",
"modules/notch_hider"
}
for _, module_name in ipairs(feature_modules) do
local success, module = pcall(require, module_name)
if success then
modules_loaded = modules_loaded + 1
print("Registered: " .. module_name)
else
print("Warning: Failed to register " .. module_name)
end
end
-- Now initialize all modules and their hotkeys through the proper module system
local init_system = require("core.init_system")
local init_success = init_system.loadAllModules()
if init_success then
print("All modules initialized successfully")
else
print("Warning: Some modules failed to initialize")
end
return modules_loaded
end
-- Load the modular system
local modules_loaded_count = loadModularSystem()
print("Hammerspoon loaded " .. modules_loaded_count .. " modules")
-- Success notification
notification_utils.announce("system", "startup", {
message = "Hammerspoon loaded",
duration = 1.0,
override = true
})
-- Lazy load window switcher on first Alt+Tab usage
local function cloneHotkey(list)
local result = {}
for i, value in ipairs(list) do
result[i] = string.lower(value)
end
return result
end
local function splitHotkey(hotkey)
if type(hotkey) ~= "table" or #hotkey == 0 then
return nil, nil
end
local key = hotkey[#hotkey]
local mods = {}
for i = 1, #hotkey - 1 do
mods[i] = string.lower(hotkey[i])
end
return mods, key
end
local switcherLoaded = false
local lazyBindings = {}
local function ensureWindowSwitcher(stepDirection)
if switcherLoaded then
local ok, module = pcall(require, "modules.window_expose")
if ok and module.trigger then
module.trigger(stepDirection or 1)
return true
end
return ok
end
local ok, module = pcall(require, "modules.window_expose")
if not ok then
print("Failed to load window switcher: " .. tostring(module))
return false
end
if module.ensureInitialized then
module.ensureInitialized()
elseif module.init then
module.init()
end
for _, binding in ipairs(lazyBindings) do
binding:delete()
end
lazyBindings = {}
switcherLoaded = true
if module.trigger then
module.trigger(stepDirection or 1)
end
return true
end
local config_loader = require("core.config_loader")
local exposeHotkey = config_loader.get("hotkeys.system.expose", {"alt", "tab"})
local baseMods, exposeKey = splitHotkey(exposeHotkey)
if baseMods and exposeKey then
local function bindLazy(mods, stepDirection)
local binding = hotkey_utils.bind(mods, exposeKey, {
module = "system",
id = stepDirection == 1 and "window_switcher_lazy_forward" or "window_switcher_lazy_backward",
description = "Window Switcher (Lazy Load)",
toast = false,
pressed = function()
ensureWindowSwitcher(stepDirection)
end
})
if binding then
table.insert(lazyBindings, binding)
end
end
bindLazy(baseMods, 1)
end
-- Debug function
hs.debugHammerspoon = {
reload = function() hs.reload() end,
console = function() hs.openConsole() end,
status = function()
print("=== Hammerspoon Status ===")
print("Configuration: Modular")
print("Modules loaded: " .. modules_loaded_count)
print("Use Ctrl+Cmd+Alt+H for console")
print("============================")
end
}
print("Hammerspoon configuration loaded")
print("Use hs.debugHammerspoon.status() for debug info")
print("Press Ctrl+Cmd+Alt+H for console")