Skip tray re-register on deep-link enroll

Browser enrollment succeeds once the device is ACTIVE, but the
macOS URL handler failed whenever install re-bootstrapped a tray
LaunchAgent the PKG had already installed. Skip registration when
the plist is current, treat live bootstrap as best-effort, and
exit successfully if the device is already enrolled so retries
do not show "Enrollment failed".

Signed-off-by: Ludovic Vielle <ludovic@probo.com>
This commit is contained in:
Ludovic Vielle
2026-07-19 12:55:57 +02:00
parent 238c19d509
commit 754d12d583
3 changed files with 75 additions and 77 deletions

View File

@@ -48,14 +48,23 @@ func RegisterAutoStart(exePath string, runDir string) error {
keyPath := sid + `\` + runKeyPath
key, _, err := registry.CreateKey(registry.USERS, keyPath, registry.SET_VALUE)
key, _, err := registry.CreateKey(registry.USERS, keyPath, registry.QUERY_VALUE|registry.SET_VALUE)
if err != nil {
return fmt.Errorf("cannot open or create Run registry key for interactive user: %w", err)
}
defer func() { _ = key.Close() }()
command := fmt.Sprintf(`"%s" tray --run-dir "%s"`, exePath, runDir)
command := trayRunCommand(exePath, runDir)
existing, _, err := key.GetStringValue(runValueName)
if err == nil && existing == command {
return nil
}
if err != nil && !errors.Is(err, registry.ErrNotExist) {
return fmt.Errorf("cannot read Run registry value: %w", err)
}
if err := key.SetStringValue(runValueName, command); err != nil {
return fmt.Errorf("cannot set Run registry value: %w", err)
}
@@ -63,6 +72,10 @@ func RegisterAutoStart(exePath string, runDir string) error {
return nil
}
func trayRunCommand(exePath string, runDir string) string {
return fmt.Sprintf(`"%s" tray --run-dir "%s"`, exePath, runDir)
}
func UnregisterAutoStart() error {
sid, err := currentInteractiveUserSID()
if err != nil {