Other: Tidy up app.go a bit

This commit is contained in:
James Houlahan
2022-11-17 13:32:13 +01:00
parent 319d51cb80
commit fe5e8ce7f7

View File

@ -138,6 +138,7 @@ func New() *cli.App { //nolint:funlen
Name: flagParentPID, Name: flagParentPID,
Usage: "Process ID of the parent", Usage: "Process ID of the parent",
Hidden: true, Hidden: true,
Value: -1,
}, },
} }
@ -184,9 +185,11 @@ func run(c *cli.Context) error { //nolint:funlen
return WithLocations(func(locations *locations.Locations) error { return WithLocations(func(locations *locations.Locations) error {
// Initialize logging. // Initialize logging.
return withLogging(c, crashHandler, locations, func() error { return withLogging(c, crashHandler, locations, func() error {
// If there was an error during migration, log it now.
if migrationErr != nil { if migrationErr != nil {
logrus.WithError(migrationErr).Error("Migration failed") logrus.WithError(migrationErr).Error("Failed to migrate old app data")
} }
// Ensure we are the only instance running. // Ensure we are the only instance running.
return withSingleInstance(locations, version, func() error { return withSingleInstance(locations, version, func() error {
// Unlock the encrypted vault. // Unlock the encrypted vault.
@ -194,32 +197,20 @@ func run(c *cli.Context) error { //nolint:funlen
// Load the cookies from the vault. // Load the cookies from the vault.
return withCookieJar(vault, func(cookieJar http.CookieJar) error { return withCookieJar(vault, func(cookieJar http.CookieJar) error {
// Create a new bridge instance. // Create a new bridge instance.
return withBridge( return withBridge(c, exe, locations, version, identifier, crashHandler, reporter, vault, cookieJar, func(b *bridge.Bridge, eventCh <-chan events.Event) error {
c, exe, locations, version, if insecure {
identifier, crashHandler, reporter, logrus.Warn("The vault key could not be retrieved; the vault will not be encrypted")
vault, cookieJar, func( b.PushError(bridge.ErrVaultInsecure)
b *bridge.Bridge, eventCh <-chan events.Event) error { }
if insecure {
logrus.Warn("The vault key could not be retrieved; the vault will not be encrypted")
b.PushError(bridge.ErrVaultInsecure)
}
if corrupt { if corrupt {
logrus.Warn("The vault is corrupt and has been wiped") logrus.Warn("The vault is corrupt and has been wiped")
b.PushError(bridge.ErrVaultCorrupt) b.PushError(bridge.ErrVaultCorrupt)
} }
parentPID := -1 // Run the frontend.
if pid := c.Int(flagParentPID); pid != 0 { return runFrontend(c, crashHandler, restarter, locations, b, eventCh, c.Int(flagParentPID))
parentPID = pid })
}
// Run the frontend.
return runFrontend(c, crashHandler, restarter,
locations, b, eventCh, parentPID,
)
},
)
}) })
}) })
}) })