-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_simple.sh
More file actions
executable file
·119 lines (97 loc) · 3.6 KB
/
build_simple.sh
File metadata and controls
executable file
·119 lines (97 loc) · 3.6 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
#!/bin/bash
echo "🔨 Building simplified version (without UI)..."
# 创建简化版本的主文件
cat > Sources/main_simple.swift << 'EOF'
import Cocoa
import Carbon
print("Spotlight Lite - Starting...")
// 简单的配置
struct SimpleConfig {
static var mainHotKey = (keyCode: 49, modifiers: UInt32(cmdKey)) // Command + Space
}
// 全局热键管理器
class SimpleHotKeyManager {
var eventHotKeyRef: EventHotKeyRef?
var eventHandler: EventHandlerRef?
func start() {
var eventSpec = EventTypeSpec(eventClass: OSType(kEventClassKeyboard), eventKind: UInt32(kEventHotKeyPressed))
InstallEventHandler(GetApplicationEventTarget(), { (_, _, _) -> OSStatus in
print("🔍 Hotkey pressed! (Command+Space)")
print("Opening applications search...")
// 简单演示:打开 Spotlight 搜索
NSWorkspace.shared.launchApplication(
withBundleIdentifier: "com.apple.Spotlight",
options: [],
additionalEventParamDescriptor: nil,
launchIdentifier: nil
)
return noErr
}, 1, &eventSpec, nil, &eventHandler)
var hotKeyID = EventHotKeyID(signature: OSType(0x53504F54), id: 1)
RegisterEventHotKey(UInt32(SimpleConfig.mainHotKey.keyCode),
SimpleConfig.mainHotKey.modifiers,
hotKeyID,
GetApplicationEventTarget(),
0,
&eventHotKeyRef)
print("✅ Global hotkey registered: Command+Space")
print("Press Command+Space to test...")
}
deinit {
if let ref = eventHotKeyRef {
UnregisterEventHotKey(ref)
}
if let handler = eventHandler {
RemoveEventHandler(handler)
}
}
}
// 应用代理
class SimpleAppDelegate: NSObject, NSApplicationDelegate {
var statusItem: NSStatusItem?
var hotKeyManager = SimpleHotKeyManager()
func applicationDidFinishLaunching(_ notification: Notification) {
NSApp.setActivationPolicy(.accessory)
// 创建状态栏图标
statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength)
if let button = statusItem?.button {
button.image = NSImage(systemSymbolName: "magnifyingglass", accessibilityDescription: "Spotlight")
}
let menu = NSMenu()
menu.addItem(NSMenuItem(title: "Spotlight Lite is running", action: nil, keyEquivalent: ""))
menu.addItem(NSMenuItem.separator())
menu.addItem(NSMenuItem(title: "Quit", action: #selector(quit), keyEquivalent: "q"))
statusItem?.menu = menu
// 启动热键监听
hotKeyManager.start()
print("🚀 Spotlight Lite is running!")
print("📍 Check menu bar for icon")
}
@objc func quit() {
NSApplication.shared.terminate(nil)
}
}
// 启动应用
let app = NSApplication.shared
let delegate = SimpleAppDelegate()
app.delegate = delegate
app.run()
EOF
echo "Compiling simple version..."
swiftc -o Spotlight_Lite \
Sources/main_simple.swift \
-framework Cocoa \
-framework Carbon
if [ $? -eq 0 ]; then
echo "✅ Build successful!"
echo "📦 Binary: ./Spotlight_Lite"
echo ""
echo "To run:"
echo " ./Spotlight_Lite"
echo ""
echo "⚠️ Note: This is a simplified version."
echo "For full features, install Xcode and rebuild with the original source."
else
echo "❌ Build failed!"
exit 1
fi