mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-08-24 20:52:11 +00:00
Added info logs for PDFium
This commit is contained in:
parent
7392d03393
commit
6897272a71
@ -2,7 +2,7 @@ use std::error::Error;
|
|||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use pdfium_render::prelude::Pdfium;
|
use pdfium_render::prelude::Pdfium;
|
||||||
use log::{error, warn};
|
use log::{error, info, warn};
|
||||||
|
|
||||||
pub static PDFIUM_LIB_PATH: Lazy<Mutex<Option<String>>> = Lazy::new(|| Mutex::new(None));
|
pub static PDFIUM_LIB_PATH: Lazy<Mutex<Option<String>>> = Lazy::new(|| Mutex::new(None));
|
||||||
static PDFIUM: Lazy<Mutex<Option<Pdfium>>> = Lazy::new(|| Mutex::new(None));
|
static PDFIUM: Lazy<Mutex<Option<Pdfium>>> = Lazy::new(|| Mutex::new(None));
|
||||||
@ -32,11 +32,22 @@ impl PdfiumInit for Pdfium {
|
|||||||
fn load_pdfium() -> Result<Pdfium, String> {
|
fn load_pdfium() -> Result<Pdfium, String> {
|
||||||
let lib_path = PDFIUM_LIB_PATH.lock().unwrap().clone();
|
let lib_path = PDFIUM_LIB_PATH.lock().unwrap().clone();
|
||||||
if let Some(path) = lib_path.as_ref() {
|
if let Some(path) = lib_path.as_ref() {
|
||||||
return match Pdfium::bind_to_library(Pdfium::pdfium_platform_library_name_at_path(path)) {
|
let pdfium_library_path = Pdfium::pdfium_platform_library_name_at_path(path);
|
||||||
Ok(binding) => Ok(Pdfium::new(binding)),
|
|
||||||
|
return match Pdfium::bind_to_library(&pdfium_library_path) {
|
||||||
|
Ok(binding) => {
|
||||||
|
info!("Loaded PDFium from '{path}'.", path = pdfium_library_path.to_string_lossy());
|
||||||
|
Ok(Pdfium::new(binding))
|
||||||
|
},
|
||||||
Err(library_error) => {
|
Err(library_error) => {
|
||||||
match Pdfium::bind_to_system_library() {
|
match Pdfium::bind_to_system_library() {
|
||||||
Ok(binding) => Ok(Pdfium::new(binding)),
|
Ok(binding) => {
|
||||||
|
info!(
|
||||||
|
"Loaded PDFium from the system library after failing to load '{path}'.",
|
||||||
|
path = pdfium_library_path.to_string_lossy(),
|
||||||
|
);
|
||||||
|
Ok(Pdfium::new(binding))
|
||||||
|
},
|
||||||
Err(system_error) => {
|
Err(system_error) => {
|
||||||
let error_message = format!(
|
let error_message = format!(
|
||||||
"Failed to load PDFium from '{path}' and the system library. Developer action (from repo root): run the build script once to download the required PDFium version: `cd app/Build` and `dotnet run build`. Details: library error: '{library_error}'; system error: '{system_error}'."
|
"Failed to load PDFium from '{path}' and the system library. Developer action (from repo root): run the build script once to download the required PDFium version: `cd app/Build` and `dotnet run build`. Details: library error: '{library_error}'; system error: '{system_error}'."
|
||||||
@ -52,7 +63,10 @@ fn load_pdfium() -> Result<Pdfium, String> {
|
|||||||
|
|
||||||
warn!("No custom PDFium library path set; trying to load PDFium from the system library.");
|
warn!("No custom PDFium library path set; trying to load PDFium from the system library.");
|
||||||
match Pdfium::bind_to_system_library() {
|
match Pdfium::bind_to_system_library() {
|
||||||
Ok(binding) => Ok(Pdfium::new(binding)),
|
Ok(binding) => {
|
||||||
|
info!("Loaded PDFium from the system library.");
|
||||||
|
Ok(Pdfium::new(binding))
|
||||||
|
},
|
||||||
Err(system_error) => {
|
Err(system_error) => {
|
||||||
let error_message = format!(
|
let error_message = format!(
|
||||||
"Failed to load PDFium from the system library. Developer action (from repo root): run the build script once to download the required PDFium version: `cd app/Build` and `dotnet run build`. Details: '{system_error}'."
|
"Failed to load PDFium from the system library. Developer action (from repo root): run the build script once to download the required PDFium version: `cd app/Build` and `dotnet run build`. Details: '{system_error}'."
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user