-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
115 lines (104 loc) · 2.79 KB
/
main.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package main
import (
"embed"
"fmt"
"io"
"io/fs"
"log"
"os"
"path/filepath"
"time"
"github.com/kettek/staxie/pkg/data"
"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/options"
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
"github.com/wailsapp/wails/v2/pkg/options/linux"
"github.com/wailsapp/wails/v2/pkg/options/windows"
)
//go:embed build/appicon.png
//go:embed all:frontend/dist
var assets embed.FS
func main() {
// Set logging to output to both a file and stdout.
if err := os.MkdirAll(filepath.Join(data.AppDirectory, "logs"), 0755); err != nil {
log.Println("Error creating log directory:", err)
} else {
// Clear out log files older than 7 days.
if filepath.WalkDir(filepath.Join(data.AppDirectory, "logs"), func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() {
return nil
}
info, err := d.Info()
if err != nil {
return err
}
if time.Since(info.ModTime()) > 7*24*time.Hour {
if err := os.Remove(path); err != nil {
log.Println("Error removing log file:", err)
}
}
return nil
}); err != nil {
log.Println("Error cleaning up log files:", err)
}
writer1 := os.Stdout
date := time.Now().Unix()
writer2, err := os.Create(filepath.Join(data.AppDirectory, "logs", fmt.Sprintf("%d.log", date)))
if err != nil {
log.Println("Error creating log file:", err)
} else {
log.SetOutput(io.MultiWriter(writer1, writer2))
}
}
// Read in sprite's bytes.
spriteBytes, err := assets.ReadFile("build/appicon.png")
if err != nil {
log.Println("Error reading sprite:", err)
}
log.Println("Starting Staxie...")
// Load settings.
log.Println("Loading settings...")
if err := data.LoadSettings(data.SettingsStore{
"Windowing": data.DefaultWindowing,
}); err != nil {
fmt.Println("Error loading settings:", err)
}
windowSettings := data.WindowingFromAny(data.Settings["Windowing"])
windowStartState := options.Normal
if *windowSettings.Maximized {
windowStartState = options.Maximised
} else if *windowSettings.Minimized {
windowStartState = options.Minimised
} else if *windowSettings.Fullscreen {
windowStartState = options.Fullscreen
}
// Create an instance of the app structure
app := NewApp()
// Create application with options
log.Println("Running Wails...")
if err := wails.Run(&options.App{
Title: "Staxie",
Width: *windowSettings.Width,
Height: *windowSettings.Height,
AssetServer: &assetserver.Options{
Assets: assets,
},
WindowStartState: windowStartState,
BackgroundColour: &options.RGBA{R: 27, G: 38, B: 54, A: 1},
OnStartup: app.startup,
Bind: []interface{}{
app,
},
Linux: &linux.Options{
Icon: spriteBytes,
},
Windows: &windows.Options{
ZoomFactor: 1.0,
},
}); err != nil {
log.Println(err)
}
}