fix(mobile): remember custom pairing addresses (#11741)

* fix(mobile): remember custom pairing address

* fix(mobile): stabilize custom pairing address sync

* fix(mobile): update pairing refresh refs after commit

* feat(mobile): manage saved custom pairing addresses

* fix(mobile): harden custom address selection
This commit is contained in:
Brennan Benson
2026-07-31 13:03:11 -07:00
committed by GitHub
parent 129d8b32bb
commit e698241aab
26 changed files with 1523 additions and 141 deletions
+5
View File
@@ -27,6 +27,11 @@ describe('getDefaultSettings', () => {
expect(getDefaultSettings('/tmp').sourceControlGroupOrder).toBe('changes-first')
})
it('defaults mobile pairing to discovered network addresses', () => {
expect(getDefaultSettings('/tmp').mobilePairingCustomAddress).toBeNull()
expect(getDefaultSettings('/tmp').mobilePairingCustomAddresses).toEqual([])
})
it('keeps first-work branch auto-renaming on by default for new settings', () => {
expect(getDefaultSettings('/tmp').autoRenameBranchFromWork).toBe(true)
expect(getDefaultSettings('/tmp').autoRenameBranchFromWorkDefaultedOn).toBe(true)
+2
View File
@@ -351,6 +351,8 @@ export function getDefaultSettings(homedir: string): GlobalSettings {
mobileAutoRestoreFitMs: null,
// Why: Anywhere (Relay + local) is the default; local-only is written only on explicit same-network choice.
mobilePairingConnectionMode: 'automatic',
mobilePairingCustomAddress: null,
mobilePairingCustomAddresses: [],
// Why: off keeps the cosmetic overlay unmounted for users who never opt in.
experimentalPet: false,
experimentalActivity: false,
@@ -0,0 +1,54 @@
import { describe, expect, it } from 'vitest'
import {
MAX_MOBILE_PAIRING_CUSTOM_ADDRESSES,
addMobilePairingCustomAddress,
normalizeMobilePairingCustomAddress,
normalizeMobilePairingCustomAddresses,
removeMobilePairingCustomAddress
} from './mobile-pairing-custom-address'
describe('normalizeMobilePairingCustomAddress', () => {
it('keeps a valid custom address', () => {
expect(normalizeMobilePairingCustomAddress(' 100.126.117.25:6768 ')).toBe('100.126.117.25:6768')
})
it.each([null, undefined, 42, '', '0.0.0.0', 'host:99999'])(
'clears an invalid persisted value: %s',
(value) => {
expect(normalizeMobilePairingCustomAddress(value)).toBeNull()
}
)
})
describe('mobile pairing custom address collection', () => {
it('normalizes, deduplicates, and drops invalid entries', () => {
expect(
normalizeMobilePairingCustomAddresses([
' first.example:6768 ',
'host:99999',
'first.example:6768',
'second.example:6768'
])
).toEqual(['first.example:6768', 'second.example:6768'])
})
it('bounds persisted entries', () => {
const addresses = Array.from(
{ length: MAX_MOBILE_PAIRING_CUSTOM_ADDRESSES + 5 },
(_, index) => `host-${index}.example:6768`
)
expect(normalizeMobilePairingCustomAddresses(addresses)).toHaveLength(
MAX_MOBILE_PAIRING_CUSTOM_ADDRESSES
)
})
it('adds the newest address and removes a saved address', () => {
expect(addMobilePairingCustomAddress(['first.example'], ' second.example ')).toEqual([
'first.example',
'second.example'
])
expect(
removeMobilePairingCustomAddress(['first.example', 'second.example'], 'first.example')
).toEqual(['second.example'])
})
})
@@ -0,0 +1,53 @@
import { parseManualNetworkAddress } from './network/manual-address'
export const MAX_MOBILE_PAIRING_CUSTOM_ADDRESSES = 50
export function normalizeMobilePairingCustomAddress(value: unknown): string | null {
if (typeof value !== 'string') {
return null
}
const parsed = parseManualNetworkAddress(value)
return parsed.ok ? parsed.address : null
}
export function normalizeMobilePairingCustomAddresses(value: unknown): string[] {
if (!Array.isArray(value)) {
return []
}
const normalized: string[] = []
for (const candidate of value) {
const address = normalizeMobilePairingCustomAddress(candidate)
if (address && !normalized.includes(address)) {
normalized.push(address)
}
if (normalized.length === MAX_MOBILE_PAIRING_CUSTOM_ADDRESSES) {
break
}
}
return normalized
}
export function addMobilePairingCustomAddress(
addresses: readonly string[],
value: string
): string[] {
const address = normalizeMobilePairingCustomAddress(value)
if (!address) {
return normalizeMobilePairingCustomAddresses(addresses)
}
const normalized = normalizeMobilePairingCustomAddresses(addresses)
if (normalized.includes(address)) {
return normalized
}
return [...normalized, address].slice(-MAX_MOBILE_PAIRING_CUSTOM_ADDRESSES)
}
export function removeMobilePairingCustomAddress(
addresses: readonly string[],
value: string
): string[] {
const address = normalizeMobilePairingCustomAddress(value)
return normalizeMobilePairingCustomAddresses(addresses).filter(
(candidate) => candidate !== address
)
}
+4
View File
@@ -3002,6 +3002,10 @@ export type GlobalSettings = {
/** Preferred mobile pairing path for new QR codes. Missing/'automatic' = Anywhere (Relay + local);
* explicit 'local-only' = same-network only. */
mobilePairingConnectionMode?: 'automatic' | 'local-only'
/** Explicit custom address restored when generating future mobile pairing codes. */
mobilePairingCustomAddress?: string | null
/** Saved custom addresses available in both mobile pairing pickers. */
mobilePairingCustomAddresses?: string[]
/** Experimental: floating animated pet in the bottom-right corner. Opt-in cosmetic;
* off never mounts the overlay, and toggling takes effect instantly (renderer-side). */
experimentalPet: boolean