5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-21 19:39:29 +08:00

[v3 linux] initial pass at event generation

This commit is contained in:
Travis McLane 2023-11-03 17:59:57 -05:00
parent a773da2651
commit ca21a3b79d
3 changed files with 47 additions and 1 deletions

View File

@ -53,6 +53,18 @@ func newCommonEvents() commonEvents {
} }
} }
var Linux = newLinuxEvents()
type linuxEvents struct {
SystemThemeChanged ApplicationEventType
}
func newLinuxEvents() linuxEvents {
return linuxEvents{
SystemThemeChanged: 1193,
}
}
var Mac = newMacEvents() var Mac = newMacEvents()
type macEvents struct { type macEvents struct {
@ -545,4 +557,5 @@ var eventToJS = map[uint]string{
1190: "common:WindowDPIChanged", 1190: "common:WindowDPIChanged",
1191: "common:WindowFilesDropped", 1191: "common:WindowFilesDropped",
1192: "common:ThemeChanged", 1192: "common:ThemeChanged",
1193: "linux:SystemThemeChanged",
} }

View File

@ -1,3 +1,4 @@
linux:SystemThemeChanged
mac:ApplicationDidBecomeActive mac:ApplicationDidBecomeActive
mac:ApplicationDidChangeBackingProperties mac:ApplicationDidChangeBackingProperties
mac:ApplicationDidChangeEffectiveAppearance mac:ApplicationDidChangeEffectiveAppearance
@ -167,3 +168,4 @@ common:WindowHide
common:WindowDPIChanged common:WindowDPIChanged
common:WindowFilesDropped common:WindowFilesDropped
common:ThemeChanged common:ThemeChanged

View File

@ -22,6 +22,16 @@ func newCommonEvents() commonEvents {
$$COMMONEVENTSVALUES } $$COMMONEVENTSVALUES }
} }
var Linux = newLinuxEvents()
type linuxEvents struct {
$$LINUXEVENTSDECL}
func newLinuxEvents() linuxEvents {
return linuxEvents{
$$LINUXEVENTSVALUES }
}
var Mac = newMacEvents() var Mac = newMacEvents()
type macEvents struct { type macEvents struct {
@ -81,6 +91,9 @@ func main() {
panic(err) panic(err)
} }
linuxEventsDecl := bytes.NewBufferString("")
linuxEventsValues := bytes.NewBufferString("")
macEventsDecl := bytes.NewBufferString("") macEventsDecl := bytes.NewBufferString("")
macEventsValues := bytes.NewBufferString("") macEventsValues := bytes.NewBufferString("")
cHeaderEvents := bytes.NewBufferString("") cHeaderEvents := bytes.NewBufferString("")
@ -94,6 +107,7 @@ func main() {
commonEventsDecl := bytes.NewBufferString("") commonEventsDecl := bytes.NewBufferString("")
commonEventsValues := bytes.NewBufferString("") commonEventsValues := bytes.NewBufferString("")
linuxJSEvents := bytes.NewBufferString("")
macJSEvents := bytes.NewBufferString("") macJSEvents := bytes.NewBufferString("")
windowsJSEvents := bytes.NewBufferString("") windowsJSEvents := bytes.NewBufferString("")
commonJSEvents := bytes.NewBufferString("") commonJSEvents := bytes.NewBufferString("")
@ -101,6 +115,7 @@ func main() {
eventToJS := bytes.NewBufferString("") eventToJS := bytes.NewBufferString("")
var id int var id int
// var maxLinuxEvents int
var maxMacEvents int var maxMacEvents int
var line []byte var line []byte
// Loop over each line in the file // Loop over each line in the file
@ -131,6 +146,19 @@ func main() {
// Add to buffer // Add to buffer
switch platform { switch platform {
case "linux":
eventType := "ApplicationEventType"
if strings.HasPrefix(event, "Window") {
eventType = "WindowEventType"
}
if strings.HasPrefix(event, "WebView") {
eventType = "WindowEventType"
}
linuxEventsDecl.WriteString("\t" + eventTitle + " " + eventType + "\n")
linuxEventsValues.WriteString("\t\t" + event + ": " + strconv.Itoa(id) + ",\n")
linuxJSEvents.WriteString("\t\t" + event + ": \"" + strings.TrimSpace(string(line)) + "\",\n")
eventToJS.WriteString("\t" + strconv.Itoa(id) + ": \"" + strings.TrimSpace(string(line)) + "\",\n")
//maxLinuxEvents = id
case "mac": case "mac":
eventType := "ApplicationEventType" eventType := "ApplicationEventType"
if strings.HasPrefix(event, "Window") { if strings.HasPrefix(event, "Window") {
@ -209,8 +237,11 @@ func main() {
cHeaderEvents.WriteString("\n#define MAX_EVENTS " + strconv.Itoa(maxMacEvents+1) + "\n") cHeaderEvents.WriteString("\n#define MAX_EVENTS " + strconv.Itoa(maxMacEvents+1) + "\n")
// Save the eventsGo template substituting the values and decls // Save the eventsGo template substituting the values and decls
templateToWrite := strings.ReplaceAll(eventsGo, "$$MACEVENTSDECL", macEventsDecl.String()) templateToWrite := strings.ReplaceAll(eventsGo, "$$LINUXEVENTSDECL", linuxEventsDecl.String())
templateToWrite = strings.ReplaceAll(templateToWrite, "$$LINUXEVENTSVALUES", linuxEventsValues.String())
templateToWrite = strings.ReplaceAll(templateToWrite, "$$MACEVENTSDECL", macEventsDecl.String())
templateToWrite = strings.ReplaceAll(templateToWrite, "$$MACEVENTSVALUES", macEventsValues.String()) templateToWrite = strings.ReplaceAll(templateToWrite, "$$MACEVENTSVALUES", macEventsValues.String())
templateToWrite = strings.ReplaceAll(templateToWrite, "$$WINDOWSEVENTSDECL", windowsEventsDecl.String()) templateToWrite = strings.ReplaceAll(templateToWrite, "$$WINDOWSEVENTSDECL", windowsEventsDecl.String())
templateToWrite = strings.ReplaceAll(templateToWrite, "$$WINDOWSEVENTSVALUES", windowsEventsValues.String()) templateToWrite = strings.ReplaceAll(templateToWrite, "$$WINDOWSEVENTSVALUES", windowsEventsValues.String())
templateToWrite = strings.ReplaceAll(templateToWrite, "$$COMMONEVENTSDECL", commonEventsDecl.String()) templateToWrite = strings.ReplaceAll(templateToWrite, "$$COMMONEVENTSDECL", commonEventsDecl.String())