swadhinbiswas feat: initial release of VEET (Universal Linux App Uninstaller & Deep-Clean Residual Purger) · 8/15/2026
5e0888a
51 lines · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package detector

import (
	"context"
	"strings"

	"github.com/swadhinbiswas/veet/internal/model"
)

type flatpakDetector struct {
	ex   Execer
	path string
}

// NewFlatpakDetector detects flatpak applications.
func NewFlatpakDetector(ex Execer) Detector {
	path, _ := ex.LookPath("flatpak")
	return &flatpakDetector{ex: ex, path: path}
}

func (d *flatpakDetector) Source() string  { return "flatpak" }
func (d *flatpakDetector) Available() bool { return d.path != "" }

func (d *flatpakDetector) Detect(ctx context.Context) ([]model.AppInfo, error) {
	out, err := Exec(ctx, d.ex, "flatpak", "list", "--app",
		"--columns=application,version,size,installation,origin")
	if err != nil {
		return nil, err
	}
	var apps []model.AppInfo
	for _, line := range strings.Split(out, "\n") {
		parts := strings.Split(line, "\t")
		if len(parts) < 3 || parts[0] == "" || !strings.Contains(parts[0], ".") {
			continue
		}
		app := model.AppInfo{
			Name:   parts[0],
			Source: "flatpak",
			Status: "Installed",
		}
		if len(parts) > 1 {
			app.Version = strings.TrimSpace(parts[1])
		}
		if len(parts) > 2 {
			app.InstallSizeKB = parseHumanSize(parts[2])
		}
		apps = append(apps, app)
	}
	return apps, nil
}