feat(display): pdf support

This commit is contained in:
2025-11-28 23:57:02 +01:00
parent a7184847bb
commit 78fde49329
5 changed files with 69 additions and 20 deletions
+24 -3
View File
@@ -47,20 +47,33 @@ func GetDeviceMac() (string, error) {
return "", fmt.Errorf("no suitable MAC address found")
}
var runningHelpProgram *exec.Cmd = nil
func OpenPresentation(path string) error {
tempDirPath, err := os.MkdirTemp("", "plg-mudics-libreoffice-profile-")
if err != nil {
return fmt.Errorf("failed to create temporary profile directory: %w", err)
}
cmd := exec.Command("soffice", "--show", path, "--nologo", "--norestore", fmt.Sprintf("-env:UserInstallation=file:///%s", tempDirPath))
result := shared.RunShellCommand(cmd)
if result.ExitCode != 0 {
runningHelpProgram = exec.Command("soffice", "--show", path, "--nologo", "--norestore", fmt.Sprintf("-env:UserInstallation=file:///%s", tempDirPath))
result := shared.RunShellCommand(runningHelpProgram)
killedByParent := -1
if result.ExitCode != 0 && result.ExitCode != killedByParent {
return errors.New(result.Stderr)
}
return nil
}
func OpenPDF(path string) error {
runningHelpProgram = exec.Command("xreader", path, "--presentation")
result := shared.RunShellCommandNonBlocking(runningHelpProgram)
killedByParent := -1
if result.ExitCode != 0 && result.ExitCode != killedByParent {
return fmt.Errorf("could not open pdf: %s (%d)", result.Stderr, result.ExitCode)
}
return nil
}
type KeyAction int
const (
@@ -154,3 +167,11 @@ func ResolveStorageFilePath(pathParam string) (string, bool, error) {
return fullPath, true, nil
}
func CloseRunningProgram() error {
if runningHelpProgram == nil {
return nil
}
err := runningHelpProgram.Process.Kill()
return err
}