Make Background a native feature
- Background replaces the Background Slideshow plugin and the background image of Appearance. It shows a folder as a slideshow, or one image. - It is on by default. Its module loads at launch only when a folder or an image is chosen. - Rust keeps the one folder in background-folder.json. The interface never sends a path. Eight background_* commands replace the six deprecated backgrounds_* commands. - The first start moves the slideshow folder and settings, and keeps the saved image as the image source. - One blur worker with a cache, fewer folder reads, and a decode before each fade. The hub writes only the changed properties. - Remove the deprecated folder methods of api.backgrounds. set, get, and subscribe stay for the Project Management plugin. - Show the view buttons in the workbench test without text, after UI-056. - Update the tests, the measurement tool, the docs, and UI-057.
This commit is contained in:
+16
-10
@@ -18,9 +18,9 @@ use tauri_plugin_dialog::DialogExt;
|
||||
|
||||
const GRANTS_FILE: &str = "folder-grants.json";
|
||||
const GRANT_LIMIT: usize = 64;
|
||||
const READ_LIMIT: u64 = 64 * 1024 * 1024;
|
||||
const SIDECAR_LIMIT: u64 = 1024 * 1024;
|
||||
const LIST_LIMIT: usize = 10_000;
|
||||
pub(crate) const READ_LIMIT: u64 = 64 * 1024 * 1024;
|
||||
pub(crate) const SIDECAR_LIMIT: u64 = 1024 * 1024;
|
||||
pub(crate) const LIST_LIMIT: usize = 10_000;
|
||||
|
||||
/// Serializes changes to grant files and sidecar files.
|
||||
static LOCK: Mutex<()> = Mutex::new(());
|
||||
@@ -47,7 +47,7 @@ pub struct FolderGrant {
|
||||
|
||||
#[derive(Debug, Serialize, PartialEq)]
|
||||
pub struct FolderEntry {
|
||||
name: String,
|
||||
pub(crate) name: String,
|
||||
size: u64,
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ impl Grants {
|
||||
}
|
||||
|
||||
/// Resolve a chosen folder. Reject relative paths, parent segments, files, and whole drives.
|
||||
fn granted_root(folder: &Path) -> Result<PathBuf> {
|
||||
pub(crate) fn granted_root(folder: &Path) -> Result<PathBuf> {
|
||||
if !folder.is_absolute() || folder.components().any(|part| matches!(part, Component::ParentDir)) {
|
||||
return Err("Supply an absolute folder path without parent segments.".into());
|
||||
}
|
||||
@@ -200,7 +200,7 @@ fn file_path(root: &Path, name: &str) -> Result<PathBuf> {
|
||||
}
|
||||
|
||||
/// Open one ordinary file. Reject links, also a link that replaces the file after the check.
|
||||
fn open_plain(root: &Path, path: &Path) -> Result<(fs::File, u64)> {
|
||||
pub(crate) fn open_plain(root: &Path, path: &Path) -> Result<(fs::File, u64)> {
|
||||
let metadata = fs::symlink_metadata(path)?;
|
||||
if !metadata.is_file() || is_link(&metadata) {
|
||||
return Err("Granted folder access is limited to ordinary files, not links or folders.".into());
|
||||
@@ -213,7 +213,7 @@ fn open_plain(root: &Path, path: &Path) -> Result<(fs::File, u64)> {
|
||||
Ok((file, opened.len()))
|
||||
}
|
||||
|
||||
fn list_files(root: &Path) -> Result<Vec<FolderEntry>> {
|
||||
pub(crate) fn list_files(root: &Path) -> Result<Vec<FolderEntry>> {
|
||||
let mut entries = Vec::new();
|
||||
for entry in fs::read_dir(root)? {
|
||||
let entry = entry?;
|
||||
@@ -232,7 +232,7 @@ fn list_files(root: &Path) -> Result<Vec<FolderEntry>> {
|
||||
Ok(entries)
|
||||
}
|
||||
|
||||
fn read_file(root: &Path, name: &str) -> Result<Vec<u8>> {
|
||||
pub(crate) fn read_file(root: &Path, name: &str) -> Result<Vec<u8>> {
|
||||
let path = file_path(root, name)?;
|
||||
let (file, size) = open_plain(root, &path)?;
|
||||
if size > READ_LIMIT {
|
||||
@@ -251,7 +251,7 @@ fn sidecar_path(root: &Path, name: &str) -> Result<PathBuf> {
|
||||
file_path(root, name)
|
||||
}
|
||||
|
||||
fn read_sidecar(root: &Path, name: &str) -> Result<Option<String>> {
|
||||
pub(crate) fn read_sidecar(root: &Path, name: &str) -> Result<Option<String>> {
|
||||
let path = sidecar_path(root, name)?;
|
||||
match fs::symlink_metadata(&path) {
|
||||
Err(error) if error.kind() == std::io::ErrorKind::NotFound => return Ok(None),
|
||||
@@ -267,7 +267,7 @@ fn read_sidecar(root: &Path, name: &str) -> Result<Option<String>> {
|
||||
}
|
||||
|
||||
/// Save a sidecar only if it still holds `expected` (`None` when the file does not exist).
|
||||
fn write_sidecar(root: &Path, name: &str, contents: &str, expected: Option<&str>) -> Result<()> {
|
||||
pub(crate) fn write_sidecar(root: &Path, name: &str, contents: &str, expected: Option<&str>) -> Result<()> {
|
||||
let path = sidecar_path(root, name)?;
|
||||
if contents.len() as u64 > SIDECAR_LIMIT {
|
||||
return Err("The sidecar file exceeds 1 MiB.".into());
|
||||
@@ -285,6 +285,12 @@ fn write_sidecar(root: &Path, name: &str, contents: &str, expected: Option<&str>
|
||||
}
|
||||
}
|
||||
|
||||
/// The folder of one grant of `plugin` in the plugin data folder `data`, with the checks of a normal access.
|
||||
/// The Background feature uses it to take the folder of the old Background Slideshow plugin. It changes no file.
|
||||
pub(crate) fn plugin_grant(data: &Path, plugin: &str, id: &str) -> Result<PathBuf> {
|
||||
Grants { data: data.to_path_buf() }.resolve(plugin, id)
|
||||
}
|
||||
|
||||
fn grants(app: &AppHandle) -> Result<Grants> {
|
||||
Ok(Grants { data: app.path().app_data_dir()?.join("plugin-data") })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user