try out sync.Once

This commit is contained in:
Jeff Carr 2025-03-03 23:50:11 -06:00
parent 54bbe72aa8
commit 6127fa1cbb
3 changed files with 10 additions and 11 deletions

View File

@ -73,9 +73,9 @@ func toolkitInit() {
me.BG.tk = makeNewInternalWidget(me.BG.wId)
}
// SETUP libnotify
makeNotifyClock(me.notify.clock.wId)
makeNotifyMenu(me.notify.menu.wId)
// SETUP libnotify clock and menu
me.notify.clock.once.Do(makeNotifyClock)
me.notify.menu.once.Do(makeNotifyMenu)
// PUT INIT DEBUG COOE HERE
var toggle bool

View File

@ -1,10 +1,8 @@
// Copyright 2014 The gocui Authors. All rights reserved.
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// this file implements a libnotify-like menu
// also there is SIGWINCH resizing
package main
import (
@ -52,12 +50,12 @@ func makeNewInternalWidget(wId int) *guiWidget {
return tk
}
func makeNotifyClock(wId int) {
func makeNotifyClock() {
if me.treeRoot == nil {
log.Info("gogui makeClock() error. treeRoot == nil")
return
}
me.notify.clock.tk = makeNewInternalWidget(wId)
me.notify.clock.tk = makeNewInternalWidget(me.notify.clock.wId)
me.notify.clock.tk.dumpWidget("init() clock")
me.notify.clock.tk.MoveToOffset(0, 0)
me.notify.clock.tk.labelN = time.Now().Format("15:04:05")
@ -69,12 +67,12 @@ func makeNotifyClock(wId int) {
}
func makeNotifyMenu(wId int) {
func makeNotifyMenu() {
if me.treeRoot == nil {
log.Info("gogui makeClock() error. treeRoot == nil")
return
}
me.notify.menu.tk = makeNewInternalWidget(wId)
me.notify.menu.tk = makeNewInternalWidget(me.notify.menu.wId)
me.notify.menu.tk.dumpWidget("init() menu")
w, _ := me.baseGui.Size()
me.notify.menu.tk.MoveToOffset(w-5, me.notify.menu.offsetH)

View File

@ -138,6 +138,7 @@ type dropdown struct {
// settings for the dropdown window
type internalTK struct {
once sync.Once // for init
tk *guiWidget // where to show STDOUT
callerTK *guiWidget // which widget called the dropdown menu
wId int // the widget id to use