further fixes to hampack-manager

This commit is contained in:
David Young
2026-03-31 16:14:43 -06:00
parent 3187dd3c79
commit 5afd4c077d

View File

@@ -119,15 +119,69 @@ func parseFlatpaks() []string {
// ── State ────────────────────────────────────────────────────────────────────── // ── State ──────────────────────────────────────────────────────────────────────
func loadState() map[string]bool { // installedPacmanPackages returns a set of all installed pacman package names.
data, err := os.ReadFile(stateFilePath()) func installedPacmanPackages() map[string]bool {
out, err := exec.Command("pacman", "-Q").Output()
if err != nil { if err != nil {
return map[string]bool{} return map[string]bool{}
} }
var state map[string]bool installed := make(map[string]bool)
if err := json.Unmarshal(data, &state); err != nil { for _, line := range strings.Split(string(out), "\n") {
if fields := strings.Fields(line); len(fields) > 0 {
installed[fields[0]] = true
}
}
return installed
}
// installedFlatpaks returns a set of all installed Flatpak application IDs.
func installedFlatpaks() map[string]bool {
out, err := exec.Command("flatpak", "list", "--app", "--columns=application").Output()
if err != nil {
return map[string]bool{} return map[string]bool{}
} }
installed := make(map[string]bool)
for _, line := range strings.Split(string(out), "\n") {
if s := strings.TrimSpace(line); s != "" {
installed[s] = true
}
}
return installed
}
// detectInitialState checks actual installation status for every item.
func detectInitialState(
utils, apps, flatpaks []string,
compiled, binaries map[string]map[string]string,
) map[string]bool {
pacman := installedPacmanPackages()
flatpak := installedFlatpaks()
state := make(map[string]bool)
for _, name := range utils {
state["utility:"+name] = pacman[name]
}
for _, name := range apps {
state["application:"+name] = pacman[name]
}
for _, id := range flatpaks {
state["flatpak:"+id] = flatpak[id]
}
for name, fields := range compiled {
path := expand(fields["install"])
_, err := os.Stat(path)
state["compiled:"+name] = err == nil
}
for name, fields := range binaries {
path := expand(fields["install"])
_, err := os.Stat(path)
state["binary:"+name] = err == nil
}
for _, item := range windowsItems {
_, err := os.Stat(item[1])
state["windows:"+item[0]] = err == nil
}
return state return state
} }
@@ -137,6 +191,7 @@ func saveState(state map[string]bool) {
os.WriteFile(stateFilePath(), data, 0644) os.WriteFile(stateFilePath(), data, 0644)
} }
// ── Operations ──────────────────────────────────────────────────────────────── // ── Operations ────────────────────────────────────────────────────────────────
type Op struct { type Op struct {
@@ -435,11 +490,16 @@ type mainWin struct {
} }
func newMainWin(app *adw.Application) *mainWin { func newMainWin(app *adw.Application) *mainWin {
compiled := parseINI(filepath.Join(hampackDir(), "compile.conf"))
binaries := parseINI(filepath.Join(hampackDir(), "binaries.conf"))
utils, apps := parsePackages()
flatpaks := parseFlatpaks()
w := &mainWin{ w := &mainWin{
ApplicationWindow: adw.NewApplicationWindow(&app.Application), ApplicationWindow: adw.NewApplicationWindow(&app.Application),
compiled: parseINI(filepath.Join(hampackDir(), "compile.conf")), compiled: compiled,
binaries: parseINI(filepath.Join(hampackDir(), "binaries.conf")), binaries: binaries,
state: loadState(), state: detectInitialState(utils, apps, flatpaks, compiled, binaries),
rows: make(map[string]*gtk.Switch), rows: make(map[string]*gtk.Switch),
} }
w.SetTitle("HamPack Manager") w.SetTitle("HamPack Manager")
@@ -459,9 +519,6 @@ func newMainWin(app *adw.Application) *mainWin {
page := adw.NewPreferencesPage() page := adw.NewPreferencesPage()
toolbar.SetContent(page) toolbar.SetContent(page)
utils, apps := parsePackages()
flatpaks := parseFlatpaks()
windows := make([]string, len(windowsItems)) windows := make([]string, len(windowsItems))
for i, item := range windowsItems { for i, item := range windowsItems {
windows[i] = item[0] windows[i] = item[0]