-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
104 lines (92 loc) · 2.63 KB
/
main.go
File metadata and controls
104 lines (92 loc) · 2.63 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"
"net/http"
"strings"
"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/menu"
"github.com/wailsapp/wails/v2/pkg/menu/keys"
"github.com/wailsapp/wails/v2/pkg/options"
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
macopts "github.com/wailsapp/wails/v2/pkg/options/mac"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
//go:embed all:frontend/dist
var assets embed.FS
// AssetHandler serves both embedded assets and media files
type AssetHandler struct {
mediaServer http.Handler
}
func (h *AssetHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Route /media/* requests to the media server
if strings.HasPrefix(r.URL.Path, "/media/") {
h.mediaServer.ServeHTTP(w, r)
return
}
// All other requests return 404 (will be handled by embedded assets)
http.NotFound(w, r)
}
func main() {
// Create an instance of the app structure
app := NewApp()
// Create asset handler with media server
assetHandler := &AssetHandler{
mediaServer: app.mediaServer,
}
// Create application menu by extending the defaults
appMenu := menu.NewMenu()
appMenu.Append(menu.AppMenu())
appMenu.Append(menu.EditMenu())
// Custom window menu retains core controls and adds Cmd+W close shortcut
windowMenu := appMenu.AddSubmenu("Window")
windowMenu.AddText("Minimize", keys.CmdOrCtrl("m"), func(cd *menu.CallbackData) {
if app.ctx != nil {
runtime.WindowMinimise(app.ctx)
}
})
windowMenu.AddText("Zoom", nil, func(cd *menu.CallbackData) {
if app.ctx != nil {
runtime.WindowToggleMaximise(app.ctx)
}
})
windowMenu.AddSeparator()
windowMenu.AddText("Close Window", keys.CmdOrCtrl("w"), func(cd *menu.CallbackData) {
if app.ctx != nil {
runtime.Quit(app.ctx)
}
})
// Create application with options
err := wails.Run(&options.App{
Title: "transcube-webapp",
Width: 1024,
Height: 768,
AssetServer: &assetserver.Options{
Assets: assets,
Handler: assetHandler,
},
BackgroundColour: &options.RGBA{R: 255, G: 255, B: 255, A: 1},
OnStartup: app.startup,
Menu: appMenu,
Mac: &macopts.Options{
TitleBar: &macopts.TitleBar{
TitlebarAppearsTransparent: false,
FullSizeContent: false,
UseToolbar: false,
HideTitle: false,
},
Appearance: macopts.NSAppearanceNameAqua,
WebviewIsTransparent: false,
WindowIsTranslucent: false,
Preferences: &macopts.Preferences{
// Enable DOM Element Fullscreen API in WKWebView (macOS 12.3+)
FullscreenEnabled: macopts.Enabled,
},
},
Bind: []interface{}{
app,
},
})
if err != nil {
println("Error:", err.Error())
}
}