Remember four recent Midra connections for quick switching
This commit is contained in:
parent
ed07d5c00d
commit
533173b42c
|
|
@ -100,6 +100,7 @@ pub(super) struct DeviceUi {
|
|||
pub(super) sending: bool,
|
||||
message: String,
|
||||
pub(super) host: String,
|
||||
pub(super) recent_hosts: Vec<String>,
|
||||
pending: Option<Receiver<Result<device::Snapshot, String>>>,
|
||||
pub(super) snapshot: Option<device::Snapshot>,
|
||||
loading: Option<Vec<(usize, midra_layout::MidraLink)>>,
|
||||
|
|
@ -294,6 +295,12 @@ impl DeviceUi {
|
|||
let was_sending = std::mem::take(&mut self.sending);
|
||||
match result {
|
||||
Ok(snapshot) => {
|
||||
if let Ok(address) = device::address(&self.host) {
|
||||
let host = address.to_string();
|
||||
self.recent_hosts.retain(|entry| entry != &host);
|
||||
self.recent_hosts.insert(0, host);
|
||||
self.recent_hosts.truncate(4);
|
||||
}
|
||||
if was_sending {
|
||||
self.message =
|
||||
"Send complete. Preset update sent; geometry verified by device readback."
|
||||
|
|
@ -614,6 +621,19 @@ impl Editor {
|
|||
self.device.error.clear();
|
||||
self.device.message.clear();
|
||||
}
|
||||
ui.add_enabled_ui(self.device.pending.is_none() && !self.device.recent_hosts.is_empty(), |ui| {
|
||||
ui.menu_button("Recent machines…", |ui| {
|
||||
for host in self.device.recent_hosts.clone() {
|
||||
if ui.button(&host).on_hover_text("Connect to this machine (read only)").clicked() {
|
||||
self.device.host = host;
|
||||
self.device.input_edits.clear();
|
||||
self.device.reset_mappings();
|
||||
self.device.fetch(ctx);
|
||||
ui.close_menu();
|
||||
}
|
||||
}
|
||||
}).response.on_hover_text("Last four successful connections; choose one to connect");
|
||||
});
|
||||
ui.weak("Address saved automatically in application settings. Connect reads device data; it does not change layers.");
|
||||
ui.horizontal(|ui| {
|
||||
if ui.add_enabled(self.device.pending.is_none(), egui::Button::new(if self.device.online() { "Refresh connection" } else { "Connect" })).clicked() { self.device.fetch(ctx); }
|
||||
|
|
@ -643,7 +663,11 @@ impl Editor {
|
|||
if !self.device.allow_program {
|
||||
self.device.target = Target::Preview;
|
||||
}
|
||||
let recent_before = self.device.recent_hosts.clone();
|
||||
self.device.poll();
|
||||
if self.device.recent_hosts != recent_before {
|
||||
self.settings.save(&self.application_settings(ctx));
|
||||
}
|
||||
self.finish_linked_load();
|
||||
self.connection_window(ctx);
|
||||
if !self.device.open {
|
||||
|
|
@ -1089,6 +1113,49 @@ mod tests {
|
|||
)
|
||||
.unwrap()
|
||||
}
|
||||
#[test]
|
||||
fn connection_history_tracks_successes_and_keeps_four_distinct_endpoints() {
|
||||
let mut device = DeviceUi::default();
|
||||
for port in 3000..3005 {
|
||||
device.host = format!("127.0.0.1:{port}");
|
||||
let (tx, rx) = mpsc::channel();
|
||||
device.pending = Some(rx);
|
||||
tx.send(Ok(linked_test_snapshot())).unwrap();
|
||||
device.poll();
|
||||
}
|
||||
assert_eq!(
|
||||
device.recent_hosts,
|
||||
[
|
||||
"127.0.0.1:3004",
|
||||
"127.0.0.1:3003",
|
||||
"127.0.0.1:3002",
|
||||
"127.0.0.1:3001"
|
||||
]
|
||||
);
|
||||
device.host = " 127.0.0.1:3002 ".into();
|
||||
let (tx, rx) = mpsc::channel();
|
||||
device.pending = Some(rx);
|
||||
tx.send(Ok(linked_test_snapshot())).unwrap();
|
||||
device.poll();
|
||||
assert_eq!(device.recent_hosts[0], "127.0.0.1:3002");
|
||||
assert_eq!(device.recent_hosts.len(), 4);
|
||||
let before = device.recent_hosts.clone();
|
||||
device.host = "127.0.0.1:9999".into();
|
||||
let (tx, rx) = mpsc::channel();
|
||||
device.pending = Some(rx);
|
||||
tx.send(Err("Offline".into())).unwrap();
|
||||
device.poll();
|
||||
assert_eq!(device.recent_hosts, before);
|
||||
let ctx = egui::Context::default();
|
||||
let app = Editor {
|
||||
device,
|
||||
..Default::default()
|
||||
};
|
||||
let saved = app.application_settings(&ctx);
|
||||
let restored = Editor::with_settings(&ctx, settings::Store::default(), saved);
|
||||
assert_eq!(restored.device.recent_hosts, before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn property_mapping_selects_screen_and_unmaps_without_device_writes() {
|
||||
use super::super::tests::click_text;
|
||||
|
|
|
|||
|
|
@ -397,6 +397,7 @@ impl Editor {
|
|||
saved.allow_sending_to_program,
|
||||
);
|
||||
device.autoconnect_at_startup = saved.autoconnect_at_startup;
|
||||
device.recent_hosts = saved.recent_midra_hosts;
|
||||
Self {
|
||||
device,
|
||||
settings: store,
|
||||
|
|
@ -410,6 +411,7 @@ impl Editor {
|
|||
fn application_settings(&self, ctx: &egui::Context) -> settings::Settings {
|
||||
settings::Settings {
|
||||
midra_host: self.device.host.clone(),
|
||||
recent_midra_hosts: self.device.recent_hosts.clone(),
|
||||
autoconnect_at_startup: self.device.autoconnect_at_startup,
|
||||
allow_sending_to_program: self.device.allow_program,
|
||||
theme: theme::Theme::current(ctx),
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use std::{io::Read, path::PathBuf};
|
|||
pub struct Settings {
|
||||
pub version: u32,
|
||||
pub midra_host: String,
|
||||
pub recent_midra_hosts: Vec<String>,
|
||||
pub autoconnect_at_startup: bool,
|
||||
pub allow_sending_to_program: bool,
|
||||
pub theme: Theme,
|
||||
|
|
@ -20,10 +21,11 @@ pub struct Settings {
|
|||
impl Default for Settings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
version: 7,
|
||||
version: 8,
|
||||
autoconnect_at_startup: false,
|
||||
allow_sending_to_program: false,
|
||||
midra_host: String::new(),
|
||||
recent_midra_hosts: Vec::new(),
|
||||
theme: Theme::Midra,
|
||||
recent_themes: vec![Theme::Midra],
|
||||
snapping: Default::default(),
|
||||
|
|
@ -98,14 +100,35 @@ impl Settings {
|
|||
value["snapping"]["grid_divisions"] = serde_json::json!([8, 6]);
|
||||
value["version"] = 7.into();
|
||||
}
|
||||
if value["version"] == 7 {
|
||||
if value.get("recent_midra_hosts").is_some() {
|
||||
return Err("Unexpected recent_midra_hosts in version 7 settings".into());
|
||||
}
|
||||
value["recent_midra_hosts"] = serde_json::json!([]);
|
||||
value["version"] = 8.into();
|
||||
}
|
||||
let settings: Self = serde_json::from_value(value).map_err(|e| e.to_string())?;
|
||||
settings.validate()?;
|
||||
Ok(settings)
|
||||
}
|
||||
fn validate(&self) -> Result<(), String> {
|
||||
if self.version != 7 {
|
||||
if self.version != 8 {
|
||||
return Err(format!("unsupported settings version {}", self.version));
|
||||
}
|
||||
if self.recent_midra_hosts.len() > 4
|
||||
|| self.recent_midra_hosts.iter().enumerate().any(|(i, host)| {
|
||||
midra_layout::device::address(host)
|
||||
.map(|address| address.to_string())
|
||||
.as_ref()
|
||||
!= Ok(host)
|
||||
|| self.recent_midra_hosts[..i].contains(host)
|
||||
})
|
||||
{
|
||||
return Err(
|
||||
"recent_midra_hosts must contain at most four unique canonical IP:port addresses"
|
||||
.into(),
|
||||
);
|
||||
}
|
||||
if self
|
||||
.snapping
|
||||
.grid_divisions
|
||||
|
|
@ -217,6 +240,40 @@ impl Store {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn connection_history_migrates_and_round_trips_strictly() {
|
||||
let old = include_str!("../../../docs/interfaces/midra-layout-settings-v7.example.json");
|
||||
assert!(Settings::parse(old).unwrap().recent_midra_hosts.is_empty());
|
||||
let example =
|
||||
include_str!("../../../docs/interfaces/midra-layout-settings-v8.example.json");
|
||||
assert_eq!(Settings::parse(example).unwrap(), Settings::default());
|
||||
let mut value: serde_json::Value = serde_json::from_str(example).unwrap();
|
||||
value["recent_midra_hosts"] = serde_json::json!(["192.168.10.146:3000", "[::1]:80"]);
|
||||
let settings = Settings::parse(&value.to_string()).unwrap();
|
||||
assert_eq!(
|
||||
Settings::parse(&serde_json::to_string(&settings).unwrap()).unwrap(),
|
||||
settings
|
||||
);
|
||||
for hosts in [
|
||||
serde_json::json!(["bad"]),
|
||||
serde_json::json!(["127.0.0.1"]),
|
||||
serde_json::json!(["127.0.0.1:80", "127.0.0.1:80"]),
|
||||
serde_json::json!([
|
||||
"127.0.0.1:1",
|
||||
"127.0.0.1:2",
|
||||
"127.0.0.1:3",
|
||||
"127.0.0.1:4",
|
||||
"127.0.0.1:5"
|
||||
]),
|
||||
] {
|
||||
value["recent_midra_hosts"] = hosts;
|
||||
assert!(Settings::parse(&value.to_string()).is_err());
|
||||
}
|
||||
let mut legacy: serde_json::Value = serde_json::from_str(old).unwrap();
|
||||
legacy["recent_midra_hosts"] = serde_json::json!([]);
|
||||
assert!(Settings::parse(&legacy.to_string()).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_settings_and_changed_options_roundtrip_without_temp_files() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
|
|
@ -251,7 +308,7 @@ mod tests {
|
|||
for text in [
|
||||
"broken".to_string(),
|
||||
serde_json::to_string(&Settings {
|
||||
version: 8,
|
||||
version: 9,
|
||||
..Default::default()
|
||||
})
|
||||
.unwrap(),
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"version": 8,
|
||||
"theme": "midra",
|
||||
"recent_themes": [
|
||||
"midra"
|
||||
],
|
||||
"show_toolbar_icon_names": false,
|
||||
"keep_aspect_ratio": true,
|
||||
"show_source_pattern": false,
|
||||
"snapping": {
|
||||
"enabled": false,
|
||||
"pixels": true,
|
||||
"screen_edges": true,
|
||||
"layer_edges": true,
|
||||
"grid": false,
|
||||
"show_grid": true,
|
||||
"grid_divisions": [
|
||||
8,
|
||||
6
|
||||
]
|
||||
},
|
||||
"midra_host": "",
|
||||
"allow_sending_to_program": false,
|
||||
"autoconnect_at_startup": false,
|
||||
"recent_midra_hosts": []
|
||||
}
|
||||
|
|
@ -1,13 +1,13 @@
|
|||
# Midra Layout application settings, version 7
|
||||
# Midra Layout application settings, version 8
|
||||
|
||||
Implementation: `crates/midra-layout/src/settings.rs`. This per-user JSON file is
|
||||
independent of the [project JSON and SVG contracts](midra-layout.md).
|
||||
[Complete default example](midra-layout-settings-v7.example.json).
|
||||
[Complete default example](midra-layout-settings-v8.example.json).
|
||||
Version 1 files migrate automatically: the saved theme becomes the only entry in
|
||||
`recent_themes`, with all other preferences preserved. The [version 1 example](midra-layout-settings-v1.example.json)
|
||||
remains a migration fixture. Version 2 files then migrate by adding disabled
|
||||
snapping with all target types enabled. The [version 2 example](midra-layout-settings-v2.example.json)
|
||||
remains a migration fixture too. Version 3 files migrate by adding an empty `midra_host`; the [version 3 example](midra-layout-settings-v3.example.json) remains a migration fixture. Version 4 files migrate by adding `allow_sending_to_program: false`; the [version 4 example](midra-layout-settings-v4.example.json) remains a migration fixture. Version 5 files migrate with `autoconnect_at_startup: false`; the [version 5 example](midra-layout-settings-v5.example.json) remains a migration fixture. Version 6 files migrate with the overlay grid visible, snapping to it disabled, and `grid_divisions: [8, 6]`; the [version 6 example](midra-layout-settings-v6.example.json) remains a migration fixture. Saving writes version 7; old applications reject it.
|
||||
remains a migration fixture too. Version 3 files migrate by adding an empty `midra_host`; the [version 3 example](midra-layout-settings-v3.example.json) remains a migration fixture. Version 4 files migrate by adding `allow_sending_to_program: false`; the [version 4 example](midra-layout-settings-v4.example.json) remains a migration fixture. Version 5 files migrate with `autoconnect_at_startup: false`; the [version 5 example](midra-layout-settings-v5.example.json) remains a migration fixture. Version 6 files migrate with the overlay grid visible, snapping to it disabled, and `grid_divisions: [8, 6]`; the [version 6 example](midra-layout-settings-v6.example.json) remains a migration fixture. Version 7 migrates with an empty `recent_midra_hosts` list; the [version 7 example](midra-layout-settings-v7.example.json) remains a migration fixture. Saving writes version 8; old applications reject it.
|
||||
|
||||
The `directories` 6 crate resolves `ProjectDirs::from("org", "beffroi", "midra-layout")`.
|
||||
The filename is `settings.json` beneath `config_dir()`:
|
||||
|
|
@ -24,7 +24,7 @@ unknown theme names are rejected. There are no numeric coordinates or units.
|
|||
|
||||
| Field | Values / default |
|
||||
| --- | --- |
|
||||
| `version` | Integer `7` |
|
||||
| `version` | Integer `8` |
|
||||
| `autoconnect_at_startup` | Boolean; default false. Try one background connection at application startup if the saved address is nonblank. |
|
||||
| `allow_sending_to_program` | Boolean; default false. Enables the Program destination in the exporter. Turning it off restores Preview; applies to quick Apply too. |
|
||||
| `midra_host` | Device IP address text with optional TCP port (e.g. `192.168.10.146:3000`, `[::1]:3000`; default port 80); default `""`. Saved as typed, including incomplete drafts; validated when connecting. |
|
||||
|
|
@ -147,3 +147,18 @@ immediately and survive project changes; v1–v6 migration does not alter geomet
|
|||
Custom ports use the existing `midra_host` string without a schema change. The
|
||||
port is shared by HTTP reads/captures and WebSocket writes, including startup
|
||||
autoconnection. Hostnames, URL schemes, paths and port 0 are rejected on use.
|
||||
|
||||
## Recent connections
|
||||
|
||||
`recent_midra_hosts` is an array of zero to four unique canonical IP:port strings,
|
||||
most recently connected first (for example `["192.168.10.146:3000", "192.168.10.143:80"]`).
|
||||
IPv6 entries use brackets. Successful reads or verified sends promote an endpoint;
|
||||
failed or cancelled attempts and typed drafts do not enter the list. Default port
|
||||
80 is explicit so equivalent addresses deduplicate. Invalid addresses, noncanonical
|
||||
strings, duplicates and more than four entries are rejected.
|
||||
|
||||
The connection window lists these under **Recent machines…**. Choosing one sets
|
||||
the saved address, clears old device state/staged input edits, and starts a read-only
|
||||
connection. The picker is disabled during a pending operation. History belongs
|
||||
to application settings, not project files; migration starts empty because older
|
||||
settings do not record whether their last address connected successfully.
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
- Add a Recent machines picker for the last four successful connections, saved across restarts with distinct ports and most-recent-first ordering. Selecting an entry reads the device immediately; failed attempts do not displace history. Settings v8 migrates v1–v7 with empty history; tests cover ordering, deduplication, failures, persistence and validation.
|
||||
|
||||
- Support optional device ports for HTTP state reads, input captures and WebSocket sends, preserving the address in preferences/autoconnect. Accept all four Midra 4K identities (Eikos, Pulse, QuickVu, QuickMatrix) with device-reported allocation. Read-checked Pulse 4K 3.3.7 at port 3000 (four layers); add address, model, capture and WebSocket port regressions. Other model hardware acceptance remains outstanding.
|
||||
|
||||
- Replace the layer-header Folder, Add image and Manage text buttons with compact vector icons, grouped on the right, with tooltips and accessible action names.
|
||||
|
|
|
|||
|
|
@ -10,6 +10,10 @@ with a port use brackets, for example `[::1]:3000`. Omit URL schemes and paths.
|
|||
The same address is saved in preferences and used for reads, input snapshots,
|
||||
automatic reconnect and WebSocket sends.
|
||||
|
||||
Use **Recent machines…** to switch to one of the last four successful connections.
|
||||
Choosing an entry connects immediately to read its state; it does not send layers.
|
||||
History survives restarts, retains custom ports and excludes failed attempts.
|
||||
|
||||
The adapter accepts Eikos 4K, Pulse 4K, QuickVu 4K and QuickMatrix 4K and reads
|
||||
screen sizes and allocated layer counts from the device instead of assuming
|
||||
Eikos's configuration. This covers the Midra **4K** family, not earlier Midra
|
||||
|
|
|
|||
Loading…
Reference in New Issue