The Windows app cross-compiles (WebView2, no cgo) as a GUI program with an icon, version info and a DPI-aware manifest; run from a terminal with a command it borrows the console. The Linux app links GTK 3 and WebKitGTK 4.1. Off the Mac the app updates its own binary from its own build: downloaded in the background, swapped in on restart or quit, and the relaunched process waits for the old one before taking the gateway. The window leaves room for traffic lights only on a Mac.
32 lines
935 B
Go
32 lines
935 B
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"syscall"
|
|
)
|
|
|
|
// The desktop build is linked as a GUI program so double-clicking it opens
|
|
// no console window; such a program starts with no standard streams. When it
|
|
// is run from a terminal with a command, borrow that terminal's console so
|
|
// `magpie ls` and friends still print. Output that is redirected already has
|
|
// somewhere to go and is left alone.
|
|
func init() {
|
|
if len(os.Args) < 2 {
|
|
return
|
|
}
|
|
if t, err := syscall.GetFileType(syscall.Stdout); err == nil && t != 0 {
|
|
return // FILE_TYPE_UNKNOWN is 0: nothing attached
|
|
}
|
|
const attachParentProcess = ^uintptr(0) // (DWORD)-1
|
|
r, _, _ := syscall.NewLazyDLL("kernel32.dll").NewProc("AttachConsole").Call(attachParentProcess)
|
|
if r == 0 {
|
|
return
|
|
}
|
|
if out, err := os.OpenFile("CONOUT$", os.O_RDWR, 0); err == nil {
|
|
os.Stdout, os.Stderr = out, out
|
|
}
|
|
if in, err := os.OpenFile("CONIN$", os.O_RDWR, 0); err == nil {
|
|
os.Stdin = in
|
|
}
|
|
}
|