-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
93 lines (80 loc) · 1.87 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
package main
import (
"embed"
"fmt"
"log"
"net/http"
"os"
"strings"
"browser-profile-launcher/profile"
"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/logger"
"github.com/wailsapp/wails/v2/pkg/options"
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
)
//go:embed all:frontend/dist
var assets embed.FS
type IcoLoader struct {
http.Handler
}
func NewIcoLoader() *IcoLoader {
return &IcoLoader{}
}
func (h *IcoLoader) ServeHTTP(res http.ResponseWriter, req *http.Request) {
var err error
if !strings.HasSuffix(req.URL.Path, ".ico") {
return
}
if req.URL.Path == "/favicon.ico" {
return
}
log.Println("Req: ", req.URL.Path)
query := req.URL.Query()
browser := query.Get("browser")
directory := query.Get("directory")
var filePath string
for _, p := range profile.List() {
if p.Browser == browser && p.Directory == directory {
filePath = p.IcoPath
break
}
}
if filePath == "" {
res.WriteHeader(http.StatusNotFound)
}
fileData, err := os.ReadFile(filePath)
if err != nil {
res.WriteHeader(http.StatusBadRequest)
res.Write([]byte(fmt.Sprintf("Could not load file %s", req.URL)))
}
res.Write(fileData)
}
func main() {
app := NewApp()
err := wails.Run(&options.App{
Title: "Browser Profile Launcher",
Width: 420,
Height: 580,
AssetServer: &assetserver.Options{
Assets: assets,
Handler: NewIcoLoader(),
},
Logger: logger.NewFileLogger("browser-profile-launcher.log"),
LogLevel: logger.DEBUG,
LogLevelProduction: logger.ERROR,
SingleInstanceLock: &options.SingleInstanceLock{
UniqueId: "3ebf5e8f-9955-4a4d-8865-d10f4de79392",
OnSecondInstanceLaunch: app.OnSecondInstanceLaunch,
},
Debug: options.Debug{
OpenInspectorOnStartup: true,
},
OnStartup: app.startup,
Bind: []interface{}{
app,
},
})
if err != nil {
println("Error:", err.Error())
}
}