| 
 | 1 | +package packaging  | 
 | 2 | + | 
 | 3 | +import (  | 
 | 4 | +	"github.com/go-flutter-desktop/hover/internal/build"  | 
 | 5 | +	"github.com/go-flutter-desktop/hover/internal/log"  | 
 | 6 | +	"github.com/go-flutter-desktop/hover/internal/pubspec"  | 
 | 7 | +	"github.com/otiai10/copy"  | 
 | 8 | +	"os"  | 
 | 9 | +	"path/filepath"  | 
 | 10 | +)  | 
 | 11 | + | 
 | 12 | +func InitLinuxAppImage() {  | 
 | 13 | +	projectName := pubspec.GetPubSpec().Name  | 
 | 14 | +	packagingFormat := "linux-appimage"  | 
 | 15 | +	createPackagingFormatDirectory(packagingFormat)  | 
 | 16 | +	appImageDirectoryPath := packagingFormatPath(packagingFormat)  | 
 | 17 | +	appRunFilePath, err := filepath.Abs(filepath.Join(appImageDirectoryPath, "AppRun"))  | 
 | 18 | +	if err != nil {  | 
 | 19 | +		log.Errorf("Failed to resolve absolute path for AppRun file %s: %v", appRunFilePath, err)  | 
 | 20 | +		os.Exit(1)  | 
 | 21 | +	}  | 
 | 22 | + | 
 | 23 | +	appRunFile, err := os.Create(appRunFilePath)  | 
 | 24 | +	if err != nil {  | 
 | 25 | +		log.Errorf("Failed to create AppRun file %s: %v", appRunFilePath, err)  | 
 | 26 | +		os.Exit(1)  | 
 | 27 | +	}  | 
 | 28 | +	appRunFileContent := []string{  | 
 | 29 | +		`#!/bin/sh`,  | 
 | 30 | +		`cd "$(dirname "$0")"`,  | 
 | 31 | +		`exec ./build/` + projectName,  | 
 | 32 | +	}  | 
 | 33 | +	for _, line := range appRunFileContent {  | 
 | 34 | +		if _, err := appRunFile.WriteString(line + "\n"); err != nil {  | 
 | 35 | +			log.Errorf("Could not write AppRun file: %v", err)  | 
 | 36 | +			os.Exit(1)  | 
 | 37 | +		}  | 
 | 38 | +	}  | 
 | 39 | +	err = appRunFile.Close()  | 
 | 40 | +	if err != nil {  | 
 | 41 | +		log.Errorf("Could not close AppRun file: %v", err)  | 
 | 42 | +		os.Exit(1)  | 
 | 43 | +	}  | 
 | 44 | +	err = os.Chmod(appRunFilePath, 0777)  | 
 | 45 | +	if err != nil {  | 
 | 46 | +		log.Errorf("Failed to change file permissions for AppRun file: %v", err)  | 
 | 47 | +		os.Exit(1)  | 
 | 48 | +	}  | 
 | 49 | + | 
 | 50 | +	desktopFilePath, err := filepath.Abs(filepath.Join(appImageDirectoryPath, projectName+".desktop"))  | 
 | 51 | +	if err != nil {  | 
 | 52 | +		log.Errorf("Failed to resolve absolute path for desktop file %s: %v", desktopFilePath, err)  | 
 | 53 | +		os.Exit(1)  | 
 | 54 | +	}  | 
 | 55 | +	createLinuxDesktopFile(desktopFilePath, packagingFormat, "", "/build/assets/icon")  | 
 | 56 | +	createDockerfile(packagingFormat)  | 
 | 57 | + | 
 | 58 | +	printInitFinished(packagingFormat)  | 
 | 59 | +}  | 
 | 60 | + | 
 | 61 | +func BuildLinuxAppImage() {  | 
 | 62 | +	projectName := pubspec.GetPubSpec().Name  | 
 | 63 | +	packagingFormat := "linux-appimage"  | 
 | 64 | +	tmpPath := getTemporaryBuildDirectory(projectName, packagingFormat)  | 
 | 65 | +	log.Infof("Packaging AppImage in %s", tmpPath)  | 
 | 66 | + | 
 | 67 | +	err := copy.Copy(build.OutputDirectoryPath("linux"), filepath.Join(tmpPath, "build"))  | 
 | 68 | +	if err != nil {  | 
 | 69 | +		log.Errorf("Could not copy build folder: %v", err)  | 
 | 70 | +		os.Exit(1)  | 
 | 71 | +	}  | 
 | 72 | +	err = copy.Copy(packagingFormatPath(packagingFormat), filepath.Join(tmpPath))  | 
 | 73 | +	if err != nil {  | 
 | 74 | +		log.Errorf("Could not copy packaging configuration folder: %v", err)  | 
 | 75 | +		os.Exit(1)  | 
 | 76 | +	}  | 
 | 77 | + | 
 | 78 | +	outputFileName := projectName + "-x86_64.AppImage"  | 
 | 79 | +	outputFilePath := filepath.Join(build.OutputDirectoryPath("linux-appimage"), outputFileName)  | 
 | 80 | +	runDockerPackaging(tmpPath, packagingFormat, []string{"appimagetool", ".",})  | 
 | 81 | + | 
 | 82 | +	err = os.Rename(filepath.Join(tmpPath, outputFileName), outputFilePath)  | 
 | 83 | +	if err != nil {  | 
 | 84 | +		log.Errorf("Could not move AppImage file: %v", err)  | 
 | 85 | +		os.Exit(1)  | 
 | 86 | +	}  | 
 | 87 | +	err = os.RemoveAll(tmpPath)  | 
 | 88 | +	if err != nil {  | 
 | 89 | +		log.Errorf("Could not remove temporary build directory: %v", err)  | 
 | 90 | +		os.Exit(1)  | 
 | 91 | +	}  | 
 | 92 | +	printPackagingFinished(packagingFormat)  | 
 | 93 | +}  | 
0 commit comments