mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2026-02-17 13:52:14 +01:00
V2 Tauri integration (#3854)
# Description of Changes Please provide a summary of the changes, including: ## Add PDF File Association Support for Tauri App ### 🎯 **Features Added** - PDF file association configuration in Tauri - Command line argument detection for opened files - Automatic file loading when app is launched via "Open with" - Cross-platform support (Windows/macOS) ### 🔧 **Technical Changes** - Added `fileAssociations` in `tauri.conf.json` for PDF files - New `get_opened_file` Tauri command to detect file arguments - `fileOpenService` with Tauri fs plugin integration - `useOpenedFile` hook for React integration - Improved backend health logging during startup (reduced noise) ### 🧪 **Testing** See * https://v2.tauri.app/start/prerequisites/ * [DesktopApplicationDevelopmentGuide.md](DesktopApplicationDevelopmentGuide.md) ```bash # Test file association during development: cd frontend npm install cargo tauri dev --no-watch -- -- "path/to/file.pdf" ``` For production testing: 1. Build: npm run tauri build 2. Install the built app 3. Right-click PDF → "Open with" → Stirling-PDF 🚀 User Experience - Users can now double-click PDF files to open them directly in Stirling-PDF - Files automatically load in the viewer when opened via file association - Seamless integration with OS file handling --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md) (if applicable) - [ ] I have performed a self-review of my own code - [ ] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: Connor Yoh <connor@stirlingpdf.com> Co-authored-by: James Brunton <james@stirlingpdf.com> Co-authored-by: James Brunton <jbrunton96@gmail.com>
This commit is contained in:
134
scripts/build-tauri-jlink.bat
Normal file
134
scripts/build-tauri-jlink.bat
Normal file
@@ -0,0 +1,134 @@
|
||||
@echo off
|
||||
REM Build script for Tauri with JLink runtime bundling
|
||||
REM This script creates a self-contained Java runtime for Stirling-PDF
|
||||
|
||||
echo 🔧 Building Stirling-PDF with JLink runtime for Tauri...
|
||||
|
||||
echo ▶ Checking Java environment...
|
||||
java -version >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo ❌ Java is not installed or not in PATH
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
jlink --version >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo ❌ jlink is not available. Please ensure you have a JDK ^(not just JRE^) installed.
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo ✅ Java and jlink detected
|
||||
|
||||
echo ▶ Building Stirling-PDF JAR...
|
||||
call gradlew.bat clean bootJar --no-daemon
|
||||
if errorlevel 1 (
|
||||
echo ❌ Failed to build Stirling-PDF JAR
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM Find the built JAR(s)
|
||||
echo ▶ Listing all built JAR files in app\core\build\libs:
|
||||
dir /b app\core\build\libs\stirling-pdf-*.jar
|
||||
for %%f in (app\core\build\libs\stirling-pdf-*.jar) do set STIRLING_JAR=%%f
|
||||
if not exist "%STIRLING_JAR%" (
|
||||
echo ❌ No Stirling-PDF JAR found in build/libs/
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo ✅ Built JAR: %STIRLING_JAR%
|
||||
|
||||
echo ▶ Creating Tauri directories...
|
||||
if not exist "frontend\src-tauri\libs" mkdir "frontend\src-tauri\libs"
|
||||
if not exist "frontend\src-tauri\runtime" mkdir "frontend\src-tauri\runtime"
|
||||
|
||||
echo ▶ Copying JAR to Tauri libs directory...
|
||||
copy "%STIRLING_JAR%" "frontend\src-tauri\libs\"
|
||||
echo ✅ JAR copied to frontend\src-tauri\libs\
|
||||
|
||||
REM Log out all JAR files now in the Tauri libs directory
|
||||
echo ▶ Listing all JAR files in frontend\src-tauri\libs after copy:
|
||||
dir /b frontend\src-tauri\libs\stirling-pdf-*.jar
|
||||
|
||||
echo ▶ Creating custom JRE with jlink...
|
||||
if exist "frontend\src-tauri\runtime\jre" rmdir /s /q "frontend\src-tauri\runtime\jre"
|
||||
|
||||
REM Use predefined module list for Windows (jdeps may not be available)
|
||||
set MODULES=java.base,java.compiler,java.desktop,java.instrument,java.logging,java.management,java.naming,java.net.http,java.prefs,java.rmi,java.scripting,java.security.jgss,java.security.sasl,java.sql,java.transaction.xa,java.xml,java.xml.crypto,jdk.crypto.ec,jdk.crypto.cryptoki,jdk.unsupported
|
||||
|
||||
echo ▶ Creating JLink runtime with modules: %MODULES%
|
||||
|
||||
jlink ^
|
||||
--add-modules %MODULES% ^
|
||||
--strip-debug ^
|
||||
--compress=2 ^
|
||||
--no-header-files ^
|
||||
--no-man-pages ^
|
||||
--output "frontend\src-tauri\runtime\jre"
|
||||
|
||||
if not exist "frontend\src-tauri\runtime\jre" (
|
||||
echo ❌ Failed to create JLink runtime
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo ✅ JLink runtime created at frontend\src-tauri\runtime\jre
|
||||
|
||||
echo ▶ Creating launcher scripts for testing...
|
||||
|
||||
REM Create Windows launcher script
|
||||
echo @echo off > "frontend\src-tauri\runtime\launch-stirling.bat"
|
||||
echo REM Launcher script for Stirling-PDF with bundled JRE >> "frontend\src-tauri\runtime\launch-stirling.bat"
|
||||
echo. >> "frontend\src-tauri\runtime\launch-stirling.bat"
|
||||
echo set SCRIPT_DIR=%%~dp0 >> "frontend\src-tauri\runtime\launch-stirling.bat"
|
||||
echo set JRE_DIR=%%SCRIPT_DIR%%jre >> "frontend\src-tauri\runtime\launch-stirling.bat"
|
||||
echo set LIBS_DIR=%%SCRIPT_DIR%%..\libs >> "frontend\src-tauri\runtime\launch-stirling.bat"
|
||||
echo. >> "frontend\src-tauri\runtime\launch-stirling.bat"
|
||||
echo REM Find the Stirling-PDF JAR >> "frontend\src-tauri\runtime\launch-stirling.bat"
|
||||
echo for %%%%f in ("%%LIBS_DIR%%\Stirling-PDF-*.jar") do set STIRLING_JAR=%%%%f >> "frontend\src-tauri\runtime\launch-stirling.bat"
|
||||
echo. >> "frontend\src-tauri\runtime\launch-stirling.bat"
|
||||
echo if not exist "%%STIRLING_JAR%%" ^( >> "frontend\src-tauri\runtime\launch-stirling.bat"
|
||||
echo echo ❌ Stirling-PDF JAR not found in %%LIBS_DIR%% >> "frontend\src-tauri\runtime\launch-stirling.bat"
|
||||
echo exit /b 1 >> "frontend\src-tauri\runtime\launch-stirling.bat"
|
||||
echo ^) >> "frontend\src-tauri\runtime\launch-stirling.bat"
|
||||
echo. >> "frontend\src-tauri\runtime\launch-stirling.bat"
|
||||
echo REM Launch with bundled JRE >> "frontend\src-tauri\runtime\launch-stirling.bat"
|
||||
echo "%%JRE_DIR%%\bin\java.exe" ^^ >> "frontend\src-tauri\runtime\launch-stirling.bat"
|
||||
echo -Xmx2g ^^ >> "frontend\src-tauri\runtime\launch-stirling.bat"
|
||||
echo -DBROWSER_OPEN=true ^^ >> "frontend\src-tauri\runtime\launch-stirling.bat"
|
||||
echo -DSTIRLING_PDF_DESKTOP_UI=false ^^ >> "frontend\src-tauri\runtime\launch-stirling.bat"
|
||||
echo -jar "%%STIRLING_JAR%%" ^^ >> "frontend\src-tauri\runtime\launch-stirling.bat"
|
||||
echo %%* >> "frontend\src-tauri\runtime\launch-stirling.bat"
|
||||
|
||||
echo ✅ Created launcher scripts for testing
|
||||
|
||||
echo ▶ Testing bundled JRE...
|
||||
"frontend\src-tauri\runtime\jre\bin\java.exe" --version >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo ❌ Bundled JRE test failed
|
||||
exit /b 1
|
||||
) else (
|
||||
echo ✅ Bundled JRE works correctly
|
||||
)
|
||||
|
||||
echo.
|
||||
echo ✅ 🎉 JLink build setup completed successfully!
|
||||
echo.
|
||||
echo 📊 Summary:
|
||||
echo • JAR: %STIRLING_JAR%
|
||||
echo • Runtime: frontend\src-tauri\runtime\jre
|
||||
echo • Modules: %MODULES%
|
||||
echo.
|
||||
echo 📋 Next steps:
|
||||
echo 1. cd frontend
|
||||
echo 2. npm run tauri-build
|
||||
echo.
|
||||
echo 💡 Testing:
|
||||
echo • Test bundled runtime: frontend\src-tauri\runtime\launch-stirling.bat
|
||||
echo • Tauri configuration already updated to include bundled JRE
|
||||
echo.
|
||||
echo 💡 Benefits:
|
||||
echo • No external JRE dependency
|
||||
echo • Smaller distribution size with custom runtime
|
||||
echo • Better security with minimal required modules
|
||||
echo • Consistent Java version across all deployments
|
||||
echo.
|
||||
echo ✅ The application will now run without requiring users to install Java!
|
||||
230
scripts/build-tauri-jlink.sh
Executable file
230
scripts/build-tauri-jlink.sh
Executable file
@@ -0,0 +1,230 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Build script for Tauri with JLink runtime bundling
|
||||
# This script creates a self-contained Java runtime for Stirling-PDF
|
||||
|
||||
set -e
|
||||
|
||||
echo "🔧 Building Stirling-PDF with JLink runtime for Tauri..."
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Function to print colored output
|
||||
print_step() {
|
||||
echo -e "${BLUE}▶ $1${NC}"
|
||||
}
|
||||
|
||||
print_success() {
|
||||
echo -e "${GREEN}✅ $1${NC}"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}⚠️ $1${NC}"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}❌ $1${NC}"
|
||||
}
|
||||
|
||||
# Check if Java is installed and version
|
||||
print_step "Checking Java environment..."
|
||||
if ! command -v java &> /dev/null; then
|
||||
print_error "Java is not installed or not in PATH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! command -v jlink &> /dev/null; then
|
||||
print_error "jlink is not available. Please ensure you have a JDK (not just JRE) installed."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
JAVA_VERSION=$(java -version 2>&1 | head -n 1 | cut -d'"' -f2 | cut -d'.' -f1)
|
||||
if [ "$JAVA_VERSION" -lt 17 ]; then
|
||||
print_error "Java 17 or higher is required. Found Java $JAVA_VERSION"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
print_success "Java $JAVA_VERSION detected with jlink support"
|
||||
|
||||
# Check if jpackage is available (Java 14+)
|
||||
if command -v jpackage &> /dev/null; then
|
||||
print_success "jpackage is available for native packaging"
|
||||
else
|
||||
print_warning "jpackage is not available - using jlink only"
|
||||
fi
|
||||
|
||||
# Clean and build the Stirling-PDF JAR
|
||||
print_step "Building Stirling-PDF JAR..."
|
||||
./gradlew clean bootJar --no-daemon
|
||||
|
||||
if [ ! -f compgen -G "app/core/build/libs/stirling-pdf-*.jar" ]; then
|
||||
print_error "Failed to build stirling-pdf JAR"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Find the built JAR
|
||||
STIRLING_JAR=$(ls app/core/build/libs/stirling-pdf-*.jar | head -n 1)
|
||||
print_success "Built JAR: $STIRLING_JAR"
|
||||
|
||||
# Create directories for Tauri
|
||||
TAURI_SRC_DIR="frontend/src-tauri"
|
||||
TAURI_LIBS_DIR="$TAURI_SRC_DIR/libs"
|
||||
TAURI_RUNTIME_DIR="$TAURI_SRC_DIR/runtime"
|
||||
|
||||
print_step "Creating Tauri directories..."
|
||||
mkdir -p "$TAURI_LIBS_DIR"
|
||||
mkdir -p "$TAURI_RUNTIME_DIR"
|
||||
|
||||
# Copy the JAR to Tauri libs directory
|
||||
print_step "Copying JAR to Tauri libs directory..."
|
||||
cp "$STIRLING_JAR" "$TAURI_LIBS_DIR/"
|
||||
print_success "JAR copied to $TAURI_LIBS_DIR/"
|
||||
|
||||
# Create a custom JRE using jlink
|
||||
print_step "Creating custom JRE with jlink..."
|
||||
|
||||
# Determine modules needed by analyzing the JAR
|
||||
print_step "Analyzing JAR dependencies..."
|
||||
|
||||
# Use jdeps to analyze module dependencies if available
|
||||
if command -v jdeps &> /dev/null; then
|
||||
print_step "Running jdeps analysis..."
|
||||
REQUIRED_MODULES=$(jdeps --print-module-deps --ignore-missing-deps "$STIRLING_JAR" 2>/dev/null || echo "")
|
||||
if [ -n "$REQUIRED_MODULES" ]; then
|
||||
print_success "jdeps detected modules: $REQUIRED_MODULES"
|
||||
# Add additional modules we know Stirling-PDF needs
|
||||
MODULES="$REQUIRED_MODULES,java.compiler,java.instrument,java.management,java.naming,java.net.http,java.prefs,java.rmi,java.scripting,java.security.jgss,java.security.sasl,java.sql,java.transaction.xa,java.xml.crypto,jdk.crypto.ec,jdk.crypto.cryptoki,jdk.unsupported"
|
||||
else
|
||||
print_warning "jdeps analysis failed, using predefined module list"
|
||||
MODULES="java.base,java.compiler,java.desktop,java.instrument,java.logging,java.management,java.naming,java.net.http,java.prefs,java.rmi,java.scripting,java.security.jgss,java.security.sasl,java.sql,java.transaction.xa,java.xml,java.xml.crypto,jdk.crypto.ec,jdk.crypto.cryptoki,jdk.unsupported"
|
||||
fi
|
||||
else
|
||||
print_warning "jdeps not available, using predefined module list"
|
||||
MODULES="java.base,java.compiler,java.desktop,java.instrument,java.logging,java.management,java.naming,java.net.http,java.prefs,java.rmi,java.scripting,java.security.jgss,java.security.sasl,java.sql,java.transaction.xa,java.xml,java.xml.crypto,jdk.crypto.ec,jdk.crypto.cryptoki,jdk.unsupported"
|
||||
fi
|
||||
|
||||
print_step "Creating JLink runtime with modules: $MODULES"
|
||||
|
||||
# Remove existing runtime if present
|
||||
rm -rf "$TAURI_RUNTIME_DIR/jre"
|
||||
|
||||
# Create the custom JRE
|
||||
jlink \
|
||||
--add-modules "$MODULES" \
|
||||
--strip-debug \
|
||||
--compress=2 \
|
||||
--no-header-files \
|
||||
--no-man-pages \
|
||||
--output "$TAURI_RUNTIME_DIR/jre"
|
||||
|
||||
if [ ! -d "$TAURI_RUNTIME_DIR/jre" ]; then
|
||||
print_error "Failed to create JLink runtime"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
print_success "JLink runtime created at $TAURI_RUNTIME_DIR/jre"
|
||||
|
||||
# Calculate runtime size
|
||||
RUNTIME_SIZE=$(du -sh "$TAURI_RUNTIME_DIR/jre" | cut -f1)
|
||||
print_success "Runtime size: $RUNTIME_SIZE"
|
||||
|
||||
# Create launcher scripts for testing
|
||||
print_step "Creating launcher scripts for testing..."
|
||||
|
||||
LAUNCHER_SCRIPT="$TAURI_RUNTIME_DIR/launch-stirling.sh"
|
||||
cat > "$LAUNCHER_SCRIPT" << 'EOF'
|
||||
#!/bin/bash
|
||||
# Launcher script for Stirling-PDF with bundled JRE
|
||||
|
||||
# Get the directory of this script
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
JRE_DIR="$SCRIPT_DIR/jre"
|
||||
LIBS_DIR="$(dirname "$SCRIPT_DIR")/libs"
|
||||
|
||||
# Find the Stirling-PDF JAR
|
||||
STIRLING_JAR=$(compgen -G "app/core/build/libs/stirling-pdf-*.jar")
|
||||
|
||||
if [ ! -f "$STIRLING_JAR" ]; then
|
||||
echo "❌ Stirling-PDF JAR not found in $LIBS_DIR"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Launch with bundled JRE
|
||||
"$JRE_DIR/bin/java" \
|
||||
-Xmx2g \
|
||||
-DBROWSER_OPEN=true \
|
||||
-DSTIRLING_PDF_DESKTOP_UI=false \
|
||||
-jar "$STIRLING_JAR" \
|
||||
"$@"
|
||||
EOF
|
||||
|
||||
chmod +x "$LAUNCHER_SCRIPT"
|
||||
|
||||
# Create Windows launcher
|
||||
LAUNCHER_BAT="$TAURI_RUNTIME_DIR/launch-stirling.bat"
|
||||
cat > "$LAUNCHER_BAT" << 'EOF'
|
||||
@echo off
|
||||
REM Launcher script for Stirling-PDF with bundled JRE
|
||||
|
||||
set SCRIPT_DIR=%~dp0
|
||||
set JRE_DIR=%SCRIPT_DIR%jre
|
||||
set LIBS_DIR=%SCRIPT_DIR%..\libs
|
||||
|
||||
REM Find the Stirling-PDF JAR
|
||||
for %%f in ("%LIBS_DIR%\Stirling-PDF-*.jar") do set STIRLING_JAR=%%f
|
||||
|
||||
if not exist "%STIRLING_JAR%" (
|
||||
echo ❌ Stirling-PDF JAR not found in %LIBS_DIR%
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM Launch with bundled JRE
|
||||
"%JRE_DIR%\bin\java.exe" ^
|
||||
-Xmx2g ^
|
||||
-DBROWSER_OPEN=true ^
|
||||
-DSTIRLING_PDF_DESKTOP_UI=false ^
|
||||
-jar "%STIRLING_JAR%" ^
|
||||
%*
|
||||
EOF
|
||||
|
||||
print_success "Created launcher scripts for testing"
|
||||
|
||||
# Test the bundled runtime
|
||||
print_step "Testing bundled JRE..."
|
||||
if [ -f "$TAURI_RUNTIME_DIR/jre/bin/java" ]; then
|
||||
JAVA_VERSION_OUTPUT=$("$TAURI_RUNTIME_DIR/jre/bin/java" --version 2>&1 | head -n 1)
|
||||
print_success "Bundled JRE works: $JAVA_VERSION_OUTPUT"
|
||||
else
|
||||
print_error "Bundled JRE executable not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Display summary
|
||||
echo ""
|
||||
print_success "🎉 JLink build setup completed successfully!"
|
||||
echo ""
|
||||
echo -e "${BLUE}📊 Summary:${NC}"
|
||||
echo " • JAR: $STIRLING_JAR"
|
||||
echo " • Runtime: $TAURI_RUNTIME_DIR/jre ($RUNTIME_SIZE)"
|
||||
echo " • Modules: $MODULES"
|
||||
echo ""
|
||||
echo -e "${BLUE}📋 Next steps:${NC}"
|
||||
echo " 1. cd frontend"
|
||||
echo " 2. npm run tauri-build"
|
||||
echo ""
|
||||
echo -e "${BLUE}💡 Testing:${NC}"
|
||||
echo " • Test bundled runtime: $LAUNCHER_SCRIPT"
|
||||
echo " • Tauri configuration already updated to include bundled JRE"
|
||||
echo ""
|
||||
echo -e "${BLUE}💡 Benefits:${NC}"
|
||||
echo " • No external JRE dependency"
|
||||
echo " • Smaller distribution size with custom runtime"
|
||||
echo " • Better security with minimal required modules"
|
||||
echo " • Consistent Java version across all deployments"
|
||||
echo ""
|
||||
print_success "The application will now run without requiring users to install Java!"
|
||||
Reference in New Issue
Block a user