-
Notifications
You must be signed in to change notification settings - Fork 4
/
state.go
60 lines (51 loc) · 1.31 KB
/
state.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Content managed by Project Forge, see [projectforge.md] for details.
package app
import (
"context"
"fmt"
"time"
"projectforge.dev/projectforge/app/lib/filesystem"
"projectforge.dev/projectforge/app/lib/telemetry"
"projectforge.dev/projectforge/app/lib/theme"
"projectforge.dev/projectforge/app/util"
)
type BuildInfo struct {
Version string `json:"version"`
Commit string `json:"commit"`
Date string `json:"date"`
}
func (b *BuildInfo) String() string {
if b.Date == "unknown" {
} else {
d, _ := util.TimeFromJS(b.Date)
return fmt.Sprintf("%s (%s)", b.Version, util.TimeToYMD(d))
}
return b.Version
}
type State struct {
Debug bool
BuildInfo *BuildInfo
Files filesystem.FileLoader
Themes *theme.Service
Services *Services
Started time.Time
}
func (s State) Close(ctx context.Context, logger util.Logger) error {
return s.Services.Close(ctx, logger)
}
func NewState(debug bool, bi *BuildInfo, f filesystem.FileLoader, enableTelemetry bool, logger util.Logger) (*State, error) {
loc, err := time.LoadLocation("UTC")
if err != nil {
return nil, err
}
time.Local = loc
_ = telemetry.InitializeIfNeeded(enableTelemetry, bi.Version, logger)
ts := theme.NewService(f)
return &State{
Debug: debug,
BuildInfo: bi,
Files: f,
Themes: ts,
Started: time.Now(),
}, nil
}