Separate Midra connection settings from layer transfers
This commit is contained in:
parent
e1ba18652d
commit
43cb7dec6f
|
|
@ -16,13 +16,14 @@ enum Destination {
|
|||
#[derive(Default)]
|
||||
pub(super) struct DeviceUi {
|
||||
pub open: bool,
|
||||
pub(super) connection_open: bool,
|
||||
pub(super) prepare_send: bool,
|
||||
target: Target,
|
||||
sizing: Sizing,
|
||||
pub(super) sending: bool,
|
||||
message: String,
|
||||
send_targets: std::collections::BTreeMap<usize, String>,
|
||||
host: String,
|
||||
pub(super) host: String,
|
||||
pending: Option<Receiver<Result<device::Snapshot, String>>>,
|
||||
snapshot: Option<device::Snapshot>,
|
||||
screen: usize,
|
||||
|
|
@ -30,6 +31,16 @@ pub(super) struct DeviceUi {
|
|||
error: String,
|
||||
}
|
||||
impl DeviceUi {
|
||||
pub(super) fn reset_mappings(&mut self) {
|
||||
self.send_targets.clear();
|
||||
self.destinations.fill(Destination::Skip);
|
||||
}
|
||||
pub(super) fn with_host(host: String) -> Self {
|
||||
Self {
|
||||
host,
|
||||
..Self::default()
|
||||
}
|
||||
}
|
||||
pub(super) fn online(&self) -> bool {
|
||||
self.snapshot.is_some()
|
||||
}
|
||||
|
|
@ -93,33 +104,66 @@ impl DeviceUi {
|
|||
}
|
||||
}
|
||||
impl Editor {
|
||||
fn connection_window(&mut self, ctx: &egui::Context) {
|
||||
if !self.device.connection_open {
|
||||
return;
|
||||
}
|
||||
let mut open = true;
|
||||
let before = self.device.host.clone();
|
||||
egui::Window::new("Midra connection").open(&mut open).collapsible(false)
|
||||
.default_width(420.0).show(ctx, |ui| {
|
||||
ui.label("Device IP");
|
||||
if ui.add_enabled(self.device.pending.is_none(), egui::TextEdit::singleline(&mut self.device.host).hint_text("192.168.…")).changed() {
|
||||
self.device.snapshot = None;
|
||||
self.device.reset_mappings();
|
||||
self.device.error.clear();
|
||||
self.device.message.clear();
|
||||
}
|
||||
ui.weak("Address saved automatically in application preferences. 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); }
|
||||
if ui.add_enabled(self.device.online() && self.device.pending.is_none(), egui::Button::new("Disconnect")).clicked() {
|
||||
self.device.snapshot = None;
|
||||
self.device.reset_mappings();
|
||||
self.device.message.clear();
|
||||
}
|
||||
});
|
||||
if self.device.pending.is_some() {
|
||||
ui.spinner();
|
||||
ui.label(if self.device.sending { "Sending and checking readback…" } else { "Connecting…" });
|
||||
if !self.device.sending && ui.button("Cancel connection").clicked() { self.device.pending = None; }
|
||||
}
|
||||
if let Some(snapshot) = &self.device.snapshot { ui.label(format!("Online · {}", snapshot.identity)); }
|
||||
else { ui.label("Offline"); }
|
||||
if !self.device.error.is_empty() { ui.colored_label(ui.visuals().error_fg_color, &self.device.error); }
|
||||
if let Some(error) = &self.settings.error { ui.colored_label(ui.visuals().error_fg_color, error); }
|
||||
});
|
||||
self.device.connection_open = open;
|
||||
if before != self.device.host {
|
||||
self.settings.save(&self.application_settings(ctx));
|
||||
}
|
||||
}
|
||||
pub(super) fn device_window(&mut self, ctx: &egui::Context) {
|
||||
self.device.poll();
|
||||
self.connection_window(ctx);
|
||||
if !self.device.open {
|
||||
return;
|
||||
}
|
||||
let mut open = true;
|
||||
let mut imported = false;
|
||||
let mut send_plan = None;
|
||||
egui::Window::new("Midra connection")
|
||||
egui::Window::new(if self.device.prepare_send { "Send layers to Midra" } else { "Import layers from Midra" })
|
||||
.open(&mut open).default_width(660.0).collapsible(false)
|
||||
.max_height((ctx.screen_rect().height() - 100.0).max(200.0)).vscroll(true)
|
||||
.show(ctx, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.selectable_value(&mut self.device.prepare_send, false, "Import from Midra");
|
||||
ui.selectable_value(&mut self.device.prepare_send, true, "Send layers to Midra");
|
||||
});
|
||||
if self.device.prepare_send {
|
||||
self.transfer_layer_picker(ui, "Choose editor layers to send…");
|
||||
}
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Device IP");
|
||||
if ui.add_enabled(self.device.pending.is_none(), egui::TextEdit::singleline(&mut self.device.host).hint_text("192.168.…")).changed() {
|
||||
self.device.snapshot = None;
|
||||
self.device.destinations.clear();
|
||||
}
|
||||
if ui.add_enabled(self.device.pending.is_none(), egui::Button::new("Read / refresh")).clicked() { self.device.fetch(ctx); }
|
||||
if ui.button("Connection settings…").clicked() { self.device.connection_open = true; }
|
||||
if ui.add_enabled(self.device.online() && self.device.pending.is_none(), egui::Button::new("Refresh layers")).clicked() { self.device.fetch(ctx); }
|
||||
});
|
||||
if !self.device.online() && self.device.pending.is_none() { ui.label("Connect to a Midra in Connection settings before transferring layers."); }
|
||||
if self.device.pending.is_some() {
|
||||
ui.horizontal(|ui| { ui.spinner(); ui.label(if self.device.sending { "Sending and checking readback…" } else { "Reading device… editing remains available." }); });
|
||||
if !self.device.sending && ui.button("Cancel read").clicked() { self.device.pending = None; }
|
||||
|
|
@ -464,8 +508,19 @@ mod tests {
|
|||
let ctx = egui::Context::default();
|
||||
let mut app = Editor::default();
|
||||
let before = app.layout.layers().clone();
|
||||
app.device.host = "192.168.10.143".into();
|
||||
let saved = app.application_settings(&ctx);
|
||||
let mut app = Editor::with_settings(&ctx, settings::Store::default(), saved);
|
||||
assert_eq!(app.device.host, "192.168.10.143");
|
||||
assert!(!app.device.online());
|
||||
app.device.connection_open = true;
|
||||
super::super::tests::frame(&mut app, &ctx, vec![]);
|
||||
assert!(app.device.pending.is_none());
|
||||
assert!(!app.device.open);
|
||||
app.device.connection_open = false;
|
||||
app.device.open = true;
|
||||
super::super::tests::frame(&mut app, &ctx, vec![]);
|
||||
assert!(!app.device.connection_open);
|
||||
assert!(app.device.pending.is_none());
|
||||
assert_eq!(*app.layout.layers(), before);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -276,6 +276,7 @@ impl Editor {
|
|||
theme::Theme::restore_recent(ctx, saved.recent_themes.clone());
|
||||
saved.theme.apply(ctx);
|
||||
Self {
|
||||
device: device_ui::DeviceUi::with_host(saved.midra_host),
|
||||
settings: store,
|
||||
snapping: saved.snapping,
|
||||
keep_aspect_ratio: saved.keep_aspect_ratio,
|
||||
|
|
@ -286,6 +287,7 @@ impl Editor {
|
|||
}
|
||||
fn application_settings(&self, ctx: &egui::Context) -> settings::Settings {
|
||||
settings::Settings {
|
||||
midra_host: self.device.host.clone(),
|
||||
theme: theme::Theme::current(ctx),
|
||||
recent_themes: theme::Theme::recent(ctx),
|
||||
snapping: self.snapping,
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ impl Editor {
|
|||
|
||||
pub(super) fn import_menu(&mut self, ui: &mut egui::Ui) {
|
||||
ui.set_min_width(225.0);
|
||||
if ui.button("Midra Preview…").clicked() {
|
||||
if ui.button("Midra layers…").clicked() {
|
||||
self.device.prepare_send = false;
|
||||
self.device.open = true;
|
||||
ui.close_menu();
|
||||
|
|
@ -197,6 +197,10 @@ impl Editor {
|
|||
ui.close_menu();
|
||||
}
|
||||
ui.separator();
|
||||
if ui.button("Midra connection…").clicked() {
|
||||
self.device.connection_open = true;
|
||||
ui.close_menu();
|
||||
}
|
||||
ui.menu_button("Project", |ui| self.project_menu(ui));
|
||||
ui.menu_button("Import", |ui| self.import_menu(ui));
|
||||
ui.menu_button("Edit", |ui| {
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ impl Editor {
|
|||
Section::Device => {
|
||||
ui.heading("Midra integration");
|
||||
ui.label("Read Preview layer containers from an Eikos 4K and review their mapping before import.");
|
||||
if ui.button("Open Midra connection…").clicked() { self.device.open = true; }
|
||||
if ui.button("Open Midra connection…").clicked() { self.device.connection_open = true; }
|
||||
ui.weak("Read snapshots and explicitly send reviewed size, position and crop changes.");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,8 +56,10 @@ impl Editor {
|
|||
})
|
||||
.transpose()?;
|
||||
let e = project.editor;
|
||||
self.device.reset_mappings();
|
||||
// Replace only after both the document and embedded image are ready.
|
||||
*self = Self {
|
||||
device: std::mem::take(&mut self.device),
|
||||
settings: std::mem::take(&mut self.settings),
|
||||
snapping: self.snapping,
|
||||
layout,
|
||||
|
|
@ -314,7 +316,9 @@ mod tests {
|
|||
let settings_dir = tempfile::tempdir().unwrap();
|
||||
let settings_path = settings_dir.path().join("settings.json");
|
||||
restored.settings = settings::Store::at(settings_path.clone()).0;
|
||||
restored.device.host = "192.168.10.143".into();
|
||||
restored.install_project(&ctx, project.clone()).unwrap();
|
||||
assert_eq!(restored.device.host, "192.168.10.143");
|
||||
assert_eq!(restored.settings.path.as_ref(), Some(&settings_path));
|
||||
assert!(
|
||||
!settings_path.exists(),
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use std::{io::Read, path::PathBuf};
|
|||
#[serde(deny_unknown_fields)]
|
||||
pub struct Settings {
|
||||
pub version: u32,
|
||||
pub midra_host: String,
|
||||
pub theme: Theme,
|
||||
pub recent_themes: Vec<Theme>,
|
||||
pub snapping: midra_layout::snapping::Snapping,
|
||||
|
|
@ -17,7 +18,8 @@ pub struct Settings {
|
|||
impl Default for Settings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
version: 3,
|
||||
version: 4,
|
||||
midra_host: String::new(),
|
||||
theme: Theme::Midra,
|
||||
recent_themes: vec![Theme::Midra],
|
||||
snapping: Default::default(),
|
||||
|
|
@ -54,12 +56,19 @@ impl Settings {
|
|||
.map_err(|e| e.to_string())?;
|
||||
value["version"] = 3.into();
|
||||
}
|
||||
if value["version"] == 3 {
|
||||
if value.get("midra_host").is_some() {
|
||||
return Err("Unexpected midra_host in version 3 settings".into());
|
||||
}
|
||||
value["midra_host"] = "".into();
|
||||
value["version"] = 4.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 != 3 {
|
||||
if self.version != 4 {
|
||||
return Err(format!("unsupported settings version {}", self.version));
|
||||
}
|
||||
if self.recent_themes.is_empty()
|
||||
|
|
@ -177,6 +186,7 @@ mod tests {
|
|||
settings.show_toolbar_icon_names = true;
|
||||
settings.keep_aspect_ratio = false;
|
||||
settings.show_source_pattern = true;
|
||||
settings.midra_host = "192.168.10.143".into();
|
||||
store.save(&settings);
|
||||
assert!(store.error.is_none());
|
||||
assert_eq!(Store::at(path.clone()).1, settings);
|
||||
|
|
@ -196,7 +206,7 @@ mod tests {
|
|||
for text in [
|
||||
"broken".to_string(),
|
||||
serde_json::to_string(&Settings {
|
||||
version: 4,
|
||||
version: 5,
|
||||
..Default::default()
|
||||
})
|
||||
.unwrap(),
|
||||
|
|
@ -221,6 +231,18 @@ mod tests {
|
|||
assert_eq!(Store::at(blocker.join("settings.json")).1, settings);
|
||||
}
|
||||
#[test]
|
||||
fn version_four_remembers_address_and_migrates_legacy_without_it() {
|
||||
let example =
|
||||
include_str!("../../../docs/interfaces/midra-layout-settings-v4.example.json");
|
||||
assert_eq!(Settings::parse(example).unwrap(), Settings::default());
|
||||
let mut legacy: serde_json::Value = serde_json::from_str(include_str!(
|
||||
"../../../docs/interfaces/midra-layout-settings-v3.example.json"
|
||||
))
|
||||
.unwrap();
|
||||
legacy["midra_host"] = "192.168.10.143".into();
|
||||
assert!(Settings::parse(&legacy.to_string()).is_err());
|
||||
}
|
||||
#[test]
|
||||
fn documented_settings_match_defaults() {
|
||||
let example =
|
||||
include_str!("../../../docs/interfaces/midra-layout-settings-v1.example.json");
|
||||
|
|
|
|||
|
|
@ -74,6 +74,5 @@ Readback checks every changed field. No-op plans are disabled. Failure reports
|
|||
partial/uncertain outcomes without blind retries or automatic rollback.
|
||||
|
||||
Program selection is explicit. The application defaults to Preview. Mappings,
|
||||
plans, raw snapshots and connection addresses are not saved in projects or
|
||||
preferences. Refresh and screen changes reset destination review. Physical display
|
||||
plans and raw snapshots are not saved in projects or preferences. The device address is saved in [application settings](midra-layout-settings.md), never in projects. Refresh and screen changes reset destination review. Physical display
|
||||
validation remains separate from the successful device-field and import round trips.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"version": 4,
|
||||
"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
|
||||
},
|
||||
"midra_host": ""
|
||||
}
|
||||
|
|
@ -1,13 +1,13 @@
|
|||
# Midra Layout application settings, version 3
|
||||
# Midra Layout application settings, version 4
|
||||
|
||||
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-v3.example.json).
|
||||
[Complete default example](midra-layout-settings-v4.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. Saving writes version 3; 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. Saving writes version 4; 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,8 @@ unknown theme names are rejected. There are no numeric coordinates or units.
|
|||
|
||||
| Field | Values / default |
|
||||
| --- | --- |
|
||||
| `version` | Integer `3` |
|
||||
| `version` | Integer `4` |
|
||||
| `midra_host` | Device IP address text; default `""`. Saved as typed, including incomplete drafts; validated when connecting. |
|
||||
| `theme` | Theme ID from the catalog below; default `"midra"` |
|
||||
| `recent_themes` | 1–3 unique theme IDs, newest first; first must equal `theme`; default `["midra"]` |
|
||||
| `show_toolbar_icon_names` | Boolean; default false |
|
||||
|
|
@ -54,8 +55,9 @@ the previous destination where atomic publication failed; Options offers a retry
|
|||
Failure to locate a configuration directory also disables persistence with an
|
||||
Options error. Tests use temporary directories and never touch user settings.
|
||||
|
||||
No layer geometry, source crops, camera state, project paths, image bytes, device
|
||||
addresses or clipboard contents are stored. No settings are exported to SVG.
|
||||
The device address is saved immediately when edited in **Midra connection…**. Loading settings never connects or sends. Opening a project preserves the current connection and address, and clears transfer mappings. Connection status, snapshots and mappings are not persisted. Restore default preferences leaves the connection address unchanged; edit it in the connection window.
|
||||
|
||||
No layer geometry, source crops, camera state, project paths, image bytes or clipboard contents are stored. No settings are exported to SVG.
|
||||
Breaking or additive schema changes under this strict contract require a version
|
||||
bump, updated documentation/examples/tests, and either an explicit migration or
|
||||
an actionable unsupported-version error.
|
||||
|
|
@ -95,7 +97,7 @@ The picker includes both light and dark themes with color swatches.
|
|||
|
||||
The Preferences window and quick menus share the same settings. Changes apply
|
||||
and save immediately; closing the window requires no Apply step. Restore default
|
||||
preferences resets all values, including theme history and snapping, without
|
||||
preferences resets appearance and editing values, including theme history and snapping, without
|
||||
changing layer geometry or pending position/size text fields. Snapping uses a
|
||||
fixed six-logical-pixel proximity radius converted by viewport scale. It affects
|
||||
layer movement and resize handles; numeric entry, nudges and crop-content gestures
|
||||
|
|
|
|||
|
|
@ -46,8 +46,7 @@ above come from the installed device and its own WebRCS bundle.
|
|||
|
||||
## Read-only import bridge
|
||||
|
||||
The desktop app now has **Import → Midra Preview…**, also accessible from
|
||||
**Preferences → Midra integration**. Enter the device IP and click **Read / refresh**.
|
||||
Open **Midra connection…** in the main menu or **Preferences → Midra integration**. Enter the device IP and click **Connect**. Then open the separate **Import → Midra layers…** window.
|
||||
Reads run in a worker thread; canceling discards late results. Choose a screen and
|
||||
choose a destination beside each device layer: **Do not import**, **New layer**,
|
||||
or an existing visible, unlocked editor layer. Click **Import layers** directly
|
||||
|
|
@ -55,7 +54,7 @@ in this window; no prior selection or matching layer count is required. Duplicat
|
|||
or removed destinations are rejected without partial changes. The entire import,
|
||||
including new layers, is one undo step. Output resolutions must match. Reading never
|
||||
changes the document; only applying the reviewed import does. No automatic
|
||||
connection or polling occurs, and no credentials or address are persisted. The
|
||||
connection or polling occurs. The address is remembered in application settings; no credentials are stored. The
|
||||
footer shows **ONLINE** after a successful read (last-read status, not continuous
|
||||
monitoring), and **OFFLINE** when refreshing, after a failed read, or after editing
|
||||
the address.
|
||||
|
|
|
|||
|
|
@ -517,7 +517,9 @@ handles retain their existing behavior. One drag remains one undo step, with Esc
|
|||
|
||||
## Midra connection and sending
|
||||
|
||||
Open **Import → Midra Preview…**, enter the device IP, then **Read / refresh**.
|
||||
Open **Midra connection…** in the main menu (also in **Preferences → Midra integration**), enter the device IP, then **Connect**. The address saves automatically in the application config and survives project loads and restarts; startup does not connect automatically.
|
||||
|
||||
Open **Import → Midra layers…** for the separate layer import window. **Refresh layers** reads a fresh snapshot; **Connection settings…** opens the connection window.
|
||||
Choose a destination beside each device layer: existing layer, new layer, or skip.
|
||||
Centered crops import visible bounds and framing; unsupported aspect/mask cases
|
||||
are explained in the review. Imports are one undoable edit.
|
||||
|
|
|
|||
Loading…
Reference in New Issue