mirror of
https://github.com/fleetdm/fleet
synced 2026-05-20 15:38:39 +00:00
#15821
This PR is adding two improvements and fixing two Windows bugs in Fleet
Desktop:
## Improvement
- We are now capturing the stderr of Fleet Desktop. This helped me find
bug (1) below (otherwise the panic output below was hidden from us).
- To reduce complexity I'm removing the "Theme detection" routine
because we made the decision to use the colored icon for both themes...,
see here:
415d1f493b/orbit/cmd/desktop/desktop_windows.go (L21-L27)
## Bug fixes
1. Fleet Desktop icon not showing in the task bar. This was fixed by
updating to use the latest version of `fyne.io/systray`. (See
https://github.com/fyne-io/systray/issues/22#issuecomment-1173157898.)
2. Orbit now properly detects if Fleet Desktop isn't running on Windows.
Bug (1)'s panic output
```
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x72b14b]
goroutine 23 [running]:
fyne.io/systray.(*winTray).setTooltip(0x1eb5d40, {0x126923f?, 0x0?})
/Users/luk/gopath/pkg/mod/fyne.io/systray@v1.10.0/systray_windows.go:260 +0xcb
fyne.io/systray.SetTooltip({0x126923f?, 0x125fc16?})
/Users/luk/gopath/pkg/mod/fyne.io/systray@v1.10.0/systray_windows.go:961 +0x29
main.main.func1()
/Users/luk/fleetdm/git/fleet/orbit/cmd/desktop/desktop.go:103 +0xba
fyne.io/systray.Register.func2()
/Users/luk/gopath/pkg/mod/fyne.io/systray@v1.10.0/systray.go:98 +0x2f
created by fyne.io/systray.Register in goroutine 1
/Users/luk/gopath/pkg/mod/fyne.io/systray@v1.10.0/systray.go:96 +0xb1
```
- [X] Changes file added for user-visible changes in `changes/` or
`orbit/changes/`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [X] Manual QA for all new/changed functionality
- For Orbit and Fleet Desktop changes:
- [X] Manual QA must be performed in the three main OSs, macOS, Windows
and Linux.
- [x] Auto-update manual QA, from released version of component to new
version (see [tools/tuf/test](../tools/tuf/test/README.md)).
84 lines
2.1 KiB
Go
84 lines
2.1 KiB
Go
// Log the panic under windows to the log file
|
|
//
|
|
// Code from minix, via
|
|
//
|
|
// https://play.golang.org/p/kLtct7lSUg
|
|
|
|
//go:build windows
|
|
// +build windows
|
|
|
|
package paniclog
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"syscall"
|
|
)
|
|
|
|
var (
|
|
kernel32 = syscall.MustLoadDLL("kernel32.dll")
|
|
procSetStdHandle = kernel32.MustFindProc("SetStdHandle")
|
|
procGetStdHandle = kernel32.MustFindProc("GetStdHandle")
|
|
)
|
|
|
|
func dupFD(fd uintptr) (syscall.Handle, error) {
|
|
// Cribbed from https://github.com/golang/go/blob/go1.8/src/syscall/exec_windows.go#L303.
|
|
p, err := syscall.GetCurrentProcess()
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
var h syscall.Handle
|
|
return h, syscall.DuplicateHandle(p, syscall.Handle(fd), p, &h, 0, true, syscall.DUPLICATE_SAME_ACCESS)
|
|
}
|
|
|
|
func getStdHandle(stdHandle int32) (syscall.Handle, error) {
|
|
r0, _, e1 := syscall.Syscall(procGetStdHandle.Addr(), 2, uintptr(stdHandle), 0, 0)
|
|
rh0 := syscall.Handle(r0)
|
|
if rh0 == syscall.InvalidHandle {
|
|
if e1 != 0 {
|
|
return syscall.InvalidHandle, error(e1)
|
|
}
|
|
return syscall.InvalidHandle, syscall.EINVAL
|
|
}
|
|
return syscall.Handle(r0), nil
|
|
}
|
|
|
|
func setStdHandle(stdhandle int32, handle syscall.Handle) error {
|
|
r0, _, e1 := syscall.Syscall(procSetStdHandle.Addr(), 2, uintptr(stdhandle), uintptr(handle), 0)
|
|
if r0 == 0 {
|
|
if e1 != 0 {
|
|
return error(e1)
|
|
}
|
|
return syscall.EINVAL
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func redirectStderr(f *os.File) (UndoFunction, error) {
|
|
stderrFd, err := getStdHandle(syscall.STD_ERROR_HANDLE)
|
|
if err != nil {
|
|
return nil, errors.New("Failed to redirect stderr to file: " + err.Error())
|
|
}
|
|
|
|
// duplicate the handle to match unix behavior
|
|
fHandle, err := dupFD(f.Fd())
|
|
if err != nil {
|
|
return nil, errors.New("Failed to duplicate file: " + err.Error())
|
|
}
|
|
|
|
err = setStdHandle(syscall.STD_ERROR_HANDLE, fHandle)
|
|
if err != nil {
|
|
return nil, errors.New("Failed to redirect stderr to file: " + err.Error())
|
|
}
|
|
|
|
undo := func() error {
|
|
err := setStdHandle(syscall.STD_ERROR_HANDLE, stderrFd)
|
|
if err != nil {
|
|
return errors.New("Failed to redirect stderr to file: " + err.Error())
|
|
}
|
|
syscall.CloseHandle(fHandle)
|
|
return nil
|
|
}
|
|
|
|
return undo, nil
|
|
}
|