A: MacOS 添加 touch bar 支持

This commit is contained in:
zhangli10 2023-12-04 19:20:21 +08:00
parent 86d549ae37
commit e62ddd4d35
2 changed files with 47 additions and 50 deletions

View File

@ -10,7 +10,7 @@ func MakeCatalog(switcher barutils.Switcher, update func()) barbuilder.Item {
fmt.Println("MakeCatalog")
// TODO: showcase Escape
return barutils.VirtualPopover(barbuilder.Popover{
CollapsedText: "Catalog",
CollapsedText: "目录",
CollapsedImage: barbuilder.TBBookmarksTemplate,
Bar: []barbuilder.Item{
&barbuilder.Label{

View File

@ -7,7 +7,6 @@ import (
"github.com/energye/energy/v2/pkgs/touchbar"
"github.com/energye/energy/v2/pkgs/touchbar/barbuilder"
"github.com/energye/energy/v2/pkgs/touchbar/barutils"
"github.com/energye/golcl/lcl"
)
func main() {
@ -17,57 +16,55 @@ func main() {
app := cef.NewApplication()
app.SetUseMockKeyChain(true)
cef.BrowserWindow.Config.Url = "https://www.baidu.com"
var tb barbuilder.TouchBar
cef.BrowserWindow.SetBrowserInit(func(event *cef.BrowserEvent, window cef.IBrowserWindow) {
var tbar = func() {
tb := touchbar.New(barbuilder.Options{
EventErrorLogger: func(err error) {
fmt.Println("EventErrorLogger", err)
},
})
makeUpdater := func(switcher barutils.Switcher) func() {
return func() {
fmt.Println("makeUpdater")
err := switcher.Update()
if err != nil {
fmt.Printf("could not update: %v\n", err)
}
}
}
config := barutils.MakeStackableBar(tb, func(switcher barutils.Switcher) []barbuilder.Item {
update := makeUpdater(switcher)
fmt.Println("MakeStackableBar")
return []barbuilder.Item{
&barbuilder.Label{
Content: &barbuilder.ContentLabel{
Text: "Go Touch Bar",
},
},
&barbuilder.SpaceLarge{},
bar.MakeDemo(update),
&barbuilder.SpaceSmall{},
bar.MakeCatalog(switcher, update),
}
})
err := tb.Install(config)
fmt.Println("install err", err)
if err != nil {
panic(err)
}
// end
//err = tb.Uninstall()
//if err != nil {
// panic(err)
//}
}
window.AsLCLBrowserWindow().BrowserWindow().SetOnShow(func(sender lcl.IObject) bool {
tbar()
return false
tb = touchbar.New(barbuilder.Options{
EventErrorLogger: func(err error) {
fmt.Println("EventErrorLogger", err)
},
})
makeUpdater := func(switcher barutils.Switcher) func() {
return func() {
fmt.Println("makeUpdater")
err := switcher.Update()
if err != nil {
fmt.Printf("could not update: %v\n", err)
}
}
}
config := barutils.MakeStackableBar(tb, func(switcher barutils.Switcher) []barbuilder.Item {
update := makeUpdater(switcher)
fmt.Println("MakeStackableBar")
return []barbuilder.Item{
&barbuilder.Label{
Content: &barbuilder.ContentLabel{
Text: "Go Touch Bar",
},
},
&barbuilder.SpaceLarge{},
bar.MakeDemo(update),
&barbuilder.SpaceSmall{},
bar.MakeCatalog(switcher, update),
}
})
err := tb.Install(config)
fmt.Println("install err", err)
if err != nil {
panic(err)
}
})
//run application
cef.Run(app)
if tb != nil {
fmt.Println("tb Uninstall")
// end
err := tb.Uninstall()
if err != nil {
panic(err)
}
}
}