Skip to content

Commit 0343ded

Browse files
committed
refactor: save config if valid, abort on invalid config in startup
1 parent 2f226a4 commit 0343ded

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

cmd/vinegar/app.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ func newApp() *app {
4242
// an effective wrapper for Studio arguments.
4343
gio.GApplicationHandlesCommandLineValue,
4444
),
45-
cfg: config.Default(),
4645
rbx: rbxweb.NewClient(),
4746
}
4847

@@ -57,8 +56,6 @@ func newApp() *app {
5756
}
5857

5958
func (a *app) reload() error {
60-
slog.Info("Reloading!")
61-
6259
pfx, err := a.cfg.Prefix()
6360
if err != nil {
6461
return fmt.Errorf("prefix configure: %w", err)
@@ -92,19 +89,18 @@ func (a *app) startup(_ gio.Application) {
9289
cfg, err := config.Load()
9390
if err != nil {
9491
a.showError(fmt.Errorf("config error: %w", err))
95-
} else {
96-
a.cfg = cfg
92+
return
9793
}
94+
a.cfg = cfg
9895

9996
if err := a.reload(); err != nil {
10097
a.showError(err)
10198
}
10299
}
103100

104101
func (a *app) commandLine(_ gio.Application, clPtr uintptr) int {
105-
if a.keepLog {
106-
// Error dialog is open currently
107-
return 0
102+
if a.cfg == nil || a.pfx == nil {
103+
return 1
108104
}
109105

110106
cl := gio.ApplicationCommandLineNewFromInternalPtr(clPtr)

cmd/vinegar/manager_actions.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,12 @@ func (m *manager) saveConfig() {
6262
m.builder.GetObject("banner-config-error").Cast(&banner)
6363
banner.SetRevealed(false)
6464

65-
if err := m.cfg.Save(); err != nil {
66-
m.showError(err)
67-
return
68-
}
69-
7065
err := m.reload()
7166
if err == nil {
67+
slog.Info("Saving configuration!")
68+
if err := m.cfg.Save(); err != nil {
69+
m.showError(fmt.Errorf("save config: %w", err))
70+
}
7271
return
7372
}
7473

0 commit comments

Comments
 (0)