-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.go
More file actions
115 lines (99 loc) · 3.44 KB
/
main.go
File metadata and controls
115 lines (99 loc) · 3.44 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
105
106
107
108
109
110
111
112
113
114
115
package main
import (
"embed"
_ "embed"
"iOSGhostRun/services"
"log"
"log/slog"
"sync/atomic"
"github.com/wailsapp/wails/v3/pkg/application"
"github.com/wailsapp/wails/v3/pkg/events"
)
//go:embed all:frontend/dist
var assets embed.FS
//go:embed build/appicon.png
var icon []byte
func init() {
// Register a custom event whose associated data type is string.
// This is not required, but the binding generator will pick up registered events
// and provide a strongly typed JS/TS API for them.
application.RegisterEvent[string]("time")
application.RegisterEvent[string]("developer-mode-menu-revealed")
}
// main function serves as the application's entry point. It initializes the application, creates a window,
// and starts a goroutine that emits a time-based event every second. It subsequently runs the application and
// logs any error that might occur.
func main() {
// Create a new Wails application by providing the necessary options.
// Variables 'Name' and 'Description' are for application metadata.
// 'Assets' configures the asset server with the 'FS' variable pointing to the frontend files.
// 'Bind' is a list of Go struct instances. The frontend has access to the methods of these instances.
// 'Mac' options tailor the application when running an macOS.
// 创建服务实例
loggerSvc := services.NewLoggerService()
devicesSvc := services.NewDevicesService()
locationSvc := services.NewLocationService()
runningSvc := services.NewRunningService(locationSvc)
app := application.New(application.Options{
Name: "iOSGhostRun",
Description: "iOS虚拟定位跑步应用",
LogLevel: slog.LevelInfo,
Services: []application.Service{
application.NewService(loggerSvc),
application.NewService(devicesSvc),
application.NewService(locationSvc),
application.NewService(runningSvc),
},
Assets: application.AssetOptions{
Handler: application.AssetFileServerFS(assets),
},
Mac: application.MacOptions{
ApplicationShouldTerminateAfterLastWindowClosed: true,
},
Windows: application.WindowsOptions{DisableQuitOnLastWindowClosed: false},
})
app.SetIcon(icon)
var allowQuit atomic.Bool
// Create a new window with the necessary options.
// 'Title' is the title of the window.
// 'Mac' options tailor the window when running on macOS.
// 'BackgroundColour' is the background colour of the window.
// 'URL' is the URL that will be loaded into the webview.
window := app.Window.NewWithOptions(application.WebviewWindowOptions{
Title: "iOS虚拟定位跑步",
Width: 800, Height: 600,
Frameless: true,
BackgroundColour: application.NewRGBA(27, 38, 54, 230),
Mac: application.MacWindow{
Backdrop: application.MacBackdropTransparent,
TitleBar: application.MacTitleBarHidden,
},
URL: "/",
})
window.OnWindowEvent(events.Common.WindowClosing, func(event *application.WindowEvent) {
if allowQuit.Load() {
return
}
event.Cancel()
app.Event.Emit("app:close-requested")
})
app.Event.On("app:close-quit", func(_ *application.CustomEvent) {
if allowQuit.Load() {
return
}
services.SetAppShuttingDown(true)
allowQuit.Store(true)
runningSvc.StopRun()
devInfo, err := devicesSvc.GetSelectedDevice()
if err == nil {
_ = services.UnmountImage(devInfo.UDID)
}
window.Close()
})
// Run the application. This blocks until the application has been exited.
err := app.Run()
// If an error occurred while running the application, log it and exit.
if err != nil {
log.Fatal(err)
}
}