Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions installer/DirectorSetup.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@
<bal:Condition Condition="WindowsBuildNumber &gt;= 26100"
Message="Director needs Windows 11, version 24H2 or newer. Update Windows from Settings &gt; Windows Update, then run setup again." />

<!-- Director 0.9.1 and earlier could install just for the current user. Windows Installer cannot upgrade
that copy from a machine-wide install, so ask the user to remove it first. Presets are kept. -->
<util:RegistrySearch Id="PerUserDirectorSearch" Variable="PerUserDirectorInstalled" Result="exists"
Root="HKCU" Key="Software\Director\Installer" Value="UserPath" />
<bal:Condition Condition="NOT PerUserDirectorInstalled"
Message="An earlier Director preview is installed just for your account. Uninstall it from Settings &gt; Apps &gt; Installed apps, then run setup again. Your presets, scenes and TV pairings are kept." />

<Chain>
<ExePackage Id="WindowsAppRuntime" DisplayName="Windows App Runtime $(var.RuntimeVersion)"
Expand Down
4 changes: 2 additions & 2 deletions src/audio_devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ mod tests {
);
assert_eq!(
inventory
.resolve("old", false, &[endpoint("legacy", None)])
.resolve("old", false, &[endpoint("no-stable-id", None)])
.as_deref(),
Some("legacy")
Some("no-stable-id")
);
}
}
40 changes: 4 additions & 36 deletions src/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,15 @@ use std::{
};

const LIMIT: u64 = 8 * 1024 * 1024;
/// Version 2 drops audio presets: scenes hold their sound. Version 1 backups still restore;
/// their scenes' audio presets are migrated into the Sound step.
const VERSION: u8 = 2;
/// The backup file format. Other versions are refused.
const VERSION: u8 = 1;

#[derive(Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
struct Backup {
version: u8,
scenes: Vec<scenes::Scene>,
displays: Vec<displays::Preset>,
/// Version 1 audio presets, read only to migrate the scenes that used them.
#[serde(default, skip_serializing)]
audio: Option<serde_json::Value>,
tv_names: BTreeMap<String, String>,
}

Expand Down Expand Up @@ -84,7 +80,6 @@ pub fn export(path: &Path) -> Result<(), String> {
version: VERSION,
scenes,
displays,
audio: None,
tv_names,
};
let bytes = serde_json::to_vec_pretty(&backup).map_err(|e| e.to_string())?;
Expand Down Expand Up @@ -114,16 +109,11 @@ fn read(path: &Path) -> Result<Backup, String> {
if bytes.len() as u64 > LIMIT {
return Err("The backup is too large.".into());
}
let mut backup: Backup =
let backup: Backup =
serde_json::from_slice(&bytes).map_err(|e| format!("Invalid Director backup: {e}"))?;
if !(1..=VERSION).contains(&backup.version) {
if backup.version != VERSION {
return Err("This backup version is unsupported.".into());
}
let legacy = backup
.audio
.take()
.and_then(|v| v.get("presets").cloned().or(Some(v)));
scenes::migrate(&mut backup.scenes, legacy);
scenes::validate_backup(&backup.scenes)?;
displays::validate(&backup.displays)?;
Ok(backup)
Expand Down Expand Up @@ -279,7 +269,6 @@ mod tests {
version: VERSION,
scenes: vec![],
displays: vec![],
audio: None,
tv_names: BTreeMap::new(),
};
let file = folder.join("Director.director-backup");
Expand All @@ -304,25 +293,4 @@ mod tests {
restore_catalog(&import, &scene_path, &display_path).unwrap();
assert!(displays::load(&display_path).unwrap().is_empty());
}

#[test]
fn version_one_backups_migrate_audio_presets_into_scene_sound() {
let folder =
std::env::temp_dir().join(format!("director-backup-v1-{}", std::process::id()));
fs::create_dir_all(&folder).unwrap();
let file = folder.join("old.director-backup");
let v1 = serde_json::json!({
"version": 1,
"scenes": [{"id":"s","name":"Desk","display":null,"audio":"p","tv":null,"actions":[]}],
"displays": [],
"audio": [{"id":"p","name":"Desk sound","output_id":"soundbar","output_name":"SOUNDBAR","volume_percent":10,"keep_changes":false}],
"tv_names": {}
});
fs::write(&file, serde_json::to_vec(&v1).unwrap()).unwrap();
let backup = read(&file).unwrap();
let sound = backup.scenes[0].sound.as_ref().unwrap();
assert_eq!(sound.volume, Some(10));
assert!(matches!(&sound.output, Some(SoundOutput::Device { id, .. }) if id == "soundbar"));
let _ = fs::remove_dir_all(folder);
}
}
10 changes: 4 additions & 6 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ requires it. Applying a scene first runs the previous scene's When leaving steps
runs them without applying another scene.";

/// `director list`, or `<area> list` and the other read-only lists, with an optional
/// `--json`. Older spellings (`display presets`, `display current`) still work.
/// `--json`.
fn list_command(args: &[String]) -> Option<(&'static [crate::cli_list::Category], bool, bool)> {
use crate::cli_list::Category;
let mut words: Vec<&str> = args.iter().map(String::as_str).collect();
Expand All @@ -67,8 +67,8 @@ fn list_command(args: &[String]) -> Option<(&'static [crate::cli_list::Category]
let categories: &'static [Category] = match words.as_slice() {
["list"] => &Category::ALL,
["scene", "list"] => &[Category::Scenes],
["display", "list" | "presets"] => &[Category::DisplayPresets],
["display", "screens" | "current"] => &[Category::Screens],
["display", "list"] => &[Category::DisplayPresets],
["display", "screens"] => &[Category::Screens],
["audio", "list"] => &[Category::AudioOutputs, Category::AudioInputs],
["audio", "outputs"] => &[Category::AudioOutputs],
["audio", "inputs"] => &[Category::AudioInputs],
Expand Down Expand Up @@ -146,9 +146,7 @@ mod tests {
for (command, wanted) in [
("scene list", Category::Scenes),
("display list", Category::DisplayPresets),
("display presets", Category::DisplayPresets),
("display screens", Category::Screens),
("display current", Category::Screens),
("audio outputs", Category::AudioOutputs),
("audio inputs --json", Category::AudioInputs),
("tv list", Category::Tvs),
Expand All @@ -158,7 +156,7 @@ mod tests {
"{command}"
);
}
assert!(list("audio presets").is_none());
assert!(list("display presets").is_none());
assert!(list("list scenes").is_none());
assert!(list("audio list extra").is_none());
assert!(list("scene apply desk").is_none());
Expand Down
4 changes: 2 additions & 2 deletions src/cli_name.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Command-line names: "Desk View" is `desk-view`, so names never need quotes.
//!
//! CLI names are derived from the saved name every time and never stored. Lookups accept an
//! exact ID or anything that normalizes to the same CLI name, so older quoted commands such
//! as `"Desk View"` keep working.
//! exact ID or anything that normalizes to the same CLI name, so a quoted name such as
//! `"Desk View"` works too.

/// Lowercase letters and digits, with every run of other characters turned into one `-`.
/// Empty only for a name made entirely of symbols.
Expand Down
4 changes: 2 additions & 2 deletions src/current_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ impl CurrentState {
self.display.editor = Some(Editor::new(&layout, options));
self.display.drag = None;
self.display.draft = Some(Preset {
id: "current-setup-session".into(),
name: "Current setup".into(),
id: "now-session".into(),
name: "Now".into(),
captured_at_unix_seconds: 0,
confirm_changes: false,
layout,
Expand Down
6 changes: 3 additions & 3 deletions src/display_apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,9 @@ pub(crate) mod tests {
let result = apply(&mut backend, &wanted, || true);
assert_eq!(result.outcome, Outcome::Failed);
assert_eq!(backend.current.monitors[0].hdr, Some(false));
let mut legacy = wanted.clone();
legacy.monitors[0].hdr = None;
assert!(verify(&legacy, &before).is_ok());
let mut unset = wanted.clone();
unset.monitors[0].hdr = None;
assert!(verify(&unset, &before).is_ok());
}
#[test]
fn no_op_and_preflight_failures_never_write() {
Expand Down
14 changes: 3 additions & 11 deletions src/displays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub struct Monitor {
pub device_path: Option<String>,
pub name: String,
pub connected: bool,
/// None preserves legacy behavior: leave HDR unchanged.
/// None leaves the screen's HDR state as it is when the preset is applied.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub hdr: Option<bool>,
pub enabled: bool,
Expand Down Expand Up @@ -152,13 +152,9 @@ pub struct Preset {
pub id: String,
pub name: String,
pub captured_at_unix_seconds: u64,
#[serde(default = "confirmation_default")]
pub confirm_changes: bool,
pub layout: Layout,
}
fn confirmation_default() -> bool {
true
}
#[derive(Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
struct Document {
Expand Down Expand Up @@ -287,13 +283,9 @@ pub(crate) mod tests {
);
}
#[test]
fn legacy_presets_require_confirmation_and_opt_out_round_trips() {
fn confirmation_opt_out_round_trips() {
let original = sample();
let mut json = serde_json::to_value(&original).unwrap();
json.as_object_mut().unwrap().remove("confirm_changes");
let legacy: Preset = serde_json::from_value(json).unwrap();
assert!(legacy.confirm_changes);
let mut automatic = legacy.clone();
let mut automatic = original.clone();
automatic.confirm_changes = false;
let restored: Preset =
serde_json::from_slice(&serde_json::to_vec(&automatic).unwrap()).unwrap();
Expand Down
33 changes: 6 additions & 27 deletions src/preferences.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,19 @@ pub struct Preferences {
pub hide_tv_setup_tip: bool,
#[serde(default)]
pub notify_scene_failures: bool,
/// Keep steps that finished when a later scene or audio preset step fails.
/// Keep steps that finished when a later scene step fails.
#[serde(default)]
pub keep_completed_changes: bool,
/// How long scenes wait for a TV or audio device, and for waited apps (1–120 s).
#[serde(default = "default_wait")]
pub device_wait_seconds: u16,
/// The Scenes page's "make your next scene" tip was dismissed. Written only when set, so
/// older builds keep reading the file until the tip is dismissed.
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
/// The Scenes page's "make your next scene" tip was dismissed.
#[serde(default)]
pub hide_next_scene_tip: bool,
/// After a scene selects a TV input, keep switching back to it for this long when a TV
/// box or console takes the input over (0–60 s, 0 = off). Only for TVs that report
/// their input. Written only when changed, so older builds keep reading the file.
#[serde(
default = "default_input_guard",
skip_serializing_if = "is_default_input_guard"
)]
/// their input.
#[serde(default = "default_input_guard")]
pub tv_input_guard_seconds: u16,
}
fn default_wait() -> u16 {
Expand All @@ -33,9 +29,6 @@ fn default_wait() -> u16 {
fn default_input_guard() -> u16 {
crate::tv_input_guard::DEFAULT_SECONDS
}
fn is_default_input_guard(seconds: &u16) -> bool {
*seconds == default_input_guard()
}
impl Default for Preferences {
fn default() -> Self {
Self {
Expand Down Expand Up @@ -127,13 +120,6 @@ mod tests {
assert_eq!(initial.device_wait_seconds, 30);
assert!(!initial.hide_next_scene_tip);
assert_eq!(initial.tv_input_guard_seconds, 10);
std::fs::write(
&path,
br#"{"version":1,"preferences":{"hide_tv_setup_tip":false,"notify_scene_failures":false,"keep_completed_changes":false,"device_wait_seconds":30}}"#,
)
.unwrap();
assert_eq!(load(&path).unwrap(), initial, "older files still load");
std::fs::remove_file(&path).unwrap();
assert_eq!(initial.audio_policy(), crate::audio::FailurePolicy::Revert);
let hidden = Preferences {
hide_tv_setup_tip: true,
Expand All @@ -146,15 +132,8 @@ mod tests {
save(&path, &initial, &hidden).unwrap();
assert_eq!(load(&path).unwrap(), hidden);
assert_eq!(hidden.scene_policy().input_guard_seconds, 0);
let written = std::fs::read_to_string(&path).unwrap();
assert!(written.contains("tv_input_guard_seconds"));
save(&path, &hidden, &initial).unwrap();
assert!(
!std::fs::read_to_string(&path)
.unwrap()
.contains("tv_input_guard_seconds"),
"the default stays out of the file for older builds"
);
assert_eq!(load(&path).unwrap(), initial);
save(&path, &initial, &hidden).unwrap();
assert!(save(&path, &initial, &initial).is_err());
let future = br#"{"version":99,"preferences":{"hide_tv_setup_tip":false}}"#;
Expand Down
4 changes: 2 additions & 2 deletions src/samsung.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ pub fn report(tv: &crate::tvs::Tv) -> Result<CompatibilityReport, String> {
test.firmware = clean(&test.firmware);
}
Ok(CompatibilityReport {
format_version: 2,
format_version: 1,
director_version: env!("CARGO_PKG_VERSION"),
brand: tv.brand.label(),
model: clean(&tv.compatibility().model),
Expand Down Expand Up @@ -320,7 +320,7 @@ mod tests {
}
#[test]
fn report_is_an_allowlist_and_never_serializes_secrets_or_addresses() {
let tv:crate::tvs::Tv=serde_json::from_value(serde_json::json!({"id":"private-id","name":"private-alias","brand":"samsung","address":"192.0.2.50","display":null,"credential":[1,2,3],"samsung":{"model":"S90C","firmware":"1234","tests":[]}})).unwrap();
let tv:crate::tvs::Tv=serde_json::from_value(serde_json::json!({"id":"private-id","name":"private-alias","brand":"samsung","connection":"encrypted","address":"192.0.2.50","display":null,"credential":[1,2,3],"samsung":{"model":"S90C","firmware":"1234","tests":[]}})).unwrap();
let data = serde_json::to_string(&report(&tv).unwrap()).unwrap();
assert!(data.contains("S90C"));
for value in [
Expand Down
Loading
Loading