mirror of
https://github.com/spacedriveapp/spacedrive
synced 2024-07-07 04:23:29 +00:00
[ENG-1220] Fix pdf thumb crashing app (#1460)
Fix pdf thumb crashing app
This commit is contained in:
parent
811faa22a0
commit
6fd8bd4ad8
|
@ -31,8 +31,4 @@ tracing = { workspace = true }
|
|||
# this broke builds as we build our own liibheif, so i disabled their default features
|
||||
libheif-rs = { version = "0.22.0", default-features = false, optional = true }
|
||||
libheif-sys = { version = "2.0.0", default-features = false, optional = true }
|
||||
pdfium-render = { version = "0.8.8", features = [
|
||||
"sync",
|
||||
"image",
|
||||
"thread_safe",
|
||||
] }
|
||||
pdfium-render = { version = "0.8.8", features = ["image"] }
|
||||
|
|
|
@ -6,7 +6,6 @@ use std::{
|
|||
|
||||
use crate::{consts::PDF_RENDER_WIDTH, Error::PdfiumBinding, ImageHandler, Result};
|
||||
use image::DynamicImage;
|
||||
use once_cell::sync::Lazy;
|
||||
use pdfium_render::prelude::{PdfPageRenderRotation, PdfRenderConfig, Pdfium};
|
||||
use tracing::error;
|
||||
|
||||
|
@ -20,7 +19,9 @@ const BINDING_LOCATION: &str = if cfg!(target_os = "macos") {
|
|||
"../lib/spacedrive"
|
||||
};
|
||||
|
||||
static PDFIUM: Lazy<Option<Pdfium>> = Lazy::new(|| {
|
||||
// FIX-ME: This is slow, but using Lazy with thread_safe was causing concurrency bugs that crashed the app
|
||||
thread_local! {
|
||||
static PDFIUM: Option<Pdfium> = {
|
||||
let lib_name = Pdfium::pdfium_platform_library_name();
|
||||
let lib_path = current_exe()
|
||||
.ok()
|
||||
|
@ -56,13 +57,15 @@ static PDFIUM: Lazy<Option<Pdfium>> = Lazy::new(|| {
|
|||
.map(Pdfium::new)
|
||||
.map_err(|err| error!("{err:#?}"))
|
||||
.ok()
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
pub struct PdfHandler {}
|
||||
|
||||
impl ImageHandler for PdfHandler {
|
||||
fn handle_image(&self, path: &Path) -> Result<DynamicImage> {
|
||||
let pdfium = PDFIUM.as_ref().ok_or(PdfiumBinding)?;
|
||||
PDFIUM.with(|maybe_pdfium| {
|
||||
let pdfium = maybe_pdfium.as_ref().ok_or(PdfiumBinding)?;
|
||||
|
||||
let render_config = PdfRenderConfig::new()
|
||||
.set_target_width(PDF_RENDER_WIDTH)
|
||||
|
@ -74,5 +77,6 @@ impl ImageHandler for PdfHandler {
|
|||
.first()?
|
||||
.render_with_config(&render_config)?
|
||||
.as_image())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue