Add installer, launch-to-browser, and switching from the web GUI

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>
This commit is contained in:
2026-08-20 14:32:15 +10:00
parent a8bbf91223
commit f267c430d9
21 changed files with 2330 additions and 565 deletions
+61
View File
@@ -0,0 +1,61 @@
// Command devserver runs the editor server alone, against a throwaway preset
// file, so the web UI can be opened during development on a non-Windows box.
//
// It is a development aid, not part of the shipped product: the real server is
// started on demand by the tray.
package main
import (
"flag"
"fmt"
"log"
"os"
"path/filepath"
"gitea.apointless.space/bsncubed/ipswap/internal/config"
"gitea.apointless.space/bsncubed/ipswap/internal/netcfg"
"gitea.apointless.space/bsncubed/ipswap/internal/preset"
"gitea.apointless.space/bsncubed/ipswap/internal/server"
"gitea.apointless.space/bsncubed/ipswap/internal/switcher"
)
func main() {
dir := flag.String("dir", "", "data directory (default: a temp dir seeded with examples/preset-pack.json)")
flag.Parse()
d := *dir
if d == "" {
var err error
d, err = os.MkdirTemp("", "ipswap-dev-")
if err != nil {
log.Fatal(err)
}
seed, err := os.ReadFile(filepath.Join("examples", "preset-pack.json"))
if err == nil {
_ = os.WriteFile(filepath.Join(d, "presets.json"), seed, 0o644)
}
}
paths := config.Paths{
Dir: d,
Presets: filepath.Join(d, "presets.json"),
Config: filepath.Join(d, "config.json"),
Log: filepath.Join(d, "ipswap.log"),
}
store, err := preset.NewStore(paths.Presets)
if err != nil {
log.Fatal(err)
}
mgr := netcfg.New()
srv := server.New(store, switcher.New(store, mgr), mgr, paths, config.Default())
url, err := srv.Start()
if err != nil {
log.Fatal(err)
}
fmt.Println(url)
select {} // serve until killed
}
+39 -5
View File
@@ -8,6 +8,7 @@
package main
import (
"errors"
"flag"
"fmt"
"log"
@@ -18,9 +19,11 @@ import (
"gitea.apointless.space/bsncubed/ipswap/internal/config"
"gitea.apointless.space/bsncubed/ipswap/internal/desktop"
"gitea.apointless.space/bsncubed/ipswap/internal/elevate"
"gitea.apointless.space/bsncubed/ipswap/internal/instance"
"gitea.apointless.space/bsncubed/ipswap/internal/netcfg"
"gitea.apointless.space/bsncubed/ipswap/internal/preset"
"gitea.apointless.space/bsncubed/ipswap/internal/server"
"gitea.apointless.space/bsncubed/ipswap/internal/switcher"
"gitea.apointless.space/bsncubed/ipswap/internal/tray"
)
@@ -29,6 +32,7 @@ var version = "dev"
func main() {
showVersion := flag.Bool("version", false, "print the version and exit")
background := flag.Bool("background", false, "start the tray without opening the editor (used by the start-with-Windows entry)")
flag.Parse()
if *showVersion {
@@ -36,14 +40,14 @@ func main() {
return
}
if err := run(); err != nil {
if err := run(*background); err != nil {
// With -H windowsgui there is no stderr to read, so anything fatal has
// to be shown rather than printed.
fatal(err)
}
}
func run() error {
func run(background bool) error {
paths, err := config.ResolvePaths()
if err != nil {
return err
@@ -57,7 +61,20 @@ func run() error {
}
defer logw.Close()
log.Printf("--- %s %s starting (elevated=%v) ---", config.AppName, version, elevate.IsElevated())
log.Printf("--- %s %s starting (elevated=%v, background=%v) ---",
config.AppName, version, elevate.IsElevated(), background)
// Opening ipswap when it is already running should show the editor, not
// start a second tray icon. Hand the request to the running copy and stop.
if background {
if instance.IsRunning(paths) {
log.Printf("another instance is already running; exiting")
return nil
}
} else if err := instance.Signal(paths); err == nil {
log.Printf("another instance is running; it will open the editor")
return nil
}
settings, err := config.Load(paths.Config)
if err != nil {
@@ -81,8 +98,25 @@ func run() error {
}
mgr := netcfg.New()
srv := server.New(store, mgr, paths, settings)
app := tray.New(store, mgr, srv, paths, settings, version)
sw := switcher.New(store, mgr)
srv := server.New(store, sw, mgr, paths, settings)
app := tray.New(store, sw, srv, paths, settings, version)
app.OpenOnStart = !background
// Claim the single-instance slot and publish the control address, so a
// later launch can find this process instead of starting its own tray.
primary, err := instance.Acquire(paths, app.OpenEditor)
if err != nil {
if errors.Is(err, instance.ErrAlreadyRunning) {
// Lost a race with a simultaneous launch. That copy owns the tray;
// let it open the editor.
log.Printf("lost the single-instance race; deferring to the other process")
_ = instance.Signal(paths)
return nil
}
return err
}
defer primary.Release()
// systray.Run takes over this goroutine and does not return until Exit.
app.Run()