Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func runMain(args []string) {
if isMacOS && !*noVM {
setupFirecrackerVM()
}
ensureLibreOfficeAutoSave()
}

if pyenvWG != nil {
Expand Down
42 changes: 42 additions & 0 deletions post.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,3 +544,45 @@ func installGHExtension(repo string) {
}
}

// ── LibreOffice AutoSave Extension ──────────────────────────────────────

func ensureLibreOfficeAutoSave() {
var unopkgPath string
if isMacOS {
unopkgPath = "/Applications/LibreOffice.app/Contents/MacOS/unopkg"
if _, err := osStat(unopkgPath); err != nil {
return
}
} else {
if !hasCmd("unopkg") {
return
}
unopkgPath = "unopkg"
}

fmt.Println("\n[LibreOffice] LibreOffice detected. Installing AutoSave extension ...")

tmp, err := os.MkdirTemp("", "libreoffice-autosave-")
if err != nil {
errLog(fmt.Sprintf("LibreOffice AutoSave temp dir failed: %v", err))
return
}
defer osRemoveAll(tmp)

url := "https://github.com/JMR-dev/LibreOfficeAutoSave/releases/latest/download/AutoSave.oxt"
dest := filepath.Join(tmp, "AutoSave.oxt")

if !download(url, dest) {
errLog("Failed to download LibreOffice AutoSave extension")
return
}

if !runCmd([]string{unopkgPath, "add", "-f", dest}, CmdOpts{}).OK() {
errLog("Failed to install LibreOffice AutoSave extension")
return
}

fmt.Println(" LibreOffice AutoSave extension installed successfully.")
}


94 changes: 94 additions & 0 deletions post_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -905,4 +905,98 @@ func TestEnsurePythonLatestBackgroundInstall(t *testing.T) {
}
}

func TestEnsureLibreOfficeAutoSave(t *testing.T) {
defer resetMocks()

// 1. isMacOS = false, LibreOffice not installed
isMacOS = false
hasCmd = func(name string) bool {
if name == "unopkg" {
return false
}
return true
}
var calledDownload bool
download = func(url, dest string) bool {
calledDownload = true
return true
}
ensureLibreOfficeAutoSave()
if calledDownload {
t.Error("expected download not to be called when unopkg is missing")
}

// 2. isMacOS = true, LibreOffice not installed
isMacOS = true
osStat = func(name string) (os.FileInfo, error) {
return nil, os.ErrNotExist
}
calledDownload = false
ensureLibreOfficeAutoSave()
if calledDownload {
t.Error("expected download not to be called when unopkg is missing on macOS")
}

// 3. isMacOS = false, LibreOffice installed, download fails
isMacOS = false
hasCmd = func(name string) bool {
return name == "unopkg"
}
download = func(url, dest string) bool {
return false
}
var runCmdCalled bool
runCmd = func(argv []string, opts CmdOpts) CmdResult {
runCmdCalled = true
return CmdResult{ExitCode: 0}
}
ensureLibreOfficeAutoSave()
if runCmdCalled {
t.Error("expected runCmd not to be called when download fails")
}

// 4. isMacOS = false, LibreOffice installed, download succeeds, runCmd fails
download = func(url, dest string) bool {
return true
}
var unopkgArgv []string
runCmd = func(argv []string, opts CmdOpts) CmdResult {
unopkgArgv = argv
return CmdResult{ExitCode: 1}
}
ensureLibreOfficeAutoSave()
if len(unopkgArgv) == 0 || unopkgArgv[0] != "unopkg" {
t.Errorf("expected runCmd with unopkg, got: %v", unopkgArgv)
}

// 5. isMacOS = false, LibreOffice installed, download succeeds, runCmd succeeds
runCmd = func(argv []string, opts CmdOpts) CmdResult {
unopkgArgv = argv
return CmdResult{ExitCode: 0}
}
ensureLibreOfficeAutoSave()
if len(unopkgArgv) == 0 || unopkgArgv[0] != "unopkg" || unopkgArgv[1] != "add" || unopkgArgv[2] != "-f" {
t.Errorf("expected runCmd with unopkg add -f, got: %v", unopkgArgv)
}

// 6. isMacOS = true, LibreOffice installed, download succeeds, runCmd succeeds
isMacOS = true
osStat = func(name string) (os.FileInfo, error) {
if name == "/Applications/LibreOffice.app/Contents/MacOS/unopkg" {
return nil, nil
}
return nil, os.ErrNotExist
}
runCmd = func(argv []string, opts CmdOpts) CmdResult {
unopkgArgv = argv
return CmdResult{ExitCode: 0}
}
ensureLibreOfficeAutoSave()
expectedMacPath := "/Applications/LibreOffice.app/Contents/MacOS/unopkg"
if len(unopkgArgv) == 0 || unopkgArgv[0] != expectedMacPath {
t.Errorf("expected runCmd with %s, got: %v", expectedMacPath, unopkgArgv)
}
}



Loading