diff options
| author | Mitch Riedstra <mitch@riedstra.us> | 2021-08-04 23:53:36 -0400 |
|---|---|---|
| committer | Mitch Riedstra <mitch@riedstra.us> | 2021-08-04 23:53:36 -0400 |
| commit | c202f2eca32e1ab2e313417168351df1c58ee062 (patch) | |
| tree | 6540629b337d2d769581baec26096ac0555f71f9 /cmd/web/app.go | |
| parent | 742938b00222c7ad57ad11eb24850d9202c2503d (diff) | |
| download | steam-export-c202f2eca32e1ab2e313417168351df1c58ee062.tar.gz steam-export-c202f2eca32e1ab2e313417168351df1c58ee062.tar.xz | |
More major changes. Web UI works. Downloading games works. Status works. extractFile needs work
Diffstat (limited to 'cmd/web/app.go')
| -rw-r--r-- | cmd/web/app.go | 80 |
1 files changed, 31 insertions, 49 deletions
diff --git a/cmd/web/app.go b/cmd/web/app.go index 9ab1c0e..578c44d 100644 --- a/cmd/web/app.go +++ b/cmd/web/app.go @@ -1,35 +1,38 @@ package main import ( - "html/template" - "sync" - "time" + "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 -} +// // 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 *steamLib - Status *statusInfo - Demo bool + Library *steam.Library + + // Whether or not we're running in demo mode + Demo bool + + ShareLink string + Version string - Templates *template.Template + templateFS fs.FS + staticFS fs.FS - // Sending to this channel triggers the downloader in the background - download chan string + // download chan string } // NewApp sets up the steam library for us as well as parses the embedded @@ -41,39 +44,18 @@ func NewApp(libPath string) (*App, error) { } a := &App{ - Library: &steamLib{}, - Status: &statusInfo{}, - download: make(chan string), + Library: lib, + Version: Version, + ShareLink: getShareLink(), + // download: make(chan string), + templateFS: TemplateFS, + staticFS: StaticFS, } - a.Library.Library = *lib - - a.Templates = template.Must(template.New("index").Parse(indexTemplate)) - return a, nil } -// LibrarySet takes care of locking the Library and switching over to a new -// path, unlocking when done. -// Errors will be logged and no changes will be made if unsuccessful. -func (a *App) LibrarySet(path string) { - Logger.Println("Starting library reload") - a.Library.Lock() - defer a.Library.Unlock() - var err error - l2, err := steam.NewLibrary(path) - if err != nil { - Logger.Printf("Error reopening lib: %s", err) - return - } - a.Library.Library = *l2 - Logger.Println("Done reloading lib") -} - -// LibraryReload calls LibrarySet but with the current directory, forcing a -// reload of information off of disk. -func (a *App) LibraryReload() { - cur := a.Library.Folder - a.LibrarySet(cur) - return +func (a *App) useLocalFS(pth string) { + a.templateFS = os.DirFS(pth) + a.staticFS = a.templateFS } |
