fix(linux): a refusal to start is shown, not written to nobody
fatalBox off Windows was a single println. That goes to stderr, and a
binary started from a file manager or a .desktop launcher has no stderr
anyone will read — so a carefully worded refusal ("the folder OpsLog
keeps everything in cannot be written to…") reached the operator as "I
click it and nothing happens", which is the least useful thing a program
can say.
It now opens a dialog through zenity or kdialog when either is present —
both ship with every distribution's desktop task — and writes to stderr
either way. Neither is required: the startup log already carries the
same text, and nothing here may stop OpsLog from exiting.
This commit is contained in:
+35
-2
@@ -2,5 +2,38 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
// fatalBox is Windows-only; elsewhere the terminal carries the message.
|
import (
|
||||||
func fatalBox(title, text string) { println(title + ": " + text) }
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
)
|
||||||
|
|
||||||
|
// fatalBox says why OpsLog is not starting, as visibly as the desktop allows.
|
||||||
|
//
|
||||||
|
// It used to be one println. That goes to stderr, and a binary started from a
|
||||||
|
// file manager or a .desktop launcher has no stderr anybody will ever read — so
|
||||||
|
// the refusal that was carefully worded arrived as "I click it and nothing
|
||||||
|
// happens", which is the least useful thing a program can say.
|
||||||
|
//
|
||||||
|
// So: a real dialog when the desktop has one of the two tools that every
|
||||||
|
// distribution ships with its desktop task, and stderr regardless. Neither is
|
||||||
|
// required — the startup log has the same text, and nothing here is allowed to
|
||||||
|
// stop OpsLog from exiting.
|
||||||
|
func fatalBox(title, text string) {
|
||||||
|
os.Stderr.WriteString(title + ": " + text + "\n")
|
||||||
|
for _, c := range [][]string{
|
||||||
|
{"zenity", "--error", "--no-wrap", "--title", title, "--text", text},
|
||||||
|
{"kdialog", "--title", title, "--error", text},
|
||||||
|
// Neither is a hard requirement, and on a headless box there is nothing
|
||||||
|
// to show a dialog on anyway.
|
||||||
|
} {
|
||||||
|
if _, err := exec.LookPath(c[0]); err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
cmd := exec.Command(c[0], c[1:]...)
|
||||||
|
if err := cmd.Start(); err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
_ = cmd.Wait()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user