Skip to content

armgit / nota

Public Imported from GitHub
0

Nota — a free DAW for macOS, Windows and Linux. No subscription, no account — just open it and make music.

(feat) Nota Remote: choose the address in the link and QR (#85) (#576)

Asish0741084548a9
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 26efda08..eac8b602 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -23,6 +23,16 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.
## [Unreleased]
### Added
+- **Choose the address Nota Remote shows** (#85, specs/095). On a computer with several
+ networks (Wi-Fi and Ethernet, a VPN, a virtual machine's network), Nota could put an address
+ in the QR code that the phone can't reach. Now you can choose it.
+ - **Settings → Remote → Address in the QR**: Automatic (as before: USB, then Wi-Fi, then
+ Ethernet) or one network interface. The choice is kept after a restart, by the
+ interface's name. While that interface is down, Automatic stands in, and the list says so.
+ - **Connect phone**: the other addresses under the main one take a click, which puts that
+ address in the link and QR code; **Automatic** under them goes back.
+ - Next to the address, **Open in the browser** opens the Remote page on this computer, and
+ **Copy the link** copies it.
- **A Modular tab in the browser** (#592, specs/095). While Modular is the view the browser's
rail carries a **Modular** tab (a patch-cable icon, after MIDI effects) listing every node
Modular offers — LFO, Envelope Follower, MIDI → CV, ADSR, Macro, Math, Scope — with its
diff --git a/FEATURES.md b/FEATURES.md
index 732d42f4..16ca7bb7 100644
--- a/FEATURES.md
+++ b/FEATURES.md
@@ -585,6 +585,10 @@ docks as a panel under any of the three, or floats in its own window — see
permissions (play only / play and control) in **Settings → Remote**. Phone notes record like
the computer keyboard's; knobs and XY axes map through MIDI Learn (XY and tilt per track);
several phones play at once, each on its own track, with players' names on the tracks.
+ On a computer with several networks, the address in the link and QR is chosen
+ automatically (USB, then Wi-Fi, then Ethernet) or by hand, in Settings → Remote or with a
+ click on another address in Connect phone; the link opens in the browser or copies with a
+ click.
- **Nota Remote in Nota's theme**: the phone wears the colour theme Nota wears and follows
every change live (including Follow system); **Follow phone** (⋯ → Theme) wears the
In dark mode / In light mode themes by the phone's own scheme. Its screens follow the
diff --git a/specs/095-remote-interface-pick/plan.md b/specs/095-remote-interface-pick/plan.md
new file mode 100644
index 00000000..44887f93
--- /dev/null
+++ b/specs/095-remote-interface-pick/plan.md
@@ -0,0 +1,42 @@
+# Implementation Plan: Nota Remote — choose the network interface for the link and QR
+
+**Branch**: `095-remote-interface-pick` | **Date**: 2026-11-11 | **Spec**: [spec.md](spec.md)
+
+## Summary
+
+Links carry their interface's name; a pure `RemoteLinks.Pick` chooses the link for the QR from
+the `RemoteInterface` setting. Settings → Remote gets an **Address in the QR** list; Connect
+phone makes the other addresses clickable and adds open-in-browser and copy keys.
+
+## Technical Context
+
+**Language/Version**: C# / .NET 10, Avalonia.
+
+**Primary Dependencies**: none new.
+
+**Audio-Thread Impact**: none.
+
+**Testing**: `RemoteTests` (`-- --remote` alone): Automatic, a chosen interface, an interface
+with two addresses, a chosen interface that is down, no network.
+
+## Design
+
+- `RemoteLink` gains `Interface` (`NetworkInterface.Name`), filled by `RemoteLinks.All`.
+- `RemoteLinks.Pick(links, chosen)`: the first link of `chosen`, else `links[0]`, else null.
+- `Settings.RemoteInterface` (string?, null = Automatic).
+- `RemoteService.Link` = `Pick(Links, RemoteInterface)`; `Url` (and so `QrText`) use it;
+ `ChooseInterface(iface)` stores the setting, saves and raises `Changed`, which rebuilds the
+ popup and refreshes the Settings page.
+- `ConnectPhoneView`: the main address is `Link`'s, with the USB pill when it is the cable
+ link and two glyph keys — `PopOut` (launch the URL through the main window's `Launcher`) and
+ `Copy` (the main window's clipboard; a `Check` for 1.5 s). Every other link is a dim row with
+ a hand cursor that chooses its interface; an **Automatic** row appears once a choice is set.
+ The rebuild signature includes the choice.
+- `PreferencesWindow.Remote`: an **Address in the QR** row under the port — a `Combo` of
+ Automatic, one entry per interface and, when the chosen one is down, a disabled "not
+ connected" entry (like Settings → Outputs' missing pairs). Rebuilt only when the addresses or
+ the choice change, so an open list survives the page's other refreshes.
+
+## Constitution Check
+
+UI and settings only; no engine, ABI or format change. Texts through `Loc`.
diff --git a/specs/095-remote-interface-pick/spec.md b/specs/095-remote-interface-pick/spec.md
new file mode 100644
index 00000000..02093683
--- /dev/null
+++ b/specs/095-remote-interface-pick/spec.md
@@ -0,0 +1,120 @@
+# Feature Specification: Nota Remote — choose the network interface for the link and QR
+
+**Feature Branch**: `095-remote-interface-pick`
+
+**Created**: 2026-11-11
+
+**Status**: Implemented
+
+**Input**: GitHub issue nota-daw/nota#85: "Connect a phone to Nota Remote on a machine with several
+network interfaces (Wi-Fi + Ethernet, a VPN, a VM/Docker bridge, USB tethering, a second LAN),
+where the address Nota picks for the QR code is not the one the phone can actually reach. I want
+to choose which interface/address the link and QR are built from. I'd also like to open the
+Remote page on the computer itself […] without retyping the address." Suggested: a
+`RemoteInterface` setting (interface name or "auto"), remembered across restarts with a fallback
+to Automatic; clickable addresses in Connect phone; an open-in-browser and a copy action; the
+same picker in Settings → Remote.
+
+## Nota Context
+
+**Feature area**:
+
+- [ ] Engine (C++, `src/native/nota.engine`)
+- [x] Managed app (C#, `src/managed/*`) — Nota Remote's links, the app's Remote service, settings
+- [x] UI (Avalonia) — Connect phone and Settings → Remote, follow `DESIGN.md` (Studio)
+- [ ] Plugin hosting
+- [ ] Build / packaging / CI
+- [ ] Docs only
+
+**Nota docs to keep in mind**: [`ARCHITECTURE.md`](../../ARCHITECTURE.md),
+[`CONTRIBUTING.md`](../../CONTRIBUTING.md), [`DESIGN.md`](../../DESIGN.md),
+[`FEATURES.md`](../../FEATURES.md).
+
+**Existing behaviour this builds on**: `RemoteServer` listens on every interface; only what Nota
+shows is chosen. `RemoteLinks.All()` ranks the computer's IPv4 addresses (USB first, then
+interfaces with a gateway, Wi-Fi before Ethernet) and drops some virtual adapters by name.
+`RemoteService.Url` and `QrText` always take the first. Connect phone shows that address as
+text, with the others dimmed under it; Settings → Remote lists them all on its status line.
+
+## User Scenarios & Testing
+
+### User Story 1 - Pick the address the phone can reach (Priority: P1)
+
+A laptop on Wi-Fi also runs a VPN that wins the ranking. The user opens Settings → Remote and
+picks the Wi-Fi interface under **Address in the QR**; the Connect phone QR and link now carry
+the Wi-Fi address, and still do after a restart.
+
+**Independent Test**: with links from two interfaces, choosing the second makes it the one in
+the QR and the link; choosing Automatic returns to the first.
+
+**Acceptance Scenarios**:
+
+1. **Given** several interfaces, **Then** Settings → Remote lists Automatic and one entry per
+ interface (its kind, first address and system name), the current choice selected.
+2. **When** an interface is chosen, **Then** the link and the QR use its first address.
+3. **Given** a chosen interface that is down, **Then** the link and QR use the Automatic
+ address, and the list shows the interface as not connected; **when** it is back, it is used
+ again.
+4. **Given** a restart, **Then** the choice is kept.
+
+### User Story 2 - Switch from the Connect phone popup (Priority: P2)
+
+**Acceptance Scenarios**:
+
+1. **Given** the popup with several addresses, **When** the user clicks one of the dim
+ addresses under the main one, **Then** it becomes the address in the link and QR.
+2. **Given** an address chosen by hand, **Then** an **Automatic** row under the others goes back
+ to the best address.
+
+### User Story 3 - Open or copy the link (Priority: P2)
+
+**Acceptance Scenarios**:
+
+1. **When** the user clicks **Open in the browser** beside the address, **Then** the default
+ browser opens the Remote page at that address (it asks for the code, as a phone does).
+2. **When** the user clicks **Copy the link**, **Then** the address is on the clipboard and the
+ key shows a tick for a moment.
+
+### Edge Cases
+
+- **No network**: unchanged — the popup says the computer isn't on a network.
+- **An interface with two IPv4 addresses**: its first address is used; the popup lists both,
+ and clicking either chooses the interface.
+- **Remote off**: the Address row is dimmed with the rest of the page, as the port is.
+- **The opened page** carries no pairing code: opening Nota Remote on the computer does not
+ trust the browser without the code.
+
+## Requirements
+
+### Functional Requirements
+
+- **FR-001**: Every link MUST carry its interface's system name.
+- **FR-002**: The link and QR MUST use the chosen interface's first address while it is up, and
+ the Automatic address otherwise.
+- **FR-003**: The choice MUST be a setting (`RemoteInterface`, null = Automatic), kept across
+ restarts.
+- **FR-004**: Settings → Remote MUST offer Automatic and every interface, and show a chosen
+ interface that is down as not connected.
+- **FR-005**: Connect phone MUST let the user choose another address with a click, go back to
+ Automatic, open the link in the browser and copy it.
+
+## Success Criteria
+
+- **SC-001**: On a computer where the ranked address is unreachable from the phone, connecting
+ takes one choice in Settings or one click in the popup, instead of typing an address by hand.
+
+## Assumptions
+
+- Interfaces are remembered by their system name, as the issue suggests; an address changes
+ with DHCP, the interface name doesn't.
+- The opened and copied link is the plain address; the code stays something the user enters.
+
+## Nota Compliance Checklist
+
+- [x] Every new source file carries the AGPL-3.0-only SPDX header (no new source files)
+- [x] No new dependency
+- [x] Audio-thread impact: none — UI and settings only
+- [x] No new managed/native crossings
+- [x] Smoke-test impact: `RemoteTests` checks the address choice (`RemoteLinks.Pick`)
+- [x] User-visible change → `CHANGELOG.md` `[Unreleased]` entry and FEATURES.md
+- [x] UI change → follows `DESIGN.md` (existing rows, ComboBox, glyph keys; texts through `Loc`)
diff --git a/specs/095-remote-interface-pick/tasks.md b/specs/095-remote-interface-pick/tasks.md
new file mode 100644
index 00000000..d0523f5e
--- /dev/null
+++ b/specs/095-remote-interface-pick/tasks.md
@@ -0,0 +1,20 @@
+# Tasks: Nota Remote — choose the network interface for the link and QR
+
+**Input**: [spec.md](spec.md), [plan.md](plan.md)
+
+## Phase 1: User Story 1 — pick the address (P1)
+
+- [x] T001 `RemoteLink.Interface`, `RemoteLinks.Pick` in `src/managed/Nota.Remote/RemoteLinks.cs` (FR-001, FR-002)
+- [x] T002 `Settings.RemoteInterface`; `RemoteService.Link`, `Url` from it, `ChooseInterface` (FR-003)
+- [x] T003 **Address in the QR** in `PreferencesWindow.Remote.cs`, a down interface listed as not connected (FR-004)
+- [x] T004 `RemoteTests`: Automatic, chosen, two addresses, down, no network
+
+## Phase 2: User Stories 2 and 3 — the popup (P2)
+
+- [x] T005 Clickable addresses and Automatic in `ConnectPhoneView` (FR-005)
+- [x] T006 Open in the browser and Copy the link keys (FR-005)
+
+## Phase 3: Polish
+
+- [x] T007 `en.json` keys; `CHANGELOG.md` `[Unreleased]` and `FEATURES.md` entries
+- [x] T008 `Nota.sln` builds on Linux; the smoke test's `--remote` address checks and `--localization` run pass
diff --git a/src/managed/Nota.App/PreferencesWindow.Remote.cs b/src/managed/Nota.App/PreferencesWindow.Remote.cs
index 64601364..561c3e3b 100644
--- a/src/managed/Nota.App/PreferencesWindow.Remote.cs
+++ b/src/managed/Nota.App/PreferencesWindow.Remote.cs
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
//
-// Settings → Remote (design 5b): the switch, the port, what phones may do, and the trusted
-// phones — a trusted phone reconnects from its Home Screen icon without a code until it is
+// Settings → Remote (design 5b): the switch, the port, the address the link and QR show (#85),
+// what phones may do, and the trusted phones — a trusted phone reconnects from its Home Screen icon without a code until it is
// forgotten here. The note at the end warns about the system's local-network / firewall prompt
// before it appears.
@@ -105,6 +105,44 @@ public sealed partial class PreferencesWindow
trustedHost.Content = Table(rows);
}
+ // The address the Connect phone link and QR show (#85): Automatic, or one interface by its
+ // name (its first address). A chosen interface that isn't up stays listed as not connected
+ // (Automatic stands in until it is back). Rebuilt only when the addresses or the choice
+ // change, so an open list isn't closed by the code rotating.
+ var addressHost = new ContentControl();
+ string addressSig = "";
+ void RenderAddress()
+ {
+ var links = remote.Links;
+ string? chosen = settings.Current.RemoteInterface;
+ string sig = string.Join("|", links.Select(l => l.Interface + "=" + l.Address)) + ";" + chosen;
+ if (sig == addressSig) return;
+ addressSig = sig;
+ var combo = Combo(280);
+ var values = new List<string?> { null };
+ combo.Items.Add(Loc.T("preferences.remote.automatic_usb_then_wi_fi"));
+ foreach (var l in links)
+ {
+ if (values.Contains(l.Interface)) continue;
+ values.Add(l.Interface);
+ combo.Items.Add(Loc.F("preferences.remote.link_on_interface", l.Name, l.Address, l.Interface));
+ }
+ if (chosen is not null && !values.Contains(chosen))
+ {
+ values.Add(chosen);
+ combo.Items.Add(new ComboBoxItem { Content = Loc.F("preferences.remote.interface_not_connected", chosen), IsEnabled = false });
+ }
+ combo.SelectedIndex = Math.Max(0, values.IndexOf(chosen));
+ combo.SelectionChanged += (_, _) =>
+ {
+ int i = combo.SelectedIndex;
+ if (i < 0 || i >= values.Count || values[i] == settings.Current.RemoteInterface) return;
+ remote.ChooseInterface(values[i]);
+ };
+ ToolTip.SetTip(combo, Loc.T("preferences.remote.the_address_the_connect_phone"));
+ addressHost.Content = combo;
+ }
+
bool Enabled() => settings.Current.RemoteEnabled;
var details = new StackPanel { Spacing = 10 };
void Refresh()
@@ -114,6 +152,7 @@ public sealed partial class PreferencesWindow
: Loc.F("preferences.remote.listening_on", string.Join(" · ", remote.Links.Select(l => (l.Usb ? Loc.T("preferences.remote.usb_caps") : "") + l.Address + ":" + settings.Current.RemotePort)));
status.Text = !on ? Loc.T("common.off") : remote.Error ?? listen;
statusDot.Fill = !on ? BorderStrong : remote.Error is null ? NotaPalette.SuccessDim : NotaPalette.Danger;
+ RenderAddress();
Inactive.Set(details, !on);
RenderTrusted();
}
@@ -134,6 +173,7 @@ public sealed partial class PreferencesWindow
DetachedFromVisualTree += (_, _) => remote.Changed -= OnChanged;
details.Children.Add(Row(Loc.T("preferences.port"), portBox));
+ details.Children.Add(Row(Loc.T("preferences.remote.address_in_the_qr"), addressHost));
details.Children.Add(Row(Loc.T("preferences.status"), new StackPanel { Orientation = Orientation.Horizontal, Spacing = 8, Children = { statusDot, status } }));
var accessRow = new Grid { ColumnDefinitions = new ColumnDefinitions($"{LabelCol},*") };
var accessLabel = RowLabel(Loc.T("preferences.remote.phones_may"));
diff --git a/src/managed/Nota.App/Remote/ConnectPhoneView.cs b/src/managed/Nota.App/Remote/ConnectPhoneView.cs
index 267912d6..678c1f59 100644
--- a/src/managed/Nota.App/Remote/ConnectPhoneView.cs
+++ b/src/managed/Nota.App/Remote/ConnectPhoneView.cs
@@ -2,7 +2,8 @@
// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
//
// Connect Phone (design 5a): the popup under the top bar's Remote button and View → Connect
-// Phone…. One switch when Remote is off; when on, a large QR, the address and the four-digit
+// Phone…. One switch when Remote is off; when on, a large QR, the address (open it in the
+// browser, copy it; another address of the computer is a click away, #85) and the four-digit
// code with its countdown ring, then the connected phones (signal, name, latency and screen,
// the track each plays, ✕ to drop it).
@@ -11,8 +12,10 @@ using System.Collections.Generic;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
+using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Controls.Shapes;
using Avalonia.Input;
+using Avalonia.Input.Platform;
using Avalonia.Layout;
using Avalonia.Media;
using Avalonia.Threading;
@@ -56,8 +59,7 @@ internal sealed class ConnectPhoneView : Border
{
// The code rotating or a phone's latency moving only updates text; a phone coming or
// going, or the network's addresses changing (a cable plugged in), rebuilds.
- string sig = string.Join("|", _remote.Hub.Devices.Select(d => $"{d.ConnectionId}:{d.Name}:{d.TrackId}"))
- + ";" + string.Join("|", _remote.Links.Select(l => l.Address));
+ string sig = string.Join("|", _remote.Hub.Devices.Select(d => $"{d.ConnectionId}:{d.Name}:{d.TrackId}")) + ";" + LinksSig();
if (sig != _lastDevices || _qr is null != !_remote.Running) Build();
else Tick();
});
@@ -108,7 +110,7 @@ internal sealed class ConnectPhoneView : Border
_left = new TextBlock { FontSize = 9, FontFamily = NotaFonts.ValuesFamily, Foreground = NotaPalette.TextTertiary, VerticalAlignment = VerticalAlignment.Center };
var codeRow = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 10, Children = { _code, new Panel { Children = { ringBack, _ring } }, _left } };
info.Children.Add(Field(Loc.T("remote.connect.code"), codeRow));
- bool usb = _remote.Links is { Count: > 0 } links && links[0].Usb;
+ bool usb = _remote.Link is { Usb: true };
info.Children.Add(Note(usb
? Loc.T("remote.connect.point_the_phone_camera_at")
: Loc.T("remote.connect.point_the_phone_camera_at_2"),
@@ -119,8 +121,7 @@ internal sealed class ConnectPhoneView : Border
_body.Children.Add(top);
var devices = _remote.Hub.Devices;
- _lastDevices = string.Join("|", devices.Select(d => $"{d.ConnectionId}:{d.Name}:{d.TrackId}"))
- + ";" + string.Join("|", _remote.Links.Select(l => l.Address));
+ _lastDevices = string.Join("|", devices.Select(d => $"{d.ConnectionId}:{d.Name}:{d.TrackId}")) + ";" + LinksSig();
if (devices.Count > 0)
{
var list = new StackPanel();
@@ -183,30 +184,96 @@ internal sealed class ConnectPhoneView : Border
_ring.SweepAngle = 360 * left.TotalSeconds / RemotePairing.CodeLifetime.TotalSeconds;
}
- // The addresses, best first: a "USB" pill on the cable link, the rest dimmer under it.
+ // The addresses and the interface chosen for the QR: a change to either rebuilds.
+ private string LinksSig() => string.Join("|", _remote.Links.Select(l => l.Address)) + ";" + _settings.Current.RemoteInterface;
+
+ // The address in the QR — a "USB" pill on the cable link, then open in the browser and copy —
+ // and the computer's other addresses dimmer under it: a click puts one in the QR (#85), and
+ // "Automatic" goes back to the best one once an address has been chosen.
private Control AddressRows()
{
var links = _remote.Links;
- var host = _remote.Url!.Replace("http://", "");
- var first = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 8 };
- first.Children.Add(new TextBlock { Text = host, FontSize = 12, FontFamily = NotaFonts.ValuesFamily, Foreground = NotaPalette.TextPrimary, VerticalAlignment = VerticalAlignment.Center });
- if (links.Count > 0 && links[0].Usb)
- first.Children.Add(new Border
+ var chosen = _remote.Link;
+ var url = _remote.Url!;
+ // Keys and badge stay docked right, so a long address gives way to them (trimmed), not they to it.
+ var first = new DockPanel { LastChildFill = true };
+ var keys = new StackPanel
+ {
+ Orientation = Orientation.Horizontal, Spacing = 2, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(8, 0, 0, 0),
+ Children =
+ {
+ LinkKey(GlyphKind.PopOut, Loc.T("remote.connect.open_in_the_browser"), _ => Host?.Launcher.LaunchUriAsync(new Uri(url))),
+ LinkKey(GlyphKind.Copy, Loc.T("remote.connect.copy_the_link"), g =>
+ {
+ if (Host?.Clipboard is not { } cb) return;
+ _ = cb.SetTextAsync(url);
+ g.Kind = GlyphKind.Check; // copied: a tick for a moment
+ DispatcherTimer.RunOnce(() => g.Kind = GlyphKind.Copy, TimeSpan.FromSeconds(1.5));
+ }),
+ },
+ };
+ DockPanel.SetDock(keys, Dock.Right);
+ first.Children.Add(keys);
+ if (chosen is { Usb: true })
+ {
+ var usb = new Border
{
- Height = 16, Padding = new Thickness(5, 0), CornerRadius = NotaRadius.Fine, VerticalAlignment = VerticalAlignment.Center,
+ Height = 16, Padding = new Thickness(5, 0), CornerRadius = NotaRadius.Fine, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(8, 0, 0, 0),
Background = NotaPalette.SurfaceRaised, BorderBrush = NotaPalette.Seam, BorderThickness = new Thickness(1),
Child = new TextBlock { Text = Loc.T("remote.connect.usb_caps"), FontSize = 8.5, FontWeight = FontWeight.SemiBold, Foreground = NotaPalette.TextPrimary, VerticalAlignment = VerticalAlignment.Center },
- });
- var rows = new StackPanel { Spacing = links.Count > 1 ? 3 : 0, Children = { first } };
- for (int i = 1; i < links.Count; i++)
- rows.Children.Add(new TextBlock
- {
- Text = $"{links[i].Name} {links[i].Address}:{_settings.Current.RemotePort}", FontSize = 9, FontFamily = NotaFonts.ValuesFamily,
- Foreground = NotaPalette.TextTertiary, Margin = new Thickness(0, 1, 0, 0),
- });
+ };
+ DockPanel.SetDock(usb, Dock.Right);
+ first.Children.Add(usb);
+ }
+ first.Children.Add(new TextBlock { Text = url.Replace("http://", ""), FontSize = 12, FontFamily = NotaFonts.ValuesFamily, Foreground = NotaPalette.TextPrimary, VerticalAlignment = VerticalAlignment.Center, TextTrimming = TextTrimming.CharacterEllipsis });
+ var rows = new StackPanel { Spacing = 3, Children = { first } };
+ foreach (var l in links)
+ {
+ if (chosen is { } c && l.Address == c.Address) continue;
+ string iface = l.Interface;
+ rows.Children.Add(OtherRow($"{l.Name} {l.Address}:{_settings.Current.RemotePort}", Loc.T("remote.connect.show_this_address_in_the"), () => _remote.ChooseInterface(iface)));
+ }
+ if (_settings.Current.RemoteInterface is not null)
+ rows.Children.Add(OtherRow(Loc.T("remote.connect.automatic"), Loc.T("remote.connect.show_the_best_address_usb"), () => _remote.ChooseInterface(null)));
return rows;
}
+ // The window the popup opens from: it reaches the browser and the clipboard, which a popup's
+ // own root may not.
+ private TopLevel? Host => (Avalonia.Application.Current?.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)?.MainWindow
+ ?? TopLevel.GetTopLevel(this);
+
+ // A dim address row that takes a click.
+ private static Control OtherRow(string text, string tip, Action click)
+ {
+ var t = new TextBlock
+ {
+ Text = text, FontSize = 9, FontFamily = NotaFonts.ValuesFamily, Foreground = NotaPalette.TextTertiary, Margin = new Thickness(0, 1, 0, 0),
+ Background = Brushes.Transparent, Cursor = new Cursor(StandardCursorType.Hand), HorizontalAlignment = HorizontalAlignment.Left,
+ };
+ ToolTip.SetTip(t, tip);
+ t.PointerEntered += (_, _) => t.Foreground = NotaPalette.TextPrimary;
+ t.PointerExited += (_, _) => t.Foreground = NotaPalette.TextTertiary;
+ t.PointerPressed += (_, e) => { if (e.GetCurrentPoint(t).Properties.IsLeftButtonPressed) { e.Handled = true; click(); } };
+ return t;
+ }
+
+ // A small glyph key beside the address; the click gets the glyph, to show what it did.
+ private static Control LinkKey(GlyphKind glyph, string tip, Action<Glyph> click)
+ {
+ var g = new Glyph(glyph, 10) { Foreground = NotaPalette.TextMuted, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center };
+ var k = new Border
+ {
+ Width = 20, Height = 20, CornerRadius = NotaRadius.Group, Background = Brushes.Transparent, Cursor = new Cursor(StandardCursorType.Hand),
+ Child = g,
+ };
+ ToolTip.SetTip(k, tip);
+ k.PointerEntered += (_, _) => k.Background = NotaPalette.SurfaceHover;
+ k.PointerExited += (_, _) => k.Background = Brushes.Transparent;
+ k.PointerPressed += (_, e) => { if (e.GetCurrentPoint(k).Properties.IsLeftButtonPressed) { e.Handled = true; click(g); } };
+ return k;
+ }
+
private static Control Field(string label, Control value)
{
var s = new StackPanel { Spacing = 3 };
diff --git a/src/managed/Nota.App/Remote/RemoteService.cs b/src/managed/Nota.App/Remote/RemoteService.cs
index d7d132b5..dab6d9c2 100644
--- a/src/managed/Nota.App/Remote/RemoteService.cs
+++ b/src/managed/Nota.App/Remote/RemoteService.cs
@@ -81,9 +81,22 @@ public sealed class RemoteService
}
}
- /// <summary>The address a phone opens: the USB one when a cable link is up (millisecond
- /// latency, no radio), else Wi-Fi/Ethernet. Null without a network.</summary>
- public string? Url => Links.Count > 0 ? $"http://{Links[0].Address}:{_server.Port}" : null;
+ /// <summary>The link a phone opens: the interface chosen in Settings → Remote or the
+ /// Connect phone popup while it is up (#85), else the USB one when a cable link is up
+ /// (millisecond latency, no radio), else Wi-Fi/Ethernet. Null without a network.</summary>
+ public RemoteLink? Link => RemoteLinks.Pick(Links, _settings.Current.RemoteInterface);
+
+ /// <summary>The address a phone opens (<see cref="Link"/>). Null without a network.</summary>
+ public string? Url => Link is { } l ? $"http://{l.Address}:{_server.Port}" : null;
+
+ /// <summary>Show <paramref name="iface"/>'s address in the link and the QR (null =
+ /// Automatic). Remembered across restarts.</summary>
+ public void ChooseInterface(string? iface)
+ {
+ _settings.Current.RemoteInterface = string.IsNullOrEmpty(iface) ? null : iface;
+ _settings.Save();
+ RaiseChanged();
+ }
/// <summary>What the QR holds: the address with the current code in the fragment, so the
/// phone pairs the moment the page opens (a fragment never leaves the phone).</summary>
diff --git a/src/managed/Nota.Application/Localization/en.json b/src/managed/Nota.Application/Localization/en.json
index 63e78a9a..641a32a7 100644
--- a/src/managed/Nota.Application/Localization/en.json
+++ b/src/managed/Nota.Application/Localization/en.json
@@ -3766,13 +3766,17 @@
"preferences.reload_the_registry": "Reload the registry",
"preferences.remote": "Remote",
"preferences.remote.a_trusted_phone_reconnects_from": "A trusted phone reconnects from its Home Screen icon without a code. Forget it and it has to scan again. Turning Remote off disconnects everyone.",
+ "preferences.remote.address_in_the_qr": "Address in the QR",
"preferences.remote.allow_control_from_a_phone": "Allow control from a phone",
"preferences.remote.also_mixer_transport_macros_xy": "Also mixer, transport, macros, XY and Session.",
+ "preferences.remote.automatic_usb_then_wi_fi": "Automatic (USB, then Wi-Fi, then Ethernet)",
"preferences.remote.days_ago": "{0} days ago",
"preferences.remote.disconnect_it_and_make_it": "Disconnect it and make it scan a new code to come back",
"preferences.remote.forget": "Forget",
"preferences.remote.h_ago": "{0} h ago",
+ "preferences.remote.interface_not_connected": "{0} (not connected: Automatic until it is back)",
"preferences.remote.just_now": "just now",
+ "preferences.remote.link_on_interface": "{0} {1} · {2}",
"preferences.remote.listening_on": "Listening on {0}",
"preferences.remote.min_ago": "{0} min ago",
"preferences.remote.no_phone_has_paired_yet": "No phone has paired yet. Turn Remote on and scan the code in Connect phone.",
@@ -3785,6 +3789,7 @@
"preferences.remote.phones_reach_nota_on_the": "Phones reach Nota on the port above: if a firewall is on, allow it.",
"preferences.remote.play_and_control_the_project": "Play and control the project",
"preferences.remote.play_notes_only": "Play notes only",
+ "preferences.remote.the_address_the_connect_phone": "The address the Connect phone link and QR code show. Nota answers on every address; pick the one the phone can reach.",
"preferences.remote.trusted_devices": "Trusted devices",
"preferences.remote.usb_caps": "USB ",
"preferences.remote.when_you_turn_this_on": "When you turn this on, Windows asks whether Nota may use the network. Allow private networks, or phones can't reach Nota.",
@@ -4046,18 +4051,23 @@
"registry.client.unsafe_path_in_the_registry": "Unsafe path in the registry entry: {0}",
"remote.connect.address": "Address",
"remote.connect.allow": "Allow",
+ "remote.connect.automatic": "Automatic",
"remote.connect.code": "Code",
"remote.connect.connect_phone": "Connect phone",
"remote.connect.connected": "connected",
"remote.connect.connecting": "connecting",
+ "remote.connect.copy_the_link": "Copy the link",
"remote.connect.disconnect_this_phone_it_stays": "Disconnect this phone (it stays trusted — forget it in Settings → Remote)",
"remote.connect.ms": "{0} ms · {1}",
"remote.connect.ms_weak_network": "{0} ms · weak network",
+ "remote.connect.open_in_the_browser": "Open in the browser on this computer",
"remote.connect.point_the_phone_camera_at": "Point the phone camera at the code. Over the cable the link is instant and needs no Wi-Fi; the code changes every 2 minutes and after each connection.",
"remote.connect.point_the_phone_camera_at_2": "Point the phone camera at the code. Same Wi-Fi only — or plug in a USB cable (USB tethering on the phone; Internet Sharing on the Mac) for an instant link. The code changes every 2 minutes and after each connection.",
"remote.connect.remote_is_off_turn_it": "Remote is off. Turn it on to show a QR code a phone on the same Wi-Fi can scan.",
"remote.connect.remote_is_off_turn_it_2": "Remote is off. Turn it on to show a QR code. The first time, Windows asks whether Nota may use the network; allow private networks.",
"remote.connect.remote_is_off_turn_it_3": "Remote is off. Turn it on to show a QR code. The first time, macOS asks to allow Nota on the local network; click Allow.",
+ "remote.connect.show_the_best_address_usb": "Show the best address again: USB, then Wi-Fi, then Ethernet",
+ "remote.connect.show_this_address_in_the": "Show this address in the link and the QR code",
"remote.connect.this_computer_isnt_on_a": "This computer isn't on a network. Join the same Wi-Fi as the phone, share the phone's hotspot with it, or plug in a USB cable (USB tethering on the phone; Internet Sharing on the Mac).",
"remote.connect.usb_caps": "USB",
"remote.connect.usb_ms": "USB · {0} ms · {1}",
diff --git a/src/managed/Nota.Application/Settings.cs b/src/managed/Nota.Application/Settings.cs
index 6f2221c6..f848f0e5 100644
--- a/src/managed/Nota.Application/Settings.cs
+++ b/src/managed/Nota.Application/Settings.cs
@@ -120,6 +120,10 @@ public sealed class Settings
public bool RemoteEnabled { get; set; }
/// <summary>TCP port Nota Remote listens on (all interfaces).</summary>
public int RemotePort { get; set; } = 7788;
+ /// <summary>The network interface whose address the Connect phone link and QR show (#85),
+ /// by its system name (en0, eth0, "Wi-Fi"); null = Automatic (a USB link first, then
+ /// Wi-Fi, then Ethernet). An interface that isn't up falls back to Automatic.</summary>
+ public string? RemoteInterface { get; set; }
/// <summary>What a phone may do: 0 play notes only, 1 also control the project (mixer,
/// transport, macros, XY, Session).</summary>
public int RemoteAccess { get; set; } = 1;
diff --git a/src/managed/Nota.Remote/RemoteLinks.cs b/src/managed/Nota.Remote/RemoteLinks.cs
index 55c70644..3cce6ec8 100644
--- a/src/managed/Nota.Remote/RemoteLinks.cs
+++ b/src/managed/Nota.Remote/RemoteLinks.cs
@@ -14,8 +14,9 @@ using System.Runtime.InteropServices;
namespace Nota.Remote;
/// <summary>One address a phone could open. <paramref name="Name"/> says what it is ("USB",
-/// "Wi-Fi") for the popup's rows.</summary>
-public readonly record struct RemoteLink(string Address, bool Usb, string Name);
+/// "Wi-Fi") for the popup's rows; <paramref name="Interface"/> is the system's name for its
+/// network interface (en0, eth0, "Wi-Fi"), which a chosen address is remembered by (#85).</summary>
+public readonly record struct RemoteLink(string Address, bool Usb, string Name, string Interface);
public static class RemoteLinks
{
@@ -38,7 +39,7 @@ public static class RemoteLinks
if (b[0] == 169 && b[1] == 254) continue; // link-local: no DHCP
bool wifi = ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211;
int rank = (isUsb ? 0 : 1) * 4 + (HasGateway(ni) ? 0 : 2) + (wifi ? 0 : 1);
- links.Add((new RemoteLink(ua.Address.ToString(), isUsb, isUsb ? "USB" : wifi ? "Wi-Fi" : "Ethernet"), rank));
+ links.Add((new RemoteLink(ua.Address.ToString(), isUsb, isUsb ? "USB" : wifi ? "Wi-Fi" : "Ethernet", ni.Name), rank));
}
}
}
@@ -46,6 +47,19 @@ public static class RemoteLinks
return links.OrderBy(l => l.Rank).Select(l => l.Link).ToList();
}
+ /// <summary>The link the QR and the shown address use (#85): the first address of the
+ /// interface named <paramref name="chosen"/> while it is up, else the best one
+ /// (<paramref name="links"/>[0], as <see cref="All"/> ranks them) — so a chosen interface
+ /// that goes away falls back to Automatic, and comes back with it. Null without a network.</summary>
+ public static RemoteLink? Pick(IReadOnlyList<RemoteLink> links, string? chosen)
+ {
+ if (links.Count == 0) return null;
+ if (!string.IsNullOrEmpty(chosen))
+ foreach (var l in links)
+ if (l.Interface == chosen) return l;
+ return links[0];
+ }
+
/// <summary>Whether <paramref name="ip"/> sits on a USB link (the device rows and the
/// phone's "USB" badge).</summary>
public static bool OnUsbLink(IPAddress? ip)
diff --git a/tests/Nota.SmokeTest/RemoteTests.cs b/tests/Nota.SmokeTest/RemoteTests.cs
index 1d89abd6..ea777cff 100644
--- a/tests/Nota.SmokeTest/RemoteTests.cs
+++ b/tests/Nota.SmokeTest/RemoteTests.cs
@@ -84,6 +84,21 @@ internal static class RemoteTests
yield return (!RemoteLinks.InSubnet(IPAddress.Parse("::1"), IPAddress.Parse("10.0.0.1"), 24)
&& !RemoteLinks.InSubnet(IPAddress.Parse("10.0.0.5"), IPAddress.Parse("10.0.0.1"), 33),
"nonsense prefixes and IPv6 match nothing");
+
+ // The address in the link and QR (#85): the chosen interface while it is up, else the best.
+ var links = new List<RemoteLink>
+ {
+ new("172.20.10.2", true, "USB", "en7"),
+ new("192.168.1.20", false, "Wi-Fi", "en0"),
+ new("192.168.1.21", false, "Wi-Fi", "en0"),
+ new("10.0.0.5", false, "Ethernet", "en1"),
+ };
+ yield return (RemoteLinks.Pick(links, null)?.Address == "172.20.10.2" && RemoteLinks.Pick(links, "")?.Address == "172.20.10.2",
+ "Automatic shows the best address (USB first)");
+ yield return (RemoteLinks.Pick(links, "en1")?.Address == "10.0.0.5", "a chosen interface's address goes in the QR");
+ yield return (RemoteLinks.Pick(links, "en0")?.Address == "192.168.1.20", "an interface with two addresses shows its first");
+ yield return (RemoteLinks.Pick(links, "utun3")?.Address == "172.20.10.2", "a chosen interface that isn't up falls back to Automatic");
+ yield return (RemoteLinks.Pick(new List<RemoteLink>(), "en0") is null, "no network, no address");
}
private static IEnumerable<(bool, string)> Engine()