Commit 3efa852e authored by Roman Alifanov's avatar Roman Alifanov

implemented background mode

parent 5e827820
......@@ -2,8 +2,8 @@ package main
import (
"SystemUpdater/lib/apm"
sudbus "SystemUpdater/lib/apm/sudbus"
bldr "SystemUpdater/lib/gtks/builder"
"fmt"
"os"
"unsafe"
......@@ -11,6 +11,7 @@ import (
_ "embed"
"github.com/diamondburned/gotk4-adwaita/pkg/adw"
"github.com/diamondburned/gotk4/pkg/core/glib"
"github.com/diamondburned/gotk4/pkg/gio/v2"
"github.com/diamondburned/gotk4/pkg/gtk/v4"
)
......@@ -26,7 +27,7 @@ var mainApp *SystemUpdater
func GetSystemUpdater() *SystemUpdater {
if mainApp == nil {
xdgName := "ru.ximperlinux.SystemUpdater"
appAdw := adw.NewApplication(xdgName, gio.ApplicationFlagsNone)
appAdw := adw.NewApplication(xdgName, gio.ApplicationFlags(8))
appGtk := (*gtk.Application)(unsafe.Pointer(appAdw))
mainApp = &SystemUpdater{
......@@ -38,22 +39,36 @@ func GetSystemUpdater() *SystemUpdater {
return mainApp
}
func (su *SystemUpdater) onActivate() {
conn := sudbus.GetConnection()
var updates []apm.PackageChanges
defer conn.Conn.Close()
func (su *SystemUpdater) backgroundStart() {
updatesSources := apm.NewUpdatesSources()
upds := apm.NewUpdatesSources()
for _, u := range updatesSources {
updates = append(updates, u.GetPackageChanges())
}
}
func (su *SystemUpdater) onActivate() {
su.App.Release()
window := GetSystemUpdaterWindow()
window.SetApplication(su.AppGTK)
for _, us := range upds {
window.FillWithChanges(su, us)
}
window.stack.SetVisibleChildName("loading")
window.Present()
// Это выглядит прям очень плохо... Потом надо бы переделать по уму
glib.TimeoutAdd(100, func() bool {
if len(updates) > 0 {
window.FillWithChanges(su, updates)
window.stack.SetVisibleChildName("main")
return false
}
return true
})
}
//go:embed window.ui
......@@ -63,6 +78,7 @@ type SystemUpdaterWindow struct {
*adw.ApplicationWindow
navView *adw.NavigationView
listbox *gtk.ListBox
stack *gtk.Stack
}
var mainWin *SystemUpdaterWindow
......@@ -75,18 +91,22 @@ func GetSystemUpdaterWindow() *SystemUpdaterWindow {
navView := bldr.GetObject[*adw.NavigationView](builder, "navigationv")
listbox := bldr.GetObject[*gtk.ListBox](builder, "updates_listbox")
stack := bldr.GetObject[*gtk.Stack](builder, "main_stack")
mainWin = &SystemUpdaterWindow{
win,
navView,
listbox,
stack,
}
}
return mainWin
}
func (sw *SystemUpdaterWindow) FillWithChanges(su *SystemUpdater, us apm.UpdaterSource) {
sw.listbox.Append(NewUpdateRow("System packages", us.GetPackageChanges()))
func (sw *SystemUpdaterWindow) FillWithChanges(su *SystemUpdater, u []apm.PackageChanges) {
for _, updatesList := range u {
sw.listbox.Append(NewUpdateRow("System packages", updatesList))
}
}
func SystemUpdaterApplication(su *SystemUpdater) {
......@@ -94,6 +114,52 @@ func SystemUpdaterApplication(su *SystemUpdater) {
su.onActivate()
})
su.App.ConnectCommandLine(func(cmd *gio.ApplicationCommandLine) int {
args := cmd.Arguments()
fmt.Println("Got args:", args)
if cmd.IsRemote() {
fmt.Println("Remote command received!")
su.App.Activate()
cmd.Done()
return 0
}
backgroundMode := false
if len(args) > 1 {
for _, arg := range args[1:] {
switch arg {
case "--background", "-b":
backgroundMode = true
default:
fmt.Fprintf(os.Stderr, "Error: unknown argument %q\n", arg)
cmd.Done()
os.Exit(1)
}
}
}
if backgroundMode {
fmt.Println("Running in background mode...")
su.App.Hold()
go su.backgroundStart()
cmd.Done()
return 0
}
go su.backgroundStart()
su.App.Activate()
cmd.Done()
return 0
})
os.Exit(su.App.Run(os.Args))
}
......
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