mirror of
https://github.com/VallierDev/uu-remote-linux.git
synced 2026-11-16 16:50:41 +01:00
控制端:跨会话记住画质、帧率和真彩设置 (#133)
The host starts every session at the official defaults (Auto, 60 fps, 4:2:0), so a choice made for a slow link was lost on reconnect. Save them in viewer.json with the other preferences and send the ones that differ once CONTROL answers the echo.
This commit is contained in:
1 parent
4cfdd563f7
commit
6a0cd5bda6
2 files changed
+18
-5
No files matched your search
+7
-3
@@ -137,8 +137,8 @@ pub enum Command {
|
||||
Quality(u64), Fps(u32), Chroma(u32), FollowRemote(bool), OneToOne(bool), Volume(u8),
|
||||
AutoLock(bool), HostMute(bool), GrabKeys(bool), Files, Watch(bool), Stats(bool), HideTab(bool), Fullscreen, Disconnect,
|
||||
}
|
||||
/// What the menu shows as selected. Remote settings start at the official viewer's defaults and
|
||||
/// reflect only this session's choices; the host does not report them back.
|
||||
/// What the menu shows as selected. The host does not report remote settings back; quality, frame
|
||||
/// rate and color are saved and sent again when the next session's CONTROL is ready.
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct State {
|
||||
pub quality: u64, pub fps: u32, pub chroma: u32, pub follow_remote: bool, pub one_to_one: bool, pub volume: u8,
|
||||
@@ -328,11 +328,15 @@ pub fn load_prefs(st: &mut State) {
|
||||
if let Some(b) = v["hide_tab_fullscreen"].as_bool() { st.hide_tab = b; }
|
||||
if let Some(b) = v["one_to_one"].as_bool() { st.one_to_one = b; }
|
||||
if let Some(n) = v["volume"].as_u64() { st.volume = n.min(100) as u8; }
|
||||
if let Some(q) = v["quality"].as_u64().filter(|q| (2..=5).contains(q)) { st.quality = q; }
|
||||
if let Some(f) = v["fps"].as_u64().filter(|f| [30, 60, 90, 144].contains(f)) { st.fps = f as u32; }
|
||||
if let Some(c) = v["chroma"].as_u64().filter(|c| [1, 3].contains(c)) { st.chroma = c as u32; }
|
||||
}
|
||||
pub fn save_prefs(st: &State) {
|
||||
let path = prefs_path();
|
||||
if let Some(dir) = path.parent() { let _ = std::fs::create_dir_all(dir); }
|
||||
let v = serde_json::json!({"stats": st.stats, "hide_tab_fullscreen": st.hide_tab, "one_to_one": st.one_to_one, "volume": st.volume});
|
||||
let v = serde_json::json!({"stats": st.stats, "hide_tab_fullscreen": st.hide_tab, "one_to_one": st.one_to_one, "volume": st.volume,
|
||||
"quality": st.quality, "fps": st.fps, "chroma": st.chroma});
|
||||
let _ = std::fs::write(path, v.to_string());
|
||||
}
|
||||
fn prefs_path() -> std::path::PathBuf { crate::config::path().parent().map_or_else(|| "viewer.json".into(), |d| d.join("viewer.json")) }
|
||||
|
||||
+11
-2
@@ -139,7 +139,8 @@ impl Window {
|
||||
fn command(&mut self,command:hud::Command){
|
||||
let st=&mut self.chrome.state;
|
||||
match command {
|
||||
hud::Command::Quality(q)=>st.quality=q, hud::Command::Fps(f)=>st.fps=f, hud::Command::Chroma(c)=>st.chroma=c,
|
||||
hud::Command::Quality(q)=>{st.quality=q;hud::save_prefs(st)}, hud::Command::Fps(f)=>{st.fps=f;hud::save_prefs(st)},
|
||||
hud::Command::Chroma(c)=>{st.chroma=c;hud::save_prefs(st)},
|
||||
hud::Command::FollowRemote(b)=>st.follow_remote=b, hud::Command::Volume(v)=>st.volume=v,
|
||||
hud::Command::AutoLock(b)=>st.auto_lock=b, hud::Command::HostMute(b)=>st.host_mute=b, hud::Command::Watch(b)=>st.watch=b,
|
||||
hud::Command::OneToOne(b)=>{st.one_to_one=b;hud::save_prefs(st)},
|
||||
@@ -156,6 +157,13 @@ impl Window {
|
||||
self.chrome.commands.push(command);
|
||||
}
|
||||
pub fn take_commands(&mut self)->Vec<hud::Command>{std::mem::take(&mut self.chrome.commands)}
|
||||
/// The host starts every session at the official defaults; repeat the saved choices that differ.
|
||||
pub fn restore_remote_settings(&mut self){
|
||||
let(st,d)=(&self.chrome.state,hud::State::default());let c=&mut self.chrome.commands;
|
||||
if st.quality!=d.quality {c.push(hud::Command::Quality(st.quality));}
|
||||
if st.fps!=d.fps {c.push(hud::Command::Fps(st.fps));}
|
||||
if st.chroma!=d.chroma {c.push(hud::Command::Chroma(st.chroma));}
|
||||
}
|
||||
pub fn state(&self)->&hud::State{&self.chrome.state}
|
||||
pub fn sync_chroma(&mut self,chroma:u32){if chroma!=0 {self.chrome.state.chroma=chroma;}}
|
||||
pub fn set_stage(&mut self,stage:&str){self.chrome.stage=stage.into();}
|
||||
@@ -391,7 +399,7 @@ pub async fn run(session:&mut Session,window:&mut Window,decoder:&mut dyn super:
|
||||
}
|
||||
Err(e)=>{ log::warn!("Type IPC not started: {e}"); None }
|
||||
};
|
||||
let mut command_open=true;let mut requested=false;let mut type_requested=false;
|
||||
let mut command_open=true;let mut requested=false;let mut type_requested=false;let mut restored=false;
|
||||
let mut type_job:Option<TypeJob>=None;
|
||||
let mut terminate=tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate()).map_err(|_|"Cannot watch termination")?;
|
||||
let mut audio=super::audio::Playback::new(&window._sdl,session.peer.audio.clone());
|
||||
@@ -464,6 +472,7 @@ pub async fn run(session:&mut Session,window:&mut Window,decoder:&mut dyn super:
|
||||
if let Some(playback)=audio.as_mut(){if playback.pump().is_err(){log::warn!("Viewer audio playback stopped");audio=None;}}
|
||||
let (quit,mut messages)=window.poll(&mut input);
|
||||
if !window.has_picture() {window.loading_frame(false);}
|
||||
if !restored && session.peer.ready(super::rtc::ReadyPolicy::EchoOnly,false) {restored=true;window.restore_remote_settings();}
|
||||
for command in window.take_commands() {
|
||||
seq+=1;
|
||||
let control=match command {
|
||||
|
||||
Reference in new issue
Block a user