85 lines
2.3 KiB
Go
85 lines
2.3 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"razer/utils"
|
|
|
|
"github.com/karalabe/hid"
|
|
"github.com/progrium/darwinkit/macos/appkit"
|
|
"github.com/progrium/darwinkit/objc"
|
|
)
|
|
|
|
func main() {
|
|
if !hid.Supported() {
|
|
log.Fatal("HID 不支持")
|
|
}
|
|
|
|
objc.WithAutoreleasePool(func() {
|
|
app := appkit.Application_SharedApplication()
|
|
app.SetActivationPolicy(appkit.ApplicationActivationPolicyAccessory)
|
|
|
|
utils.SetupStatusBar(app)
|
|
|
|
app.ActivateIgnoringOtherApps(true)
|
|
app.Run()
|
|
})
|
|
}
|
|
|
|
//// --- UI 逻辑:支持动态刷新 ---
|
|
//func updateMenu(menu appkit.Menu, app appkit.Application) {
|
|
// // 1. 清空旧菜单
|
|
// menu.RemoveAllItems()
|
|
//
|
|
// // 2. 重新扫描设备
|
|
// devices := utils.ScanDevices()
|
|
//
|
|
// // 3. 添加刷新按钮 (放在最上面)
|
|
// refreshItem := appkit.NewMenuItemWithAction("🔄 刷新设备列表", "r", func(sender objc.Object) {
|
|
// updateMenu(menu, app) // 递归调用刷新自身
|
|
// })
|
|
// menu.AddItem(refreshItem)
|
|
// menu.AddItem(appkit.MenuItem_SeparatorItem())
|
|
//
|
|
// // 4. 构建设备列表
|
|
// if len(devices) == 0 {
|
|
// none := appkit.NewMenuItemWithAction("未发现雷蛇设备", "", func(sender objc.Object) {})
|
|
// none.SetEnabled(false)
|
|
// menu.AddItem(none)
|
|
// } else {
|
|
// for _, dev := range devices {
|
|
// devTitle := appkit.NewMenuItemWithAction("设备: "+dev.Name, "", func(sender objc.Object) {})
|
|
// devTitle.SetEnabled(false)
|
|
// menu.AddItem(devTitle)
|
|
//
|
|
// menu.AddItem(appkit.NewMenuItemWithAction(" 🔴 设为红色", "", func(sender objc.Object) {
|
|
// //dev.ApplyStaticColor(0xFF, 0x00, 0x00)
|
|
// }))
|
|
//
|
|
// menu.AddItem(appkit.NewMenuItemWithAction(" 🟢 设为绿色", "", func(sender objc.Object) {
|
|
// //dev.ApplyStaticColor(0x00, 0xFF, 0x00)
|
|
// }))
|
|
//
|
|
// menu.AddItem(appkit.MenuItem_SeparatorItem())
|
|
// }
|
|
// }
|
|
//
|
|
// // 5. 退出按钮
|
|
// menu.AddItem(appkit.NewMenuItemWithAction("退出", "q", func(sender objc.Object) {
|
|
// app.Terminate(nil)
|
|
// }))
|
|
//}
|
|
|
|
//func setupStatusBar(app appkit.Application) {
|
|
// // 创建状态栏项
|
|
// item := appkit.StatusBar_SystemStatusBar().StatusItemWithLength(appkit.VariableStatusItemLength)
|
|
// objc.Retain(&item)
|
|
//
|
|
// img := appkit.Image_ImageWithSystemSymbolNameAccessibilityDescription("keyboard", "Razer Tool")
|
|
// item.Button().SetImage(img)
|
|
//
|
|
// // 创建初始菜单
|
|
// menu := appkit.NewMenuWithTitle("Razer")
|
|
// updateMenu(menu, app) // 初始填充菜单项
|
|
// item.SetMenu(menu)
|
|
//}
|