mirror of
https://codeberg.org/PLG-Development/PLG-MuDiCS
synced 2026-07-05 16:37:09 +00:00
refactor(display): move open logic into own file
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package pkg
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"plg-mudics/shared"
|
||||
)
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func CloseRunningProgram() error {
|
||||
if runningHelpProgram == nil {
|
||||
return nil
|
||||
}
|
||||
err := runningHelpProgram.Process.Kill()
|
||||
return err
|
||||
}
|
||||
@@ -47,33 +47,6 @@ 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)
|
||||
}
|
||||
|
||||
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 (
|
||||
@@ -167,11 +140,3 @@ 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user