package main import ( "Win2Linux/pkg/bcdedit" "Win2Linux/pkg/windows" _ "embed" "fmt" "os" "Win2Linux/pkg/errors" "github.com/getlantern/systray" ) //go:generate go-winres make const ( GeneralFailure int32 = 0x01 ) //go:embed tray.ico var icon []byte type () func main() { systray.Run(onReady, onExit) } func onReady() { systray.SetTitle("Win2Linux") systray.SetTooltip("Switch from Windows to Linux") systray.SetIcon(icon) entries, err := bcdedit.List() if err != nil { if wErr, ok := err.(*errors.WinError); ok { windows.Fatal("Win2Linux", fmt.Sprintf("error: %s", err), int(wErr.ExitCode())) } else { windows.Fatal("Win2Linux", fmt.Sprintf("error: %s", err), 1) } } for _, entry := range entries { fmt.Println(entry.Attributes) key := entry.Key uuid := entry.Attributes["identifier"] if desc, ok := entry.Attributes["description"]; ok { key = desc } mCustom := systray.AddMenuItem(key, "Switch to"+key) go func() { for { <-mCustom.ClickedCh if uuid == "{fwbootmgr}" { err := bcdedit.RebootToFirmware() if err != nil { if wErr, ok := err.(*errors.WinError); ok { windows.Fatal("Win2Linux", fmt.Sprintf("error: %s", err), int(wErr.ExitCode())) } else { windows.Fatal("Win2Linux", fmt.Sprintf("error: %s", err), 1) } } return } err := bcdedit.Reboot(uuid) if err != nil { if wErr, ok := err.(*errors.WinError); ok { windows.Fatal("Win2Linux", fmt.Sprintf("error: %s", err), int(wErr.ExitCode())) } else { windows.Fatal("Win2Linux", fmt.Sprintf("error: %s", err), 1) } } } }() } systray.AddSeparator() mQuit := systray.AddMenuItem("Quit", "Quit") go func() { <-mQuit.ClickedCh os.Exit(0) }() } func onExit() { // clean up here }