Commit 93d43fb4 authored by Roman Alifanov's avatar Roman Alifanov

parallel package info loading (max 15 threads) and icons support

parent aa7ff78a
package apm
import (
"SystemUpdater/lib/apm/sudbus"
"encoding/json"
)
func GetPackageInfo(name string) InfoResponse {
conn := sudbus.GetConnection()
reply := conn.BusObject.Call("org.altlinux.APM.system.Info", 0, name, "Ximper System Updater")
if reply.Err != nil {
panic("Error during async method call: " + reply.Err.Error())
}
if len(reply.Body) < 1 {
panic("Unexpected reply body")
}
responseStr, ok := reply.Body[0].(string)
if !ok {
panic("Unexpected response type")
}
var response InfoRootResponse
if err := json.Unmarshal([]byte(responseStr), &response); err != nil {
panic("Failed to parse response: " + err.Error())
}
return response.Data
}
......@@ -102,3 +102,8 @@ type InfoResponse struct {
Message string `json:"message"`
PackageInfo Package `json:"packageInfo"`
}
type InfoRootResponse struct {
Data InfoResponse `json:"data"`
Error bool `json:"error"`
}
package sudbus
import (
"log"
"github.com/godbus/dbus/v5"
)
type Connection struct {
Conn *dbus.Conn
BusObject dbus.BusObject
}
var conn *Connection
func GetConnection() *Connection {
if conn == nil {
connection, err := dbus.ConnectSystemBus()
if err != nil {
log.Fatal(err)
}
obj := connection.Object("org.altlinux.APM", dbus.ObjectPath("/org/altlinux/APM"))
conn = &Connection{connection, obj}
}
return conn
}
package apm
import (
"SystemUpdater/lib/apm/sudbus"
"encoding/json"
"github.com/godbus/dbus/v5"
......@@ -56,9 +57,10 @@ func updatesOutputProcessing(reply *dbus.Call) PackageChanges {
type UpdatesSources map[string]UpdaterSource
func NewUpdatesSources(conn *dbus.Conn, obj dbus.BusObject) UpdatesSources {
func NewUpdatesSources() UpdatesSources {
conn := sudbus.GetConnection()
return UpdatesSources{
"System": &SystemUpdatesSource{conn: conn, obj: obj},
"System": &SystemUpdatesSource{conn: conn.Conn, obj: conn.BusObject},
// "Kernel": &KernelUpdatesSource{conn: conn, obj: obj},
}
}
......
......@@ -2,8 +2,9 @@ package main
import (
"SystemUpdater/lib/apm"
sudbus "SystemUpdater/lib/apm/sudbus"
bldr "SystemUpdater/lib/gtks/builder"
"log"
"os"
"unsafe"
......@@ -12,7 +13,6 @@ import (
"github.com/diamondburned/gotk4-adwaita/pkg/adw"
"github.com/diamondburned/gotk4/pkg/gio/v2"
"github.com/diamondburned/gotk4/pkg/gtk/v4"
"github.com/godbus/dbus/v5"
)
type SystemUpdater struct {
......@@ -39,16 +39,11 @@ func GetSystemUpdater() *SystemUpdater {
}
func (su *SystemUpdater) onActivate() {
conn, err := dbus.ConnectSystemBus()
if err != nil {
log.Fatal(err)
}
defer conn.Close()
conn := sudbus.GetConnection()
obj := conn.Object("org.altlinux.APM", dbus.ObjectPath("/org/altlinux/APM"))
defer conn.Conn.Close()
upds := apm.NewUpdatesSources(conn, obj)
upds := apm.NewUpdatesSources()
window := GetSystemUpdaterWindow()
......
......@@ -3,6 +3,9 @@ package main
import (
"SystemUpdater/lib/apm"
bldr "SystemUpdater/lib/gtks/builder"
"fmt"
"strings"
"sync"
_ "embed"
......@@ -10,10 +13,25 @@ import (
"github.com/diamondburned/gotk4/pkg/gtk/v4"
)
func NewPackageRow(item string, ver string) *adw.ActionRow {
func NewPackageRow(name string, info apm.Package) *adw.ActionRow {
row := adw.NewActionRow()
row.SetTitle(item)
row.SetSubtitle(ver)
if info.AppStream != nil && len(info.AppStream.Icons) > 0 {
ico := info.AppStream.Icons[len(info.AppStream.Icons)-1]
icoPath := fmt.Sprintf(
"/usr/share/swcatalog/icons/altlinux/%dx%d/%s",
ico.Height, ico.Width, ico.Value,
)
icoWidget := gtk.NewImageFromFile(icoPath)
icoWidget.SetIconSize(gtk.IconSizeLarge)
row.AddPrefix(icoWidget)
}
row.SetTitle(name)
row.SetSubtitle(info.VersionInstalled + " -> " + strings.Split(info.VersionRaw, ":")[0])
return row
}
......@@ -58,6 +76,32 @@ func NewUpdateRow(name string, info apm.PackageChanges) *adw.ActionRow {
continue
}
pkgsWithInfo := make(map[string]apm.InfoResponse)
var mu sync.Mutex
var wg sync.WaitGroup
sem := make(chan struct{}, 15)
for _, p := range pkgs {
wg.Add(1)
go func(pkg string) {
defer wg.Done()
sem <- struct{}{}
defer func() { <-sem }()
info := apm.GetPackageInfo(pkg)
mu.Lock()
pkgsWithInfo[pkg] = info
mu.Unlock()
}(p)
}
wg.Wait()
row := adw.NewActionRow()
row.SetTitle(title)
row.SetActivatable(true)
......@@ -68,9 +112,8 @@ func NewUpdateRow(name string, info apm.PackageChanges) *adw.ActionRow {
win.navView.Push(page.nav)
})
for _, p := range pkgs {
ar := adw.NewActionRow()
ar.SetTitle(p)
for p, info := range pkgsWithInfo {
ar := NewPackageRow(p, info.PackageInfo)
page.listbox.Append(ar)
}
upage.listbox.Append(row)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment