-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
104 lines (91 loc) · 2.41 KB
/
main.go
File metadata and controls
104 lines (91 loc) · 2.41 KB
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
package main
import (
"embed"
"log"
"mime"
"net/http"
"os"
"path/filepath"
"gvnotes/internal/config"
"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/mac"
"github.com/wailsapp/wails/v2/pkg/options/windows"
)
//go:embed all:frontend/dist
var assets embed.FS
//go:embed db/migrations
var migrations embed.FS
// imageFileHandler serves image files stored on disk under imagesDir.
// Only the base filename is used to prevent path traversal.
type imageFileHandler struct {
imagesDir string
}
func (h *imageFileHandler) ServeHTTP(res http.ResponseWriter, req *http.Request) {
filename := filepath.Base(req.URL.Path)
fullPath := filepath.Join(h.imagesDir, filename)
data, err := os.ReadFile(fullPath)
if err != nil {
http.NotFound(res, req)
return
}
ct := mime.TypeByExtension(filepath.Ext(filename))
if ct == "" {
ct = "application/octet-stream"
}
res.Header().Set("Content-Type", ct)
res.Write(data)
}
func main() {
appMigrations = migrations
imagesDir, err := config.ImagesDir()
if err != nil {
log.Fatalf("failed to resolve images directory: %v", err)
}
app := NewApp()
err = wails.Run(&options.App{
Title: "GVNotes",
Width: 1600,
Height: 1200,
MinWidth: 533,
MinHeight: 400,
HideWindowOnClose: true,
EnableDefaultContextMenu: true,
BackgroundColour: &options.RGBA{R: 34, G: 37, B: 49, A: 1},
OnStartup: app.startup,
OnShutdown: app.shutdown,
CSSDragProperty: "--wails-draggable",
CSSDragValue: "drag",
AssetServer: &assetserver.Options{
Assets: assets,
Handler: &imageFileHandler{imagesDir: imagesDir},
},
Windows: &windows.Options{
WebviewIsTransparent: true,
WindowIsTranslucent: true,
CustomTheme: &windows.ThemeSettings{
DarkModeTitleBar: windows.RGB(34, 37, 49),
DarkModeBorder: windows.RGB(34, 37, 49),
},
},
Mac: &mac.Options{
TitleBar: &mac.TitleBar{
TitlebarAppearsTransparent: true,
HideTitle: true,
UseToolbar: true,
HideToolbarSeparator: false,
},
About: &mac.AboutInfo{
Title: "GVNotes",
Message: "© 2026 Guillermo Valentín",
},
},
Bind: []interface{}{
app,
},
})
if err != nil {
println("Error:", err.Error())
}
}