f267c430d9
Three features plus the design-system swap. Installer. Inno-compile.iss builds a per-user installer into %APPDATA%\ipswap with PrivilegesRequired=lowest, so it never shows a UAC prompt. That matches the app's asInvoker manifest, and it is also what lets the in-app updater replace the .exe later without elevation — a Program Files install could not. It offers a desktop shortcut and an optional start-with-Windows entry, and reuses the app's own single-instance mutex as AppMutex so setup notices a running copy, since a running .exe cannot be overwritten. Uninstall leaves presets.json, config.json and the log in place. Launching. Opening ipswap opens the editor in a browser, starting the tray first if it is not already up; if it is, the running copy opens the browser and the second process exits. internal/instance does this with a loopback control listener whose port and token live in a mode-600 session.json, plus a session-local named mutex on Windows to settle a launch race. A stale session file from a crash is detected by a failed call and treated as "no primary", so it can never wedge startup. The Run-key entry now passes --background, because a browser tab at every login is not wanted. Switching from the browser. New endpoints for active state, apply preview and apply. The browser confirms against the same before/after text the tray's MessageBox shows, built from a live read at prompt time. Apply requires the session token in a header like every other mutation — it changes the machine's network, so it is not a weaker case than editing a preset. A netsh refusal for lack of elevation comes back as 409 with a flag, so the page can point at "Relaunch as administrator" instead of showing a generic failure. To avoid two copies of that sequence, internal/switcher now owns everything between "the user said yes" and "the adapter changed", and both front ends call it. It serialises applies: two interleaved netsh sequences on one adapter would leave it matching neither preset, and there are now two ways to start one. CSS. apointless.css is vendored from bsncubed/css and left untouched; the previous file was the boarding-pass stylesheet and its class names did not match this markup. ipswap.css adds only what the design system does not ship — page chrome, tables, modals, stat tiles, a success alert — on its tokens, so re-pulling apointless.css restyles the app. Not verified: the installer is uncompiled (no Inno Setup or wine on this box) and the UI is not visually rendered (headless Firefox hangs here). Both are checked as far as the tooling allows — assets and endpoints serve, and every DOM id the JS touches exists in the markup. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
52 lines
1.4 KiB
Go
52 lines
1.4 KiB
Go
//go:build windows
|
|
|
|
package instance
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"golang.org/x/sys/windows"
|
|
)
|
|
|
|
// ErrAlreadyRunning means another instance holds the single-instance mutex.
|
|
var ErrAlreadyRunning = errors.New("another instance of ipswap is already running")
|
|
|
|
// mutexName is session-local rather than Global\: ipswap is a per-user tray
|
|
// app, and two users logged into the same machine should each get their own.
|
|
const mutexName = `Local\ipswap-single-instance`
|
|
|
|
type winLock struct{ h windows.Handle }
|
|
|
|
func (l winLock) release() {
|
|
if l.h != 0 {
|
|
windows.ReleaseMutex(l.h)
|
|
windows.CloseHandle(l.h)
|
|
}
|
|
}
|
|
|
|
// lockProcess claims the single-instance slot.
|
|
//
|
|
// CreateMutexW succeeds even when the mutex already exists, so the existing
|
|
// object is detected via GetLastError rather than the return value. The handle
|
|
// is kept for the process lifetime; Windows releases it automatically if we
|
|
// crash, which is what stops a hard kill from locking the user out.
|
|
func lockProcess() (releaser, error) {
|
|
name, err := windows.UTF16PtrFromString(mutexName)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
h, err := windows.CreateMutex(nil, false, name)
|
|
if err != nil {
|
|
if errors.Is(err, windows.ERROR_ALREADY_EXISTS) {
|
|
if h != 0 {
|
|
windows.CloseHandle(h)
|
|
}
|
|
return nil, ErrAlreadyRunning
|
|
}
|
|
return nil, fmt.Errorf("creating the single-instance mutex: %w", err)
|
|
}
|
|
return winLock{h: h}, nil
|
|
}
|