Commit 89e3bbef authored by Roman Alifanov's avatar Roman Alifanov

Skip primary-only setup when running as secondary instance

parent f52ae970
package main
import (
"context"
"log"
"os"
"SystemUpdater/backend/eepm"
_ "SystemUpdater/lib/gtks/logging"
"SystemUpdater/lib/i18n"
......@@ -8,8 +12,6 @@ import (
"SystemUpdater/service"
"SystemUpdater/store"
"SystemUpdater/ui"
"log"
"os"
"github.com/diamondburned/gotk4-adwaita/pkg/adw"
"github.com/diamondburned/gotk4/pkg/gio/v2"
......@@ -19,6 +21,42 @@ import (
func main() {
i18n.Init()
app := adw.NewApplication("ru.ximperlinux.SystemUpdater", gio.ApplicationHandlesCommandLine)
// The command-line handler runs in the primary instance. The local
// (secondary) instance only forwards the command line via D-Bus and
// waits for the primary to mark it Done().
app.ConnectCommandLine(func(cmdLine *gio.ApplicationCommandLine) int {
args := cmdLine.Arguments()
background := false
for _, arg := range args {
if arg == "--background" {
background = true
}
}
if !background {
app.Activate()
}
cmdLine.Done()
return 0
})
if err := app.Register(context.Background()); err != nil {
log.Fatalf("Failed to register application: %v", err)
}
if app.IsRemote() {
// Secondary instance: nothing to do locally — app.Run() will
// forward the command line to the primary and exit as soon as
// the primary calls cmdLine.Done().
os.Exit(app.Run(os.Args))
}
// ---- primary-only setup below ----
st := store.NewStore()
defer st.Close()
......@@ -45,8 +83,6 @@ func main() {
}
defer eepmClient.Close()
app := adw.NewApplication("ru.ximperlinux.SystemUpdater", gio.ApplicationHandlesCommandLine)
notificationSvc := service.NewNotificationService(&app.Application.Application)
historySvc := service.NewHistoryService(st, historyFile)
updateSvc := service.NewUpdateService(st, eepmClient, historySvc)
......@@ -71,23 +107,6 @@ func main() {
window.Window.Present()
})
app.ConnectCommandLine(func(cmdLine *gio.ApplicationCommandLine) int {
args := cmdLine.Arguments()
background := false
for _, arg := range args {
if arg == "--background" {
background = true
}
}
if !background {
app.Activate()
}
return 0
})
defer func() {
schedulerSvc.Stop()
log.Println("Application shutdown complete")
......
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