xyxyxy_15591 (Discord #feedback) asked for a silent auto-update: once an update is in, the window shouldn't pop up. With "Restart automatically" (Settings, beside Version) on, the window state was already kept (a closed window came back as the tray icon only), and What's New stays quiet after an in-app restart. What did show was magpie taking focus: - macOS relaunched with `open -n` and no `-g`, so LaunchServices brought magpie to the front even when only the menu-bar icon came back; - with the window open, showHere's Focus() activated the app (every OS); - joining the Dock activated magpie, and with Dock on Wails' Regular policy activated it at launch. Now a restart magpie makes by itself (AutoRestart, `magpie update` from a terminal) writes a one-shot restart-quiet mark (read once, good for 10 minutes). The next start reads it: `open -n -g`, no Focus(), the Dock joined without activating, Accessory policy at launch and the Dock set afterwards. A restart the user clicks removes any mark and comes to the front as before. `open` gets -g also whenever no window is wanted. No new setting: zero-config, the existing switch is the one asked for. Run (base841326709, rebased onced880ef0, no upstream change to these files): - mote: gofmt -l clean; go vet ./internal/gui ./internal/update ./internal/cli; GOOS=linux go vet -tags nogui ./...; GOOS=windows go vet on gui/update/cli: clean. internal/update ok; TestRestartBySelfComesBackQuietly, TestUpdateThatWontStart, TestWhatsNew*, *Handover* ok, except TestHandoverLeavesTheMenuBarIconForTheNextMagpie, killed at 30s the same at origin/main7b09d2c95(AppKit on mote, #4125). - Windows (win-run, CGO_ENABLED=0): internal/update ok; internal/gui reds the same set as origin/main7b09d2c95(#4115, #1827, #2958, #4514). - WSL (wsl-run): full `go test -tags nogui -timeout 45m ./...`, 80 ok; reds TestInstalledVersion, TestGrokInstalled, TestOmpDetectedWithPiDir (#4033, #3548), TestNoCommandBypassesProc (#4491), TestSettingsSaveKeepsWhatItDoesNotSend (#4514) all red the same at origin/main 7b09d2c95; TestColdTurnsTaken (#4510) passed there alone. internal/gui + internal/update rerun at this head: internal/update ok; internal/gui red only TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and TestColdTurnsTaken (#4510). Broken by hand: without -g, TestRelaunchOpen and TestRelaunchOpenTriedAgain fail; without markQuietRestart, TestRestartBySelfComesBackQuietly fails "window true: the start after a restart by itself isn't quiet"; without the unmark on a clicked restart, it fails "a restart the user asked for is marked quiet". Not tried: a real update restart on any OS (`open` of a GUI app over ssh on mote fails, RBSRequestErrorDomain 5), so -g and no-focus weren't seen in a real session. Windows' ShowWindow inside Wails may still bring the window forward when it was open; Linux window managers were not tried. No GUI assets changed, so no Playwright run.
63 lines
2.3 KiB
Go
63 lines
2.3 KiB
Go
package update
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// A Mac restart by itself with no window up opens the app as a login launch
|
|
// does, its menu bar icon only (#2096); one with the window opens it. Both
|
|
// ask for a new instance (-n), so LaunchServices launches the bundle rather
|
|
// than send a reopen to the magpie that has just exited (Linka's -600).
|
|
//
|
|
// Only a restart the user asked for, with its window coming back, brings
|
|
// magpie to the front. One magpie made by itself (quiet), or one with only
|
|
// the menu bar icon to come back, opens in the background (-g): without
|
|
// it, Settings' AutoRestart took the focus from the app the user was
|
|
// typing in (xyxyxy_15591 on Discord).
|
|
func TestRelaunchOpen(t *testing.T) {
|
|
const app = "/Applications/magpie.app"
|
|
for _, c := range []struct {
|
|
window, quiet bool
|
|
want string
|
|
}{
|
|
{true, false, `open -n "/Applications/magpie.app"`},
|
|
{true, true, `open -n -g "/Applications/magpie.app"`},
|
|
{false, false, `open -n -g "/Applications/magpie.app" --args tray`},
|
|
{false, true, `open -n -g "/Applications/magpie.app" --args tray`},
|
|
} {
|
|
if got := relaunchOpen(app, c.window, c.quiet); got != c.want {
|
|
t.Errorf("relaunch, window %v quiet %v: %s, want %s", c.window, c.quiet, got, c.want)
|
|
}
|
|
// a restart that hands the gateway over opens the new version
|
|
// while this one runs: a new instance (-n), which LaunchServices
|
|
// would otherwise send to the one running, as quiet as Relaunch's
|
|
if got := openBeside(app, c.window, c.quiet); got != c.want {
|
|
t.Errorf("beside, window %v quiet %v: %s, want %s", c.window, c.quiet, got, c.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// The new version a handover starts isn't told to wait for this one to
|
|
// exit (it would wait while this one waits for it), and gets the args
|
|
// RelaunchBinary gives.
|
|
func TestStartBesideWaitsForNothing(t *testing.T) {
|
|
t.Setenv("MAGPIE_REPLACES", "")
|
|
var gotArgs, gotEnv []string
|
|
stubLaunch(t, func(exe string, args, env []string) (<-chan struct{}, func(), error) {
|
|
gotArgs, gotEnv = args, env
|
|
return nil, nil, nil
|
|
})
|
|
if err := StartBeside("/opt/magpie", true, "routing"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if strings.Join(gotArgs, " ") != "gui routing" {
|
|
t.Errorf("args %q", gotArgs)
|
|
}
|
|
for _, e := range gotEnv {
|
|
if strings.HasPrefix(e, "MAGPIE_REPLACES=") && e != "MAGPIE_REPLACES=" {
|
|
t.Errorf("told to wait: %s", e)
|
|
}
|
|
}
|
|
}
|