<commit_before>package gui

import (
	"log"

	"github.com/lxn/walk"
	"github.com/tinycedar/lily/common"
)

func newNotify(mw *walk.MainWindow) {
	ni, err := walk.NewNotifyIcon()
	if err != nil {
		common.Error("Error invoking NewNotifyIcon", err)
	}
	// defer ni.Dispose()
	icon, _ := walk.NewIconFromFile("res/lily.ico")
	if err := ni.SetIcon(icon); err != nil {
		common.Error("Error setting notify icon", err)
	}
	if err := ni.SetToolTip("Click for info or use the context menu to exit."); err != nil {
		log.Fatal(err)
	}
	ni.MouseUp().Attach(func(x, y int, button walk.MouseButton) {
		if button == walk.LeftButton {
			mw.Show()
		}
		// if err := ni.ShowCustom(
		// 	"Walk NotifyIcon Example",
		// 	"There are multiple ShowX methods sporting different icons."); err != nil {
		// 	log.Fatal(err)
		// }
	})
	exitAction := walk.NewAction()
	if err := exitAction.SetText("退出"); err != nil {
		common.Error("Error setting exitAction text", err)
	}
	exitAction.Triggered().Attach(func() { walk.App().Exit(0) })
	if err := ni.ContextMenu().Actions().Add(exitAction); err != nil {
		common.Error("Error Adding exitAction", err)
	}
	if err := ni.SetVisible(true); err != nil {
		common.Error("Error setting notify visible", err)
	}
	// if err := ni.ShowInfo("Walk NotifyIcon Example", "Click the icon to show again."); err != nil {
	// 	common.Error("Error showing info", err)
	// }
}<commit_msg>misc: Notify icon related bugfix<commit_after>package gui

import (
	"log"

	"github.com/lxn/walk"
	"github.com/tinycedar/lily/common"
)

func newNotify(mw *walk.MainWindow) {
	ni, err := walk.NewNotifyIcon()
	if err != nil {
		common.Error("Error invoking NewNotifyIcon", err)
	}
	icon, _ := walk.NewIconFromFile("res/lily.ico")
	if err := ni.SetIcon(icon); err != nil {
		common.Error("Error setting notify icon", err)
	}
	if err := ni.SetToolTip("Click for info or use the context menu to exit."); err != nil {
		log.Fatal(err)
	}
	ni.MouseUp().Attach(func(x, y int, button walk.MouseButton) {
		if button == walk.LeftButton {
			if !mw.Visible() {
				mw.Show()
			} else {
				//TODO
			}
		}
		// if err := ni.ShowCustom(
		// 	"Walk NotifyIcon Example",
		// 	"There are multiple ShowX methods sporting different icons."); err != nil {
		// 	log.Fatal(err)
		// }
	})
	exitAction := walk.NewAction()
	if err := exitAction.SetText("退出"); err != nil {
		common.Error("Error setting exitAction text", err)
	}
	exitAction.Triggered().Attach(func() {
		defer ni.Dispose()
		walk.App().Exit(0)
	})
	if err := ni.ContextMenu().Actions().Add(exitAction); err != nil {
		common.Error("Error Adding exitAction", err)
	}
	if err := ni.SetVisible(true); err != nil {
		common.Error("Error setting notify visible", err)
	}
	// if err := ni.ShowInfo("Walk NotifyIcon Example", "Click the icon to show again."); err != nil {
	// 	common.Error("Error showing info", err)
	// }
}
{'fraction_non_alphanumeric': 0.17195674921520754, 'fraction_numerical': 0.0006975933031042902, 'mean_word_length': 3.5451664025356577, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6907441', 'n_tokens_mistral': 1076, 'n_tokens_neox': 1013, 'n_words': 256}