-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
53 lines (44 loc) · 861 Bytes
/
app.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
package main
import (
"context"
"log"
"github.com/redraskal/putio-desktop/downloads"
)
type App struct {
ctx context.Context
frontend frontend
downloads *downloads.Client
currentPath string
scripts js
}
type frontend interface {
ExecJS(js string)
}
func NewApp() *App {
return &App{}
}
func (b *App) startup(ctx context.Context) {
b.ctx = ctx
if f := ctx.Value("frontend"); f != nil {
b.frontend = f.(frontend)
}
if d, err := downloads.New(downloads.Options{
Path: ".",
MaxConcurrent: 5,
Splits: 5,
}, b.downloadState); err == nil {
b.downloads = d
d.Run()
}
}
func (b *App) domReady(ctx context.Context) {
if !b.requiresRedirect() {
b.injectJS()
}
}
func (b *App) shutdown(ctx context.Context) {
b.downloads.Shutdown()
}
func (b *App) Log(line string) {
log.Printf("[JS] %s", line)
}