desktop: Make recent limit user configurable
This commit is contained in:
parent
a33c18b309
commit
9db308ddf8
|
@ -20,4 +20,6 @@ log-filename-pattern-with-timestamp = With Timestamp
|
|||
|
||||
storage-backend = Save-File Location
|
||||
storage-backend-disk = Disk
|
||||
storage-backend-memory = Memory
|
||||
storage-backend-memory = Memory
|
||||
|
||||
recent-limit = Recent Limit
|
|
@ -207,13 +207,13 @@ impl RuffleGui {
|
|||
mut player: MutexGuard<Player>,
|
||||
) {
|
||||
self.currently_opened = Some((movie_url.clone(), opt.clone()));
|
||||
let recent_limit = self.preferences.recent_limit();
|
||||
if let Err(e) = self.preferences.write_recents(|writer| {
|
||||
writer.push(
|
||||
Recent {
|
||||
url: movie_url.clone(),
|
||||
},
|
||||
// TODO: Add user configurable recent limit.
|
||||
10,
|
||||
recent_limit,
|
||||
)
|
||||
}) {
|
||||
tracing::warn!("Couldn't update recents: {e}");
|
||||
|
|
|
@ -2,7 +2,7 @@ use crate::gui::{available_languages, optional_text, text};
|
|||
use crate::log::FilenamePattern;
|
||||
use crate::preferences::{storage::StorageBackend, GlobalPreferences};
|
||||
use cpal::traits::{DeviceTrait, HostTrait};
|
||||
use egui::{Align2, Button, ComboBox, Grid, Ui, Widget, Window};
|
||||
use egui::{Align2, Button, ComboBox, DragValue, Grid, Ui, Widget, Window};
|
||||
use ruffle_render_wgpu::clap::{GraphicsBackend, PowerPreference};
|
||||
use std::borrow::Cow;
|
||||
use unic_langid::LanguageIdentifier;
|
||||
|
@ -26,6 +26,9 @@ pub struct PreferencesDialog {
|
|||
available_output_devices: Vec<String>,
|
||||
output_device_changed: bool,
|
||||
|
||||
recent_limit: usize,
|
||||
recent_limit_changed: bool,
|
||||
|
||||
log_filename_pattern: FilenamePattern,
|
||||
log_filename_pattern_changed: bool,
|
||||
|
||||
|
@ -65,6 +68,9 @@ impl PreferencesDialog {
|
|||
available_output_devices,
|
||||
output_device_changed: false,
|
||||
|
||||
recent_limit: preferences.recent_limit(),
|
||||
recent_limit_changed: false,
|
||||
|
||||
log_filename_pattern: preferences.log_filename_pattern(),
|
||||
log_filename_pattern_changed: false,
|
||||
|
||||
|
@ -101,6 +107,8 @@ impl PreferencesDialog {
|
|||
self.show_log_preferences(locale, ui);
|
||||
|
||||
self.show_storage_preferences(locale, &locked_text, ui);
|
||||
|
||||
self.show_misc_preferences(locale, ui);
|
||||
});
|
||||
|
||||
if self.restart_required() {
|
||||
|
@ -313,6 +321,19 @@ impl PreferencesDialog {
|
|||
ui.end_row();
|
||||
}
|
||||
|
||||
fn show_misc_preferences(&mut self, locale: &LanguageIdentifier, ui: &mut Ui) {
|
||||
ui.label(text(locale, "recent-limit"));
|
||||
|
||||
let previous = self.recent_limit;
|
||||
DragValue::new(&mut self.recent_limit).ui(ui);
|
||||
|
||||
if self.recent_limit != previous {
|
||||
self.recent_limit_changed = true;
|
||||
}
|
||||
|
||||
ui.end_row()
|
||||
}
|
||||
|
||||
fn save(&mut self) {
|
||||
if let Err(e) = self.preferences.write_preferences(|preferences| {
|
||||
if self.graphics_backend_changed {
|
||||
|
@ -334,6 +355,9 @@ impl PreferencesDialog {
|
|||
if self.storage_backend_changed {
|
||||
preferences.set_storage_backend(self.storage_backend);
|
||||
}
|
||||
if self.recent_limit_changed {
|
||||
preferences.set_recent_limit(self.recent_limit);
|
||||
}
|
||||
}) {
|
||||
// [NA] TODO: Better error handling... everywhere in desktop, really
|
||||
tracing::error!("Could not save preferences: {e}");
|
||||
|
|
|
@ -173,6 +173,13 @@ impl GlobalPreferences {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn recent_limit(&self) -> usize {
|
||||
self.preferences
|
||||
.lock()
|
||||
.expect("Preferences is not reentrant")
|
||||
.recent_limit
|
||||
}
|
||||
|
||||
pub fn recents(&self, fun: impl FnOnce(&Recents)) {
|
||||
fun(&self.recents.lock().expect("Recents is not reentrant"))
|
||||
}
|
||||
|
@ -222,6 +229,7 @@ pub struct SavedGlobalPreferences {
|
|||
pub output_device: Option<String>,
|
||||
pub mute: bool,
|
||||
pub volume: f32,
|
||||
pub recent_limit: usize,
|
||||
pub log: LogPreferences,
|
||||
pub storage: StoragePreferences,
|
||||
}
|
||||
|
@ -239,6 +247,7 @@ impl Default for SavedGlobalPreferences {
|
|||
output_device: None,
|
||||
mute: false,
|
||||
volume: 1.0,
|
||||
recent_limit: 10,
|
||||
log: Default::default(),
|
||||
storage: Default::default(),
|
||||
}
|
||||
|
|
|
@ -51,6 +51,10 @@ pub fn read_preferences(input: &str) -> ParseDetails<SavedGlobalPreferences> {
|
|||
result.mute = value;
|
||||
};
|
||||
|
||||
if let Some(value) = document.get_integer(&mut cx, "recent_limit") {
|
||||
result.recent_limit = value as usize;
|
||||
}
|
||||
|
||||
document.get_table_like(&mut cx, "log", |cx, log| {
|
||||
if let Some(value) = log.parse_from_str(cx, "filename_pattern") {
|
||||
result.log.filename_pattern = value;
|
||||
|
@ -430,4 +434,51 @@ mod tests {
|
|||
result.warnings
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recent_limit() {
|
||||
let result = read_preferences("recent_limit = \"1\"");
|
||||
assert_eq!(
|
||||
&SavedGlobalPreferences {
|
||||
recent_limit: 10,
|
||||
..Default::default()
|
||||
},
|
||||
result.values()
|
||||
);
|
||||
assert_eq!(
|
||||
vec![ParseWarning::UnexpectedType {
|
||||
expected: "integer",
|
||||
actual: "string",
|
||||
path: "recent_limit".to_string(),
|
||||
}],
|
||||
result.warnings
|
||||
);
|
||||
|
||||
let result = read_preferences("recent_limit = 0.5");
|
||||
assert_eq!(
|
||||
&SavedGlobalPreferences {
|
||||
recent_limit: 10,
|
||||
..Default::default()
|
||||
},
|
||||
result.values()
|
||||
);
|
||||
assert_eq!(
|
||||
vec![ParseWarning::UnexpectedType {
|
||||
expected: "integer",
|
||||
actual: "float",
|
||||
path: "recent_limit".to_string(),
|
||||
}],
|
||||
result.warnings
|
||||
);
|
||||
|
||||
let result = read_preferences("recent_limit = 5");
|
||||
assert_eq!(
|
||||
&SavedGlobalPreferences {
|
||||
recent_limit: 5,
|
||||
..Default::default()
|
||||
},
|
||||
result.values()
|
||||
);
|
||||
assert_eq!(Vec::<ParseWarning>::new(), result.warnings);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,6 +72,13 @@ impl<'a> PreferencesWriter<'a> {
|
|||
values.storage.backend = backend;
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_recent_limit(&mut self, limit: usize) {
|
||||
self.0.edit(|values, toml_document| {
|
||||
toml_document["recent_limit"] = value(limit as i64);
|
||||
values.recent_limit = limit;
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -198,4 +205,18 @@ mod tests {
|
|||
"[storage]\nbackend = \"memory\"\n",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_recent_limit() {
|
||||
test(
|
||||
"",
|
||||
|writer| writer.set_recent_limit(40),
|
||||
"recent_limit = 40\n",
|
||||
);
|
||||
test(
|
||||
"recent_limit = 5",
|
||||
|writer| writer.set_recent_limit(15),
|
||||
"recent_limit = 15\n",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue