|
| 1 | +#!/bin/bash |
| 2 | +# ============================================================================= |
| 3 | +# Minecraft Splitscreen Steam Deck Installer - Desktop Launcher Module |
| 4 | +# ============================================================================= |
| 5 | +# |
| 6 | +# This module handles the creation of native desktop launchers and application |
| 7 | +# menu integration for the Minecraft Splitscreen launcher. Provides seamless |
| 8 | +# integration with Linux desktop environments. |
| 9 | +# |
| 10 | +# Functions provided: |
| 11 | +# - create_desktop_launcher: Generate .desktop file for system integration |
| 12 | +# |
| 13 | +# ============================================================================= |
| 14 | + |
| 15 | +# create_desktop_launcher: Generate .desktop file for system integration |
| 16 | +# |
| 17 | +# DESKTOP LAUNCHER BENEFITS: |
| 18 | +# - Native desktop environment integration (GNOME, KDE, XFCE, etc.) |
| 19 | +# - Appears in application menus and search results |
| 20 | +# - Desktop shortcut for quick access |
| 21 | +# - Proper icon and metadata for professional appearance |
| 22 | +# - Follows freedesktop.org Desktop Entry Specification |
| 23 | +# - Works with all Linux desktop environments |
| 24 | +# |
| 25 | +# ICON HIERARCHY: |
| 26 | +# 1. SteamGridDB custom icon (downloaded, professional appearance) |
| 27 | +# 2. PollyMC instance icon (if PollyMC setup successful) |
| 28 | +# 3. PrismLauncher instance icon (fallback) |
| 29 | +# 4. System generic icon (ultimate fallback) |
| 30 | +# |
| 31 | +# DESKTOP FILE LOCATIONS: |
| 32 | +# - Desktop shortcut: ~/Desktop/MinecraftSplitscreen.desktop |
| 33 | +# - System integration: ~/.local/share/applications/MinecraftSplitscreen.desktop |
| 34 | +create_desktop_launcher() { |
| 35 | + print_header "🖥️ DESKTOP LAUNCHER SETUP" |
| 36 | + |
| 37 | + # ============================================================================= |
| 38 | + # DESKTOP LAUNCHER USER PROMPT |
| 39 | + # ============================================================================= |
| 40 | + |
| 41 | + # USER PREFERENCE GATHERING: Ask if they want desktop integration |
| 42 | + # Desktop launchers provide convenient access without terminal or Steam |
| 43 | + # Particularly useful for users who don't use Steam or prefer native desktop integration |
| 44 | + print_info "Desktop launcher creates a native shortcut for your desktop environment." |
| 45 | + print_info "Benefits: Desktop shortcut, application menu entry, search integration" |
| 46 | + echo "" |
| 47 | + read -p "Do you want to create a desktop launcher for Minecraft Splitscreen? [y/N]: " create_desktop |
| 48 | + if [[ "$create_desktop" =~ ^[Yy]$ ]]; then |
| 49 | + |
| 50 | + # ============================================================================= |
| 51 | + # DESKTOP FILE CONFIGURATION AND PATHS |
| 52 | + # ============================================================================= |
| 53 | + |
| 54 | + # DESKTOP FILE SETUP: Define paths and filenames following Linux standards |
| 55 | + # .desktop files follow the freedesktop.org Desktop Entry Specification |
| 56 | + # Standard locations ensure compatibility across all Linux desktop environments |
| 57 | + local desktop_file_name="MinecraftSplitscreen.desktop" |
| 58 | + local desktop_file_path="$HOME/Desktop/$desktop_file_name" # User desktop shortcut |
| 59 | + local app_dir="$HOME/.local/share/applications" # System integration directory |
| 60 | + |
| 61 | + # APPLICATIONS DIRECTORY CREATION: Ensure the applications directory exists |
| 62 | + # This directory is where desktop environments look for user-installed applications |
| 63 | + mkdir -p "$app_dir" |
| 64 | + print_info "Desktop file will be created at: $desktop_file_path" |
| 65 | + print_info "Application menu entry will be registered in: $app_dir" |
| 66 | + |
| 67 | + # ============================================================================= |
| 68 | + # ICON ACQUISITION AND CONFIGURATION |
| 69 | + # ============================================================================= |
| 70 | + |
| 71 | + # CUSTOM ICON DOWNLOAD: Get professional SteamGridDB icon for consistent branding |
| 72 | + # This provides the same visual identity as the Steam integration |
| 73 | + # SteamGridDB provides high-quality gaming artwork used by many Steam applications |
| 74 | + local icon_dir="$PWD/minecraft-splitscreen-icons" |
| 75 | + local icon_path="$icon_dir/minecraft-splitscreen-steamgriddb.ico" |
| 76 | + local icon_url="https://cdn2.steamgriddb.com/icon/add7a048049671970976f3e18f21ade3.ico" |
| 77 | + |
| 78 | + print_progress "Configuring desktop launcher icon..." |
| 79 | + mkdir -p "$icon_dir" # Ensure icon storage directory exists |
| 80 | + |
| 81 | + # ICON DOWNLOAD: Fetch SteamGridDB icon if not already present |
| 82 | + # This provides a professional-looking icon that matches Steam integration |
| 83 | + if [[ ! -f "$icon_path" ]]; then |
| 84 | + print_progress "Downloading custom icon from SteamGridDB..." |
| 85 | + if wget -O "$icon_path" "$icon_url" >/dev/null 2>&1; then |
| 86 | + print_success "✅ Custom icon downloaded successfully" |
| 87 | + else |
| 88 | + print_warning "⚠️ Custom icon download failed - will use fallback icons" |
| 89 | + fi |
| 90 | + else |
| 91 | + print_info " → Custom icon already present" |
| 92 | + fi |
| 93 | + |
| 94 | + # ============================================================================= |
| 95 | + # ICON SELECTION WITH FALLBACK HIERARCHY |
| 96 | + # ============================================================================= |
| 97 | + |
| 98 | + # ICON SELECTION: Determine the best available icon with intelligent fallbacks |
| 99 | + # Priority system ensures we always have a functional icon, preferring custom over generic |
| 100 | + local icon_desktop |
| 101 | + if [[ -f "$icon_path" ]]; then |
| 102 | + icon_desktop="$icon_path" # Best: Custom SteamGridDB icon |
| 103 | + print_info " → Using custom SteamGridDB icon for consistent branding" |
| 104 | + elif [[ "$USE_POLLYMC" == true ]] && [[ -f "$HOME/.local/share/PollyMC/instances/latestUpdate-1/icon.png" ]]; then |
| 105 | + icon_desktop="$HOME/.local/share/PollyMC/instances/latestUpdate-1/icon.png" # Good: PollyMC instance icon |
| 106 | + print_info " → Using PollyMC instance icon" |
| 107 | + elif [[ -f "$TARGET_DIR/instances/latestUpdate-1/icon.png" ]]; then |
| 108 | + icon_desktop="$TARGET_DIR/instances/latestUpdate-1/icon.png" # Acceptable: PrismLauncher instance icon |
| 109 | + print_info " → Using PrismLauncher instance icon" |
| 110 | + else |
| 111 | + icon_desktop="application-x-executable" # Fallback: Generic system executable icon |
| 112 | + print_info " → Using system default executable icon" |
| 113 | + fi |
| 114 | + |
| 115 | + # ============================================================================= |
| 116 | + # LAUNCHER SCRIPT PATH CONFIGURATION |
| 117 | + # ============================================================================= |
| 118 | + |
| 119 | + # LAUNCHER SCRIPT PATH DETECTION: Set correct executable path based on active launcher |
| 120 | + # The desktop file needs to point to the appropriate launcher script |
| 121 | + # Different paths and descriptions for PollyMC vs PrismLauncher configurations |
| 122 | + local launcher_script_path |
| 123 | + local launcher_comment |
| 124 | + if [[ "$USE_POLLYMC" == true ]]; then |
| 125 | + launcher_script_path="$HOME/.local/share/PollyMC/minecraftSplitscreen.sh" |
| 126 | + launcher_comment="Launch Minecraft splitscreen with PollyMC (optimized for offline gameplay)" |
| 127 | + print_info " → Desktop launcher configured for PollyMC" |
| 128 | + else |
| 129 | + launcher_script_path="$TARGET_DIR/minecraftSplitscreen.sh" |
| 130 | + launcher_comment="Launch Minecraft splitscreen with PrismLauncher" |
| 131 | + print_info " → Desktop launcher configured for PrismLauncher" |
| 132 | + fi |
| 133 | + |
| 134 | + # ============================================================================= |
| 135 | + # DESKTOP ENTRY FILE GENERATION |
| 136 | + # ============================================================================= |
| 137 | + |
| 138 | + # DESKTOP FILE CREATION: Generate .desktop file following freedesktop.org specification |
| 139 | + # This creates a proper desktop entry that integrates with all Linux desktop environments |
| 140 | + # The file contains metadata, execution parameters, and display information |
| 141 | + print_progress "Generating desktop entry file..." |
| 142 | + |
| 143 | + # Desktop Entry Specification fields: |
| 144 | + # - Type=Application: Indicates this is an application launcher |
| 145 | + # - Name: Display name in menus and desktop |
| 146 | + # - Comment: Tooltip/description text |
| 147 | + # - Exec: Command to execute when launched |
| 148 | + # - Icon: Icon file path or theme icon name |
| 149 | + # - Terminal: Whether to run in terminal (false for GUI applications) |
| 150 | + # - Categories: Menu categories for proper organization |
| 151 | + |
| 152 | + cat > "$desktop_file_path" <<EOF |
| 153 | +[Desktop Entry] |
| 154 | +Type=Application |
| 155 | +Name=Minecraft Splitscreen |
| 156 | +Comment=$launcher_comment |
| 157 | +Exec=$launcher_script_path |
| 158 | +Icon=$icon_desktop |
| 159 | +Terminal=false |
| 160 | +Categories=Game; |
| 161 | +EOF |
| 162 | + |
| 163 | + print_success "✅ Desktop entry file created successfully" |
| 164 | + |
| 165 | + # ============================================================================= |
| 166 | + # DESKTOP FILE PERMISSIONS AND VALIDATION |
| 167 | + # ============================================================================= |
| 168 | + |
| 169 | + # DESKTOP FILE PERMISSIONS: Make the .desktop file executable |
| 170 | + # Many desktop environments require .desktop files to be executable |
| 171 | + # This ensures the launcher appears and functions properly across all DEs |
| 172 | + chmod +x "$desktop_file_path" |
| 173 | + print_info " → Desktop file permissions set to executable" |
| 174 | + |
| 175 | + # DESKTOP FILE VALIDATION: Basic syntax check |
| 176 | + # Verify the generated .desktop file has required fields |
| 177 | + if [[ -f "$desktop_file_path" ]] && grep -q "Type=Application" "$desktop_file_path"; then |
| 178 | + print_success "✅ Desktop file validation passed" |
| 179 | + else |
| 180 | + print_warning "⚠️ Desktop file validation failed - file may not work properly" |
| 181 | + fi |
| 182 | + |
| 183 | + # ============================================================================= |
| 184 | + # SYSTEM INTEGRATION AND REGISTRATION |
| 185 | + # ============================================================================= |
| 186 | + |
| 187 | + # SYSTEM INTEGRATION: Copy to applications directory for system-wide access |
| 188 | + # This makes the launcher appear in application menus, search results, and launchers |
| 189 | + # The ~/.local/share/applications directory is the standard location for user applications |
| 190 | + print_progress "Registering application with desktop environment..." |
| 191 | + |
| 192 | + if cp "$desktop_file_path" "$app_dir/$desktop_file_name"; then |
| 193 | + print_success "✅ Application registered in system applications directory" |
| 194 | + else |
| 195 | + print_warning "⚠️ Failed to register application system-wide" |
| 196 | + fi |
| 197 | + |
| 198 | + # ============================================================================= |
| 199 | + # DESKTOP DATABASE UPDATE |
| 200 | + # ============================================================================= |
| 201 | + |
| 202 | + # DATABASE UPDATE: Refresh desktop database to register new application immediately |
| 203 | + # This ensures the launcher appears in menus without requiring logout/reboot |
| 204 | + # The update-desktop-database command updates the application cache |
| 205 | + print_progress "Updating desktop application database..." |
| 206 | + |
| 207 | + if command -v update-desktop-database >/dev/null 2>&1; then |
| 208 | + update-desktop-database "$app_dir" 2>/dev/null || true |
| 209 | + print_success "✅ Desktop database updated - launcher available immediately" |
| 210 | + else |
| 211 | + print_info " → Desktop database update tool not found (launcher may need logout to appear)" |
| 212 | + fi |
| 213 | + |
| 214 | + # ============================================================================= |
| 215 | + # DESKTOP LAUNCHER COMPLETION SUMMARY |
| 216 | + # ============================================================================= |
| 217 | + |
| 218 | + print_success "🖥️ Desktop launcher setup complete!" |
| 219 | + print_info "" |
| 220 | + print_info "📋 Desktop Integration Summary:" |
| 221 | + print_info " → Desktop shortcut: $desktop_file_path" |
| 222 | + print_info " → Application menu: $app_dir/$desktop_file_name" |
| 223 | + print_info " → Icon: $(basename "$icon_desktop")" |
| 224 | + print_info " → Target launcher: $(basename "$launcher_script_path")" |
| 225 | + print_info "" |
| 226 | + print_info "🚀 Access Methods:" |
| 227 | + print_info " → Double-click desktop shortcut" |
| 228 | + print_info " → Search for 'Minecraft Splitscreen' in application menu" |
| 229 | + print_info " → Launch from desktop environment's application launcher" |
| 230 | + else |
| 231 | + # ============================================================================= |
| 232 | + # DESKTOP LAUNCHER DECLINED |
| 233 | + # ============================================================================= |
| 234 | + |
| 235 | + print_info "⏭️ Skipping desktop launcher creation" |
| 236 | + print_info " → You can still launch via Steam (if configured) or manually run the script" |
| 237 | + print_info " → Manual launch command:" |
| 238 | + if [[ "$USE_POLLYMC" == true ]]; then |
| 239 | + print_info " $HOME/.local/share/PollyMC/minecraftSplitscreen.sh" |
| 240 | + else |
| 241 | + print_info " $TARGET_DIR/minecraftSplitscreen.sh" |
| 242 | + fi |
| 243 | + fi |
| 244 | +} |
0 commit comments