frontend-utils: Move Bookmark from desktop
This commit is contained in:
parent
2b4cec664a
commit
f18d890bea
|
@ -4286,6 +4286,7 @@ name = "ruffle_frontend_utils"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"toml_edit 0.22.9",
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
use crate::gui::text;
|
||||
use crate::gui::widgets::PathOrUrlField;
|
||||
use crate::preferences::{Bookmark, GlobalPreferences};
|
||||
use crate::preferences::GlobalPreferences;
|
||||
use egui::{Align2, Button, Grid, Label, Layout, Sense, Ui, Widget, Window};
|
||||
use egui_extras::{Column, TableBuilder};
|
||||
use ruffle_frontend_utils::bookmarks::Bookmark;
|
||||
use unic_langid::LanguageIdentifier;
|
||||
use url::Url;
|
||||
|
||||
|
|
|
@ -9,12 +9,12 @@ use crate::preferences::read::{read_bookmarks, read_preferences};
|
|||
use crate::preferences::write::{BookmarksWriter, PreferencesWriter};
|
||||
use anyhow::{Context, Error};
|
||||
use ruffle_core::backend::ui::US_ENGLISH;
|
||||
use ruffle_frontend_utils::bookmarks::Bookmarks;
|
||||
use ruffle_frontend_utils::parse::DocumentHolder;
|
||||
use ruffle_render_wgpu::clap::{GraphicsBackend, PowerPreference};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use sys_locale::get_locale;
|
||||
use unic_langid::LanguageIdentifier;
|
||||
use url::Url;
|
||||
|
||||
/// The preferences that relate to the application itself.
|
||||
///
|
||||
|
@ -38,7 +38,7 @@ pub struct GlobalPreferences {
|
|||
/// The actual, mutable user preferences that are persisted to disk.
|
||||
preferences: Arc<Mutex<DocumentHolder<SavedGlobalPreferences>>>,
|
||||
|
||||
bookmarks: Arc<Mutex<DocumentHolder<Vec<Bookmark>>>>,
|
||||
bookmarks: Arc<Mutex<DocumentHolder<Bookmarks>>>,
|
||||
}
|
||||
|
||||
impl GlobalPreferences {
|
||||
|
@ -136,7 +136,7 @@ impl GlobalPreferences {
|
|||
.filename_pattern
|
||||
}
|
||||
|
||||
pub fn bookmarks(&self, fun: impl FnOnce(&Vec<Bookmark>)) {
|
||||
pub fn bookmarks(&self, fun: impl FnOnce(&Bookmarks)) {
|
||||
fun(&self.bookmarks.lock().expect("Bookmarks is not reentrant"))
|
||||
}
|
||||
|
||||
|
@ -222,17 +222,3 @@ pub struct LogPreferences {
|
|||
pub struct StoragePreferences {
|
||||
pub backend: storage::StorageBackend,
|
||||
}
|
||||
|
||||
pub static INVALID_URL: &str = "invalid:///";
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct Bookmark {
|
||||
pub url: Url,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
impl Bookmark {
|
||||
pub fn is_invalid(&self) -> bool {
|
||||
self.url.as_str() == INVALID_URL
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use crate::preferences::{Bookmark, SavedGlobalPreferences};
|
||||
use crate::preferences::SavedGlobalPreferences;
|
||||
use ruffle_frontend_utils::bookmarks::{Bookmark, Bookmarks};
|
||||
use ruffle_frontend_utils::parse::{DocumentHolder, ParseContext, ParseResult, ReadExt};
|
||||
use std::str::FromStr;
|
||||
use toml_edit::DocumentMut;
|
||||
|
@ -68,7 +69,7 @@ pub fn read_preferences(input: &str) -> ParseResult<SavedGlobalPreferences> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn read_bookmarks(input: &str) -> ParseResult<Vec<Bookmark>> {
|
||||
pub fn read_bookmarks(input: &str) -> ParseResult<Bookmarks> {
|
||||
let document = match input.parse::<DocumentMut>() {
|
||||
Ok(document) => document,
|
||||
Err(e) => {
|
||||
|
@ -86,7 +87,7 @@ pub fn read_bookmarks(input: &str) -> ParseResult<Vec<Bookmark>> {
|
|||
for bookmark in bookmarks.iter() {
|
||||
let url = match bookmark.parse_from_str(cx, "url") {
|
||||
Some(value) => value,
|
||||
None => url::Url::parse(crate::preferences::INVALID_URL)
|
||||
None => url::Url::parse(ruffle_frontend_utils::bookmarks::INVALID_URL)
|
||||
.expect("Url is constant and valid"),
|
||||
};
|
||||
|
||||
|
@ -432,7 +433,7 @@ mod tests {
|
|||
let result = read_bookmarks("[[bookmark]]");
|
||||
assert_eq!(
|
||||
&vec![Bookmark {
|
||||
url: Url::parse(crate::preferences::INVALID_URL).unwrap(),
|
||||
url: Url::parse(ruffle_frontend_utils::bookmarks::INVALID_URL).unwrap(),
|
||||
name: "".to_string(),
|
||||
}],
|
||||
result.values()
|
||||
|
@ -442,7 +443,7 @@ mod tests {
|
|||
let result = read_bookmarks("[[bookmark]]\nurl = \"invalid\"");
|
||||
assert_eq!(
|
||||
&vec![Bookmark {
|
||||
url: Url::parse(crate::preferences::INVALID_URL).unwrap(),
|
||||
url: Url::parse(ruffle_frontend_utils::bookmarks::INVALID_URL).unwrap(),
|
||||
name: "".to_string(),
|
||||
}],
|
||||
result.values()
|
||||
|
@ -512,11 +513,11 @@ mod tests {
|
|||
name: "example.swf".to_string(),
|
||||
},
|
||||
Bookmark {
|
||||
url: Url::parse(crate::preferences::INVALID_URL).unwrap(),
|
||||
url: Url::parse(ruffle_frontend_utils::bookmarks::INVALID_URL).unwrap(),
|
||||
name: "".to_string(),
|
||||
},
|
||||
Bookmark {
|
||||
url: Url::parse(crate::preferences::INVALID_URL).unwrap(),
|
||||
url: Url::parse(ruffle_frontend_utils::bookmarks::INVALID_URL).unwrap(),
|
||||
name: "".to_string(),
|
||||
},
|
||||
Bookmark {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use crate::log::FilenamePattern;
|
||||
use crate::preferences::storage::StorageBackend;
|
||||
use crate::preferences::{Bookmark, SavedGlobalPreferences};
|
||||
use crate::preferences::SavedGlobalPreferences;
|
||||
use ruffle_frontend_utils::bookmarks::{Bookmark, Bookmarks};
|
||||
use ruffle_frontend_utils::parse::DocumentHolder;
|
||||
use ruffle_render_wgpu::clap::{GraphicsBackend, PowerPreference};
|
||||
use toml_edit::{array, value, ArrayOfTables, DocumentMut, Table};
|
||||
|
@ -74,14 +75,14 @@ impl<'a> PreferencesWriter<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct BookmarksWriter<'a>(&'a mut DocumentHolder<Vec<Bookmark>>);
|
||||
pub struct BookmarksWriter<'a>(&'a mut DocumentHolder<Bookmarks>);
|
||||
|
||||
impl<'a> BookmarksWriter<'a> {
|
||||
pub(super) fn new(bookmarks: &'a mut DocumentHolder<Vec<Bookmark>>) -> Self {
|
||||
pub(super) fn new(bookmarks: &'a mut DocumentHolder<Bookmarks>) -> Self {
|
||||
Self(bookmarks)
|
||||
}
|
||||
|
||||
fn with_underlying_table(&mut self, fun: impl FnOnce(&mut Vec<Bookmark>, &mut ArrayOfTables)) {
|
||||
fn with_underlying_table(&mut self, fun: impl FnOnce(&mut Bookmarks, &mut ArrayOfTables)) {
|
||||
fn find_table(toml_document: &mut DocumentMut) -> &mut ArrayOfTables {
|
||||
if toml_document.contains_array_of_tables("bookmark") {
|
||||
return toml_document["bookmark"]
|
||||
|
@ -102,11 +103,7 @@ impl<'a> BookmarksWriter<'a> {
|
|||
})
|
||||
}
|
||||
|
||||
fn with_bookmark_table(
|
||||
&mut self,
|
||||
index: usize,
|
||||
fun: impl FnOnce(&mut Vec<Bookmark>, &mut Table),
|
||||
) {
|
||||
fn with_bookmark_table(&mut self, index: usize, fun: impl FnOnce(&mut Bookmarks, &mut Table)) {
|
||||
self.with_underlying_table(|values, array_of_tables| {
|
||||
let table = array_of_tables
|
||||
.get_mut(index)
|
||||
|
@ -305,7 +302,7 @@ mod tests {
|
|||
use std::str::FromStr;
|
||||
use url::Url;
|
||||
|
||||
define_serialization_test_helpers!(read_bookmarks, Vec<Bookmark>, BookmarksWriter);
|
||||
define_serialization_test_helpers!(read_bookmarks, Bookmarks, BookmarksWriter);
|
||||
|
||||
#[test]
|
||||
fn add_bookmark() {
|
||||
|
|
|
@ -12,3 +12,4 @@ workspace = true
|
|||
|
||||
[dependencies]
|
||||
toml_edit = { version = "0.22.9", features = ["parse"] }
|
||||
url = "2.5.0"
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
use url::Url;
|
||||
|
||||
pub static INVALID_URL: &str = "invalid:///";
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct Bookmark {
|
||||
pub url: Url,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
impl Bookmark {
|
||||
pub fn is_invalid(&self) -> bool {
|
||||
self.url.as_str() == INVALID_URL
|
||||
}
|
||||
}
|
||||
|
||||
pub type Bookmarks = Vec<Bookmark>;
|
|
@ -1 +1,2 @@
|
|||
pub mod bookmarks;
|
||||
pub mod parse;
|
||||
|
|
|
@ -101,7 +101,7 @@ impl<T> ParseResult<T> {
|
|||
pub struct ParseContext {
|
||||
pub warnings: Vec<String>,
|
||||
/// Path of the current item being parsed
|
||||
pub path: Vec<&'static str>,
|
||||
path: Vec<&'static str>,
|
||||
}
|
||||
|
||||
impl ParseContext {
|
||||
|
|
Loading…
Reference in New Issue