[darwin] add support for quitting app

This commit is contained in:
Lea Anthony
2024-01-08 21:22:33 +11:00
parent df0419a7d6
commit 68e779d64e
8 changed files with 552 additions and 488 deletions
+5
View File
@@ -42,3 +42,8 @@ tasks:
- install-deps
cmds:
- task: build:all
generate:events:
dir: ../../tasks/events
cmds:
- go run generate.go
+5
View File
@@ -122,6 +122,11 @@ func New(appOptions Options) *App {
result.keyBindings = processKeyBindingOptions(result.options.KeyBindings)
}
// Handle the terminate event
result.On(events.Common.ApplicationTerminate, func(e *Event) {
result.Quit()
})
return result
}
@@ -1,6 +1,7 @@
//go:build darwin
#import "application_darwin_delegate.h"
#import "../events/events_darwin.h"
#import "message.h"
extern bool hasListeners(unsigned int);
@implementation AppDelegate
- (void)dealloc
@@ -17,7 +18,10 @@ extern bool hasListeners(unsigned int);
processApplicationEvent(EventApplicationDidChangeTheme, NULL);
}
}
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender {
processApplicationEvent(EventApplicationTerminate, NULL);
return NSTerminateCancel;
}
- (BOOL)applicationSupportsSecureRestorableState:(NSApplication *)app
{
return YES;
@@ -152,5 +156,11 @@ extern bool hasListeners(unsigned int);
}
}
- (void)applicationTerminate:(NSNotification *)notification {
if( hasListeners(EventApplicationTerminate) ) {
processApplicationEvent(EventApplicationTerminate, NULL);
}
}
// GENERATED EVENTS END
@end
@@ -7,6 +7,7 @@ import "github.com/wailsapp/wails/v3/pkg/events"
var commonApplicationEventMap = map[events.ApplicationEventType]events.ApplicationEventType{
events.Mac.ApplicationDidFinishLaunching: events.Common.ApplicationStarted,
events.Mac.ApplicationDidChangeTheme: events.Common.ThemeChanged,
events.Mac.ApplicationTerminate: events.Common.ApplicationTerminate,
}
func (m *macosApp) setupCommonEvents() {
+366 -360
View File
File diff suppressed because it is too large Load Diff
+126 -125
View File
@@ -6,132 +6,133 @@
extern void processApplicationEvent(unsigned int, void* data);
extern void processWindowEvent(unsigned int, unsigned int);
#define EventApplicationDidBecomeActive 1024
#define EventApplicationDidChangeBackingProperties 1025
#define EventApplicationDidChangeEffectiveAppearance 1026
#define EventApplicationDidChangeIcon 1027
#define EventApplicationDidChangeOcclusionState 1028
#define EventApplicationDidChangeScreenParameters 1029
#define EventApplicationDidChangeStatusBarFrame 1030
#define EventApplicationDidChangeStatusBarOrientation 1031
#define EventApplicationDidFinishLaunching 1032
#define EventApplicationDidHide 1033
#define EventApplicationDidResignActiveNotification 1034
#define EventApplicationDidUnhide 1035
#define EventApplicationDidUpdate 1036
#define EventApplicationWillBecomeActive 1037
#define EventApplicationWillFinishLaunching 1038
#define EventApplicationWillHide 1039
#define EventApplicationWillResignActive 1040
#define EventApplicationWillTerminate 1041
#define EventApplicationWillUnhide 1042
#define EventApplicationWillUpdate 1043
#define EventApplicationDidChangeTheme 1044
#define EventApplicationShouldHandleReopen 1045
#define EventWindowDidBecomeKey 1046
#define EventWindowDidBecomeMain 1047
#define EventWindowDidBeginSheet 1048
#define EventWindowDidChangeAlpha 1049
#define EventWindowDidChangeBackingLocation 1050
#define EventWindowDidChangeBackingProperties 1051
#define EventWindowDidChangeCollectionBehavior 1052
#define EventWindowDidChangeEffectiveAppearance 1053
#define EventWindowDidChangeOcclusionState 1054
#define EventWindowDidChangeOrderingMode 1055
#define EventWindowDidChangeScreen 1056
#define EventWindowDidChangeScreenParameters 1057
#define EventWindowDidChangeScreenProfile 1058
#define EventWindowDidChangeScreenSpace 1059
#define EventWindowDidChangeScreenSpaceProperties 1060
#define EventWindowDidChangeSharingType 1061
#define EventWindowDidChangeSpace 1062
#define EventWindowDidChangeSpaceOrderingMode 1063
#define EventWindowDidChangeTitle 1064
#define EventWindowDidChangeToolbar 1065
#define EventWindowDidChangeVisibility 1066
#define EventWindowDidDeminiaturize 1067
#define EventWindowDidEndSheet 1068
#define EventWindowDidEnterFullScreen 1069
#define EventWindowDidEnterVersionBrowser 1070
#define EventWindowDidExitFullScreen 1071
#define EventWindowDidExitVersionBrowser 1072
#define EventWindowDidExpose 1073
#define EventWindowDidFocus 1074
#define EventWindowDidMiniaturize 1075
#define EventWindowDidMove 1076
#define EventWindowDidOrderOffScreen 1077
#define EventWindowDidOrderOnScreen 1078
#define EventWindowDidResignKey 1079
#define EventWindowDidResignMain 1080
#define EventWindowDidResize 1081
#define EventWindowDidUpdate 1082
#define EventWindowDidUpdateAlpha 1083
#define EventWindowDidUpdateCollectionBehavior 1084
#define EventWindowDidUpdateCollectionProperties 1085
#define EventWindowDidUpdateShadow 1086
#define EventWindowDidUpdateTitle 1087
#define EventWindowDidUpdateToolbar 1088
#define EventWindowDidUpdateVisibility 1089
#define EventWindowShouldClose 1090
#define EventWindowWillBecomeKey 1091
#define EventWindowWillBecomeMain 1092
#define EventWindowWillBeginSheet 1093
#define EventWindowWillChangeOrderingMode 1094
#define EventWindowWillClose 1095
#define EventWindowWillDeminiaturize 1096
#define EventWindowWillEnterFullScreen 1097
#define EventWindowWillEnterVersionBrowser 1098
#define EventWindowWillExitFullScreen 1099
#define EventWindowWillExitVersionBrowser 1100
#define EventWindowWillFocus 1101
#define EventWindowWillMiniaturize 1102
#define EventWindowWillMove 1103
#define EventWindowWillOrderOffScreen 1104
#define EventWindowWillOrderOnScreen 1105
#define EventWindowWillResignMain 1106
#define EventWindowWillResize 1107
#define EventWindowWillUnfocus 1108
#define EventWindowWillUpdate 1109
#define EventWindowWillUpdateAlpha 1110
#define EventWindowWillUpdateCollectionBehavior 1111
#define EventWindowWillUpdateCollectionProperties 1112
#define EventWindowWillUpdateShadow 1113
#define EventWindowWillUpdateTitle 1114
#define EventWindowWillUpdateToolbar 1115
#define EventWindowWillUpdateVisibility 1116
#define EventWindowWillUseStandardFrame 1117
#define EventMenuWillOpen 1118
#define EventMenuDidOpen 1119
#define EventMenuDidClose 1120
#define EventMenuWillSendAction 1121
#define EventMenuDidSendAction 1122
#define EventMenuWillHighlightItem 1123
#define EventMenuDidHighlightItem 1124
#define EventMenuWillDisplayItem 1125
#define EventMenuDidDisplayItem 1126
#define EventMenuWillAddItem 1127
#define EventMenuDidAddItem 1128
#define EventMenuWillRemoveItem 1129
#define EventMenuDidRemoveItem 1130
#define EventMenuWillBeginTracking 1131
#define EventMenuDidBeginTracking 1132
#define EventMenuWillEndTracking 1133
#define EventMenuDidEndTracking 1134
#define EventMenuWillUpdate 1135
#define EventMenuDidUpdate 1136
#define EventMenuWillPopUp 1137
#define EventMenuDidPopUp 1138
#define EventMenuWillSendActionToItem 1139
#define EventMenuDidSendActionToItem 1140
#define EventWebViewDidStartProvisionalNavigation 1141
#define EventWebViewDidReceiveServerRedirectForProvisionalNavigation 1142
#define EventWebViewDidFinishNavigation 1143
#define EventWebViewDidCommitNavigation 1144
#define EventWindowFileDraggingEntered 1145
#define EventWindowFileDraggingPerformed 1146
#define EventWindowFileDraggingExited 1147
#define EventApplicationDidBecomeActive 1025
#define EventApplicationDidChangeBackingProperties 1026
#define EventApplicationDidChangeEffectiveAppearance 1027
#define EventApplicationDidChangeIcon 1028
#define EventApplicationDidChangeOcclusionState 1029
#define EventApplicationDidChangeScreenParameters 1030
#define EventApplicationDidChangeStatusBarFrame 1031
#define EventApplicationDidChangeStatusBarOrientation 1032
#define EventApplicationDidFinishLaunching 1033
#define EventApplicationDidHide 1034
#define EventApplicationDidResignActiveNotification 1035
#define EventApplicationDidUnhide 1036
#define EventApplicationDidUpdate 1037
#define EventApplicationWillBecomeActive 1038
#define EventApplicationWillFinishLaunching 1039
#define EventApplicationWillHide 1040
#define EventApplicationWillResignActive 1041
#define EventApplicationWillTerminate 1042
#define EventApplicationWillUnhide 1043
#define EventApplicationWillUpdate 1044
#define EventApplicationTerminate 1045
#define EventApplicationDidChangeTheme 1046
#define EventApplicationShouldHandleReopen 1047
#define EventWindowDidBecomeKey 1048
#define EventWindowDidBecomeMain 1049
#define EventWindowDidBeginSheet 1050
#define EventWindowDidChangeAlpha 1051
#define EventWindowDidChangeBackingLocation 1052
#define EventWindowDidChangeBackingProperties 1053
#define EventWindowDidChangeCollectionBehavior 1054
#define EventWindowDidChangeEffectiveAppearance 1055
#define EventWindowDidChangeOcclusionState 1056
#define EventWindowDidChangeOrderingMode 1057
#define EventWindowDidChangeScreen 1058
#define EventWindowDidChangeScreenParameters 1059
#define EventWindowDidChangeScreenProfile 1060
#define EventWindowDidChangeScreenSpace 1061
#define EventWindowDidChangeScreenSpaceProperties 1062
#define EventWindowDidChangeSharingType 1063
#define EventWindowDidChangeSpace 1064
#define EventWindowDidChangeSpaceOrderingMode 1065
#define EventWindowDidChangeTitle 1066
#define EventWindowDidChangeToolbar 1067
#define EventWindowDidChangeVisibility 1068
#define EventWindowDidDeminiaturize 1069
#define EventWindowDidEndSheet 1070
#define EventWindowDidEnterFullScreen 1071
#define EventWindowDidEnterVersionBrowser 1072
#define EventWindowDidExitFullScreen 1073
#define EventWindowDidExitVersionBrowser 1074
#define EventWindowDidExpose 1075
#define EventWindowDidFocus 1076
#define EventWindowDidMiniaturize 1077
#define EventWindowDidMove 1078
#define EventWindowDidOrderOffScreen 1079
#define EventWindowDidOrderOnScreen 1080
#define EventWindowDidResignKey 1081
#define EventWindowDidResignMain 1082
#define EventWindowDidResize 1083
#define EventWindowDidUpdate 1084
#define EventWindowDidUpdateAlpha 1085
#define EventWindowDidUpdateCollectionBehavior 1086
#define EventWindowDidUpdateCollectionProperties 1087
#define EventWindowDidUpdateShadow 1088
#define EventWindowDidUpdateTitle 1089
#define EventWindowDidUpdateToolbar 1090
#define EventWindowDidUpdateVisibility 1091
#define EventWindowShouldClose 1092
#define EventWindowWillBecomeKey 1093
#define EventWindowWillBecomeMain 1094
#define EventWindowWillBeginSheet 1095
#define EventWindowWillChangeOrderingMode 1096
#define EventWindowWillClose 1097
#define EventWindowWillDeminiaturize 1098
#define EventWindowWillEnterFullScreen 1099
#define EventWindowWillEnterVersionBrowser 1100
#define EventWindowWillExitFullScreen 1101
#define EventWindowWillExitVersionBrowser 1102
#define EventWindowWillFocus 1103
#define EventWindowWillMiniaturize 1104
#define EventWindowWillMove 1105
#define EventWindowWillOrderOffScreen 1106
#define EventWindowWillOrderOnScreen 1107
#define EventWindowWillResignMain 1108
#define EventWindowWillResize 1109
#define EventWindowWillUnfocus 1110
#define EventWindowWillUpdate 1111
#define EventWindowWillUpdateAlpha 1112
#define EventWindowWillUpdateCollectionBehavior 1113
#define EventWindowWillUpdateCollectionProperties 1114
#define EventWindowWillUpdateShadow 1115
#define EventWindowWillUpdateTitle 1116
#define EventWindowWillUpdateToolbar 1117
#define EventWindowWillUpdateVisibility 1118
#define EventWindowWillUseStandardFrame 1119
#define EventMenuWillOpen 1120
#define EventMenuDidOpen 1121
#define EventMenuDidClose 1122
#define EventMenuWillSendAction 1123
#define EventMenuDidSendAction 1124
#define EventMenuWillHighlightItem 1125
#define EventMenuDidHighlightItem 1126
#define EventMenuWillDisplayItem 1127
#define EventMenuDidDisplayItem 1128
#define EventMenuWillAddItem 1129
#define EventMenuDidAddItem 1130
#define EventMenuWillRemoveItem 1131
#define EventMenuDidRemoveItem 1132
#define EventMenuWillBeginTracking 1133
#define EventMenuDidBeginTracking 1134
#define EventMenuWillEndTracking 1135
#define EventMenuDidEndTracking 1136
#define EventMenuWillUpdate 1137
#define EventMenuDidUpdate 1138
#define EventMenuWillPopUp 1139
#define EventMenuDidPopUp 1140
#define EventMenuWillSendActionToItem 1141
#define EventMenuDidSendActionToItem 1142
#define EventWebViewDidStartProvisionalNavigation 1143
#define EventWebViewDidReceiveServerRedirectForProvisionalNavigation 1144
#define EventWebViewDidFinishNavigation 1145
#define EventWebViewDidCommitNavigation 1146
#define EventWindowFileDraggingEntered 1147
#define EventWindowFileDraggingPerformed 1148
#define EventWindowFileDraggingExited 1149
#define MAX_EVENTS 1148
#define MAX_EVENTS 1150
#endif
+2 -1
View File
@@ -19,6 +19,7 @@ mac:ApplicationWillResignActive
mac:ApplicationWillTerminate
mac:ApplicationWillUnhide
mac:ApplicationWillUpdate
mac:ApplicationTerminate
mac:ApplicationDidChangeTheme!
mac:ApplicationShouldHandleReopen!
mac:WindowDidBecomeKey
@@ -168,4 +169,4 @@ common:WindowHide
common:WindowDPIChanged
common:WindowFilesDropped
common:ThemeChanged
common:ApplicationTerminate
+36 -1
View File
@@ -79,11 +79,26 @@ export const EventTypes = {
$$WINDOWSJSEVENTS },
Mac: {
$$MACJSEVENTS },
Linux: {
$$LINUXJSEVENTS },
Common: {
$$COMMONJSEVENTS },
};
`
var eventsTS = `
export declare const EventTypes: {
Windows: {
$$WINDOWSTSEVENTS },
Mac: {
$$MACTSEVENTS },
Linux: {
$$LINUXTSEVENTS },
Common: {
$$COMMONTSEVENTS },
};
`
func main() {
eventNames, err := os.ReadFile("../../pkg/events/events.txt")
@@ -112,6 +127,11 @@ func main() {
windowsJSEvents := bytes.NewBufferString("")
commonJSEvents := bytes.NewBufferString("")
linuxTSEvents := bytes.NewBufferString("")
macTSEvents := bytes.NewBufferString("")
windowsTSEvents := bytes.NewBufferString("")
commonTSEvents := bytes.NewBufferString("")
eventToJS := bytes.NewBufferString("")
var id int
@@ -157,6 +177,7 @@ func main() {
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")
linuxTSEvents.WriteString("\t\t" + event + ": string,\n")
eventToJS.WriteString("\t" + strconv.Itoa(id) + ": \"" + strings.TrimSpace(string(line)) + "\",\n")
//maxLinuxEvents = id
case "mac":
@@ -170,6 +191,7 @@ func main() {
macEventsDecl.WriteString("\t" + eventTitle + " " + eventType + "\n")
macEventsValues.WriteString("\t\t" + event + ": " + strconv.Itoa(id) + ",\n")
macJSEvents.WriteString("\t\t" + event + ": \"" + strings.TrimSpace(string(line)) + "\",\n")
macTSEvents.WriteString("\t\t" + event + ": string,\n")
cHeaderEvents.WriteString("#define Event" + eventTitle + " " + strconv.Itoa(id) + "\n")
eventToJS.WriteString("\t" + strconv.Itoa(id) + ": \"" + strings.TrimSpace(string(line)) + "\",\n")
maxMacEvents = id
@@ -218,6 +240,7 @@ func main() {
commonEventsDecl.WriteString("\t" + eventTitle + " " + eventType + "\n")
commonEventsValues.WriteString("\t\t" + event + ": " + strconv.Itoa(id) + ",\n")
commonJSEvents.WriteString("\t\t" + event + ": \"" + strings.TrimSpace(string(line)) + "\",\n")
commonTSEvents.WriteString("\t\t" + event + ": string,\n")
eventToJS.WriteString("\t" + strconv.Itoa(id) + ": \"" + strings.TrimSpace(string(line)) + "\",\n")
case "windows":
eventType := "ApplicationEventType"
@@ -230,6 +253,7 @@ func main() {
windowsEventsDecl.WriteString("\t" + eventTitle + " " + eventType + "\n")
windowsEventsValues.WriteString("\t\t" + event + ": " + strconv.Itoa(id) + ",\n")
windowsJSEvents.WriteString("\t\t" + event + ": \"" + strings.TrimSpace(string(line)) + "\",\n")
windowsTSEvents.WriteString("\t\t" + event + ": string,\n")
eventToJS.WriteString("\t" + strconv.Itoa(id) + ": \"" + strings.TrimSpace(string(line)) + "\",\n")
}
}
@@ -255,8 +279,19 @@ func main() {
// Save the eventsJS template substituting the values and decls
templateToWrite = strings.ReplaceAll(eventsJS, "$$MACJSEVENTS", macJSEvents.String())
templateToWrite = strings.ReplaceAll(templateToWrite, "$$WINDOWSJSEVENTS", windowsJSEvents.String())
templateToWrite = strings.ReplaceAll(templateToWrite, "$$LINUXJSEVENTS", linuxJSEvents.String())
templateToWrite = strings.ReplaceAll(templateToWrite, "$$COMMONJSEVENTS", commonJSEvents.String())
err = os.WriteFile("../../internal/runtime/desktop/api/event_types.js", []byte(templateToWrite), 0644)
err = os.WriteFile("../../internal/runtime/desktop/@wailsio/runtime/src/event_types.js", []byte(templateToWrite), 0644)
if err != nil {
panic(err)
}
// Save the eventsTS template substituting the values and decls
templateToWrite = strings.ReplaceAll(eventsTS, "$$MACTSEVENTS", macTSEvents.String())
templateToWrite = strings.ReplaceAll(templateToWrite, "$$WINDOWSTSEVENTS", windowsTSEvents.String())
templateToWrite = strings.ReplaceAll(templateToWrite, "$$LINUXTSEVENTS", linuxTSEvents.String())
templateToWrite = strings.ReplaceAll(templateToWrite, "$$COMMONTSEVENTS", commonTSEvents.String())
err = os.WriteFile("../../internal/runtime/desktop/@wailsio/runtime/types/event_types.d.ts", []byte(templateToWrite), 0644)
if err != nil {
panic(err)
}