Commit 1f6fe85e authored by Roman Alifanov's avatar Roman Alifanov

Refresh repos before checking updates

parent 08e4bea4
...@@ -11,6 +11,41 @@ import ( ...@@ -11,6 +11,41 @@ import (
"github.com/diamondburned/gotk4/pkg/glib/v2" "github.com/diamondburned/gotk4/pkg/glib/v2"
) )
func (c *Client) RefreshRepos(ctx context.Context, transaction string) error {
errorCh := make(chan error, 1)
args := glib.NewVariantTuple([]*glib.Variant{
glib.NewVariantString(transaction),
})
c.conn.QueryProxy.Call(
ctx,
"Update",
args,
gio.DBusCallFlagsNone,
300000, // 5 minutes timeout
func(res gio.AsyncResulter) {
_, err := c.conn.QueryProxy.CallFinish(res)
if err != nil {
errorCh <- err
return
}
errorCh <- nil
},
)
select {
case <-ctx.Done():
return ctx.Err()
case err := <-errorCh:
if err != nil {
log.Printf("RefreshRepos error: %v", err)
return fmt.Errorf("repo refresh failed: %w", err)
}
return nil
}
}
func (c *Client) CheckSystemUpdates(ctx context.Context) (*model.PackageChanges, error) { func (c *Client) CheckSystemUpdates(ctx context.Context) (*model.PackageChanges, error) {
resultCh := make(chan *glib.Variant, 1) resultCh := make(chan *glib.Variant, 1)
errorCh := make(chan error, 1) errorCh := make(chan error, 1)
......
...@@ -7,7 +7,6 @@ import ( ...@@ -7,7 +7,6 @@ import (
"SystemUpdater/service" "SystemUpdater/service"
"SystemUpdater/store" "SystemUpdater/store"
"SystemUpdater/ui" "SystemUpdater/ui"
"context"
"log" "log"
"os" "os"
...@@ -67,12 +66,6 @@ func main() { ...@@ -67,12 +66,6 @@ func main() {
app.ConnectActivate(func() { app.ConnectActivate(func() {
window := ui.NewWindow(app, st, updateSvc, historySvc) window := ui.NewWindow(app, st, updateSvc, historySvc)
window.Window.Present() window.Window.Present()
go func() {
if err := updateSvc.CheckAllUpdates(context.Background()); err != nil {
log.Printf("Initial update check failed: %v", err)
}
}()
}) })
app.ConnectCommandLine(func(cmdLine *gio.ApplicationCommandLine) int { app.ConnectCommandLine(func(cmdLine *gio.ApplicationCommandLine) int {
......
...@@ -56,7 +56,6 @@ func (ss *SchedulerService) Stop() { ...@@ -56,7 +56,6 @@ func (ss *SchedulerService) Stop() {
} }
func (ss *SchedulerService) run() { func (ss *SchedulerService) run() {
// Run immediately on start
ss.checkUpdates() ss.checkUpdates()
for { for {
......
...@@ -30,6 +30,10 @@ func (us *UpdateService) CheckAllUpdates(ctx context.Context) error { ...@@ -30,6 +30,10 @@ func (us *UpdateService) CheckAllUpdates(ctx context.Context) error {
us.store.Dispatch(&store.SetPhaseAction{Phase: store.PhaseLoading}) us.store.Dispatch(&store.SetPhaseAction{Phase: store.PhaseLoading})
if err := us.eepmClient.RefreshRepos(ctx, ""); err != nil {
log.Printf("Failed to refresh repos: %v", err)
}
err := us.doCheckAllUpdates(ctx) err := us.doCheckAllUpdates(ctx)
if err != nil { if err != nil {
// Try reconnect and retry once // Try reconnect and retry once
......
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