singleinstance

package
v0.12.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package singleinstance enforces a single running instance of an app and forwards a later launch's args to the primary (e.g. to focus a window or handle a deep link) instead of starting a second backend. Pure Go and cross-platform: it uses a per-app loopback address; the first instance to bind it is primary, and later instances connect and forward. An ACK handshake ensures an unrelated program on the same port is never mistaken for our primary.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Instance

type Instance struct {
	// contains filtered or unexported fields
}

Instance is the primary's handle; Close releases the lock.

func Acquire

func Acquire(appID string, args []string, onSecondary func(args []string)) (*Instance, bool, error)

Acquire attempts to become the primary instance for appID. If it succeeds it returns (instance, true, nil) and begins listening. If another instance holds the lock, it forwards args to it and returns (nil, false, nil) — the caller should exit. On error the caller should start normally (single-instance best effort).

func (*Instance) Close

func (i *Instance) Close() error

Close releases the single-instance lock.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL