aboutsummaryrefslogtreecommitdiff
path: root/cmd/web/app.go
blob: 578c44d73221c25eca69836423d8ba1814d9674f (plain) (blame)
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
61
package main

import (
	"io/fs"
	"os"

	"riedstra.dev/mitch/steam-export/steam"
)

// // statusInfo represents the internal status of game installation
// type statusInfo struct {
// 	sync.RWMutex
// 	Running     bool
// 	Error       error
// 	Url         string
// 	Transferred int64
// 	Size        int64
// 	Start       *time.Time
// }

// App binds together the steam library, templates, and channel for install
// requests as well as most the app specific http handlers.
type App struct {
	Library *steam.Library

	// Whether or not we're running in demo mode
	Demo bool

	ShareLink string
	Version   string

	templateFS fs.FS
	staticFS   fs.FS

	// download chan string
}

// NewApp sets up the steam library for us as well as parses the embedded
// template
func NewApp(libPath string) (*App, error) {
	lib, err := steam.NewLibrary(libPath)
	if err != nil {
		return nil, err
	}

	a := &App{
		Library:   lib,
		Version:   Version,
		ShareLink: getShareLink(),
		// download:  make(chan string),
		templateFS: TemplateFS,
		staticFS:   StaticFS,
	}

	return a, nil
}

func (a *App) useLocalFS(pth string) {
	a.templateFS = os.DirFS(pth)
	a.staticFS = a.templateFS
}