diff --git a/v3/STATUS.md b/v3/STATUS.md index 02dc12871..31cce3fbe 100644 --- a/v3/STATUS.md +++ b/v3/STATUS.md @@ -6,7 +6,7 @@ Status of features in v3. Incomplete - please add as you see fit. - [ ] Dev Support - What will it look like? - [ ] Translucency on Windows doesn't work right -- [ ] Events - cross-platform events, simplified event handling? +- [ ] Events - cross-platform events, simplified event handling?, event constants in JS - [ ] Error handling - needs to be revised. Centralised system error handling? - [ ] Documentation - needs to be written diff --git a/v3/internal/runtime/desktop/api/event_types.js b/v3/internal/runtime/desktop/api/event_types.js new file mode 100644 index 000000000..c9fdeda1d --- /dev/null +++ b/v3/internal/runtime/desktop/api/event_types.js @@ -0,0 +1,287 @@ + +export const EventTypes = { + Windows: { + SystemThemeChanged: "windows:SystemThemeChanged", + APMPowerStatusChange: "windows:APMPowerStatusChange", + APMSuspend: "windows:APMSuspend", + APMResumeAutomatic: "windows:APMResumeAutomatic", + APMResumeSuspend: "windows:APMResumeSuspend", + APMPowerSettingChange: "windows:APMPowerSettingChange", + WebViewNavigationCompleted: "windows:WebViewNavigationCompleted", + }, + Mac: { + ApplicationDidBecomeActive: "mac:ApplicationDidBecomeActive", + ApplicationDidChangeBackingProperties: "mac:ApplicationDidChangeBackingProperties", + ApplicationDidChangeEffectiveAppearance: "mac:ApplicationDidChangeEffectiveAppearance", + ApplicationDidChangeIcon: "mac:ApplicationDidChangeIcon", + ApplicationDidChangeOcclusionState: "mac:ApplicationDidChangeOcclusionState", + ApplicationDidChangeScreenParameters: "mac:ApplicationDidChangeScreenParameters", + ApplicationDidChangeStatusBarFrame: "mac:ApplicationDidChangeStatusBarFrame", + ApplicationDidChangeStatusBarOrientation: "mac:ApplicationDidChangeStatusBarOrientation", + ApplicationDidFinishLaunching: "mac:ApplicationDidFinishLaunching", + ApplicationDidHide: "mac:ApplicationDidHide", + ApplicationDidResignActive: "mac:ApplicationDidResignActive", + ApplicationDidUnhide: "mac:ApplicationDidUnhide", + ApplicationDidUpdate: "mac:ApplicationDidUpdate", + ApplicationWillBecomeActive: "mac:ApplicationWillBecomeActive", + ApplicationWillFinishLaunching: "mac:ApplicationWillFinishLaunching", + ApplicationWillHide: "mac:ApplicationWillHide", + ApplicationWillResignActive: "mac:ApplicationWillResignActive", + ApplicationWillTerminate: "mac:ApplicationWillTerminate", + ApplicationWillUnhide: "mac:ApplicationWillUnhide", + ApplicationWillUpdate: "mac:ApplicationWillUpdate", + WindowDidBecomeKey: "mac:WindowDidBecomeKey", + WindowDidBecomeMain: "mac:WindowDidBecomeMain", + WindowDidBeginSheet: "mac:WindowDidBeginSheet", + WindowDidChangeAlpha: "mac:WindowDidChangeAlpha", + WindowDidChangeBackingLocation: "mac:WindowDidChangeBackingLocation", + WindowDidChangeBackingProperties: "mac:WindowDidChangeBackingProperties", + WindowDidChangeCollectionBehavior: "mac:WindowDidChangeCollectionBehavior", + WindowDidChangeEffectiveAppearance: "mac:WindowDidChangeEffectiveAppearance", + WindowDidChangeOcclusionState: "mac:WindowDidChangeOcclusionState", + WindowDidChangeOrderingMode: "mac:WindowDidChangeOrderingMode", + WindowDidChangeScreen: "mac:WindowDidChangeScreen", + WindowDidChangeScreenParameters: "mac:WindowDidChangeScreenParameters", + WindowDidChangeScreenProfile: "mac:WindowDidChangeScreenProfile", + WindowDidChangeScreenSpace: "mac:WindowDidChangeScreenSpace", + WindowDidChangeScreenSpaceProperties: "mac:WindowDidChangeScreenSpaceProperties", + WindowDidChangeSharingType: "mac:WindowDidChangeSharingType", + WindowDidChangeSpace: "mac:WindowDidChangeSpace", + WindowDidChangeSpaceOrderingMode: "mac:WindowDidChangeSpaceOrderingMode", + WindowDidChangeTitle: "mac:WindowDidChangeTitle", + WindowDidChangeToolbar: "mac:WindowDidChangeToolbar", + WindowDidChangeVisibility: "mac:WindowDidChangeVisibility", + WindowDidDeminiaturize: "mac:WindowDidDeminiaturize", + WindowDidEndSheet: "mac:WindowDidEndSheet", + WindowDidEnterFullScreen: "mac:WindowDidEnterFullScreen", + WindowDidEnterVersionBrowser: "mac:WindowDidEnterVersionBrowser", + WindowDidExitFullScreen: "mac:WindowDidExitFullScreen", + WindowDidExitVersionBrowser: "mac:WindowDidExitVersionBrowser", + WindowDidExpose: "mac:WindowDidExpose", + WindowDidFocus: "mac:WindowDidFocus", + WindowDidMiniaturize: "mac:WindowDidMiniaturize", + WindowDidMove: "mac:WindowDidMove", + WindowDidOrderOffScreen: "mac:WindowDidOrderOffScreen", + WindowDidOrderOnScreen: "mac:WindowDidOrderOnScreen", + WindowDidResignKey: "mac:WindowDidResignKey", + WindowDidResignMain: "mac:WindowDidResignMain", + WindowDidResize: "mac:WindowDidResize", + WindowDidUnfocus: "mac:WindowDidUnfocus", + WindowDidUpdate: "mac:WindowDidUpdate", + WindowDidUpdateAlpha: "mac:WindowDidUpdateAlpha", + WindowDidUpdateCollectionBehavior: "mac:WindowDidUpdateCollectionBehavior", + WindowDidUpdateCollectionProperties: "mac:WindowDidUpdateCollectionProperties", + WindowDidUpdateShadow: "mac:WindowDidUpdateShadow", + WindowDidUpdateTitle: "mac:WindowDidUpdateTitle", + WindowDidUpdateToolbar: "mac:WindowDidUpdateToolbar", + WindowDidUpdateVisibility: "mac:WindowDidUpdateVisibility", + WindowShouldClose: "mac:WindowShouldClose!", + WindowWillBecomeKey: "mac:WindowWillBecomeKey", + WindowWillBecomeMain: "mac:WindowWillBecomeMain", + WindowWillBeginSheet: "mac:WindowWillBeginSheet", + WindowWillChangeOrderingMode: "mac:WindowWillChangeOrderingMode", + WindowWillClose: "mac:WindowWillClose", + WindowWillDeminiaturize: "mac:WindowWillDeminiaturize", + WindowWillEnterFullScreen: "mac:WindowWillEnterFullScreen", + WindowWillEnterVersionBrowser: "mac:WindowWillEnterVersionBrowser", + WindowWillExitFullScreen: "mac:WindowWillExitFullScreen", + WindowWillExitVersionBrowser: "mac:WindowWillExitVersionBrowser", + WindowWillFocus: "mac:WindowWillFocus", + WindowWillMiniaturize: "mac:WindowWillMiniaturize", + WindowWillMove: "mac:WindowWillMove", + WindowWillOrderOffScreen: "mac:WindowWillOrderOffScreen", + WindowWillOrderOnScreen: "mac:WindowWillOrderOnScreen", + WindowWillResignMain: "mac:WindowWillResignMain", + WindowWillResize: "mac:WindowWillResize", + WindowWillUnfocus: "mac:WindowWillUnfocus", + WindowWillUpdate: "mac:WindowWillUpdate", + WindowWillUpdateAlpha: "mac:WindowWillUpdateAlpha", + WindowWillUpdateCollectionBehavior: "mac:WindowWillUpdateCollectionBehavior", + WindowWillUpdateCollectionProperties: "mac:WindowWillUpdateCollectionProperties", + WindowWillUpdateShadow: "mac:WindowWillUpdateShadow", + WindowWillUpdateTitle: "mac:WindowWillUpdateTitle", + WindowWillUpdateToolbar: "mac:WindowWillUpdateToolbar", + WindowWillUpdateVisibility: "mac:WindowWillUpdateVisibility", + WindowWillUseStandardFrame: "mac:WindowWillUseStandardFrame", + MenuWillOpen: "mac:MenuWillOpen", + MenuDidOpen: "mac:MenuDidOpen", + MenuDidClose: "mac:MenuDidClose", + MenuWillSendAction: "mac:MenuWillSendAction", + MenuDidSendAction: "mac:MenuDidSendAction", + MenuWillHighlightItem: "mac:MenuWillHighlightItem", + MenuDidHighlightItem: "mac:MenuDidHighlightItem", + MenuWillDisplayItem: "mac:MenuWillDisplayItem", + MenuDidDisplayItem: "mac:MenuDidDisplayItem", + MenuWillAddItem: "mac:MenuWillAddItem", + MenuDidAddItem: "mac:MenuDidAddItem", + MenuWillRemoveItem: "mac:MenuWillRemoveItem", + MenuDidRemoveItem: "mac:MenuDidRemoveItem", + MenuWillBeginTracking: "mac:MenuWillBeginTracking", + MenuDidBeginTracking: "mac:MenuDidBeginTracking", + MenuWillEndTracking: "mac:MenuWillEndTracking", + MenuDidEndTracking: "mac:MenuDidEndTracking", + MenuWillUpdate: "mac:MenuWillUpdate", + MenuDidUpdate: "mac:MenuDidUpdate", + MenuWillPopUp: "mac:MenuWillPopUp", + MenuDidPopUp: "mac:MenuDidPopUp", + MenuWillSendActionToItem: "mac:MenuWillSendActionToItem", + MenuDidSendActionToItem: "mac:MenuDidSendActionToItem", + WebViewDidStartProvisionalNavigation: "mac:WebViewDidStartProvisionalNavigation", + WebViewDidReceiveServerRedirectForProvisionalNavigation: "mac:WebViewDidReceiveServerRedirectForProvisionalNavigation", + WebViewDidFinishNavigation: "mac:WebViewDidFinishNavigation", + WebViewDidCommitNavigation: "mac:WebViewDidCommitNavigation", + WindowFileDraggingEntered: "mac:WindowFileDraggingEntered", + WindowFileDraggingPerformed: "mac:WindowFileDraggingPerformed", + WindowFileDraggingExited: "mac:WindowFileDraggingExited", + }, + Common: { + ApplicationDidBecomeActive: "mac:ApplicationDidBecomeActive", + ApplicationDidChangeBackingProperties: "mac:ApplicationDidChangeBackingProperties", + ApplicationDidChangeEffectiveAppearance: "mac:ApplicationDidChangeEffectiveAppearance", + ApplicationDidChangeIcon: "mac:ApplicationDidChangeIcon", + ApplicationDidChangeOcclusionState: "mac:ApplicationDidChangeOcclusionState", + ApplicationDidChangeScreenParameters: "mac:ApplicationDidChangeScreenParameters", + ApplicationDidChangeStatusBarFrame: "mac:ApplicationDidChangeStatusBarFrame", + ApplicationDidChangeStatusBarOrientation: "mac:ApplicationDidChangeStatusBarOrientation", + ApplicationDidFinishLaunching: "mac:ApplicationDidFinishLaunching", + ApplicationDidHide: "mac:ApplicationDidHide", + ApplicationDidResignActive: "mac:ApplicationDidResignActive", + ApplicationDidUnhide: "mac:ApplicationDidUnhide", + ApplicationDidUpdate: "mac:ApplicationDidUpdate", + ApplicationWillBecomeActive: "mac:ApplicationWillBecomeActive", + ApplicationWillFinishLaunching: "mac:ApplicationWillFinishLaunching", + ApplicationWillHide: "mac:ApplicationWillHide", + ApplicationWillResignActive: "mac:ApplicationWillResignActive", + ApplicationWillTerminate: "mac:ApplicationWillTerminate", + ApplicationWillUnhide: "mac:ApplicationWillUnhide", + ApplicationWillUpdate: "mac:ApplicationWillUpdate", + WindowDidBecomeKey: "mac:WindowDidBecomeKey", + WindowDidBecomeMain: "mac:WindowDidBecomeMain", + WindowDidBeginSheet: "mac:WindowDidBeginSheet", + WindowDidChangeAlpha: "mac:WindowDidChangeAlpha", + WindowDidChangeBackingLocation: "mac:WindowDidChangeBackingLocation", + WindowDidChangeBackingProperties: "mac:WindowDidChangeBackingProperties", + WindowDidChangeCollectionBehavior: "mac:WindowDidChangeCollectionBehavior", + WindowDidChangeEffectiveAppearance: "mac:WindowDidChangeEffectiveAppearance", + WindowDidChangeOcclusionState: "mac:WindowDidChangeOcclusionState", + WindowDidChangeOrderingMode: "mac:WindowDidChangeOrderingMode", + WindowDidChangeScreen: "mac:WindowDidChangeScreen", + WindowDidChangeScreenParameters: "mac:WindowDidChangeScreenParameters", + WindowDidChangeScreenProfile: "mac:WindowDidChangeScreenProfile", + WindowDidChangeScreenSpace: "mac:WindowDidChangeScreenSpace", + WindowDidChangeScreenSpaceProperties: "mac:WindowDidChangeScreenSpaceProperties", + WindowDidChangeSharingType: "mac:WindowDidChangeSharingType", + WindowDidChangeSpace: "mac:WindowDidChangeSpace", + WindowDidChangeSpaceOrderingMode: "mac:WindowDidChangeSpaceOrderingMode", + WindowDidChangeTitle: "mac:WindowDidChangeTitle", + WindowDidChangeToolbar: "mac:WindowDidChangeToolbar", + WindowDidChangeVisibility: "mac:WindowDidChangeVisibility", + WindowDidDeminiaturize: "mac:WindowDidDeminiaturize", + WindowDidEndSheet: "mac:WindowDidEndSheet", + WindowDidEnterFullScreen: "mac:WindowDidEnterFullScreen", + WindowDidEnterVersionBrowser: "mac:WindowDidEnterVersionBrowser", + WindowDidExitFullScreen: "mac:WindowDidExitFullScreen", + WindowDidExitVersionBrowser: "mac:WindowDidExitVersionBrowser", + WindowDidExpose: "mac:WindowDidExpose", + WindowDidFocus: "mac:WindowDidFocus", + WindowDidMiniaturize: "mac:WindowDidMiniaturize", + WindowDidMove: "mac:WindowDidMove", + WindowDidOrderOffScreen: "mac:WindowDidOrderOffScreen", + WindowDidOrderOnScreen: "mac:WindowDidOrderOnScreen", + WindowDidResignKey: "mac:WindowDidResignKey", + WindowDidResignMain: "mac:WindowDidResignMain", + WindowDidResize: "mac:WindowDidResize", + WindowDidUnfocus: "mac:WindowDidUnfocus", + WindowDidUpdate: "mac:WindowDidUpdate", + WindowDidUpdateAlpha: "mac:WindowDidUpdateAlpha", + WindowDidUpdateCollectionBehavior: "mac:WindowDidUpdateCollectionBehavior", + WindowDidUpdateCollectionProperties: "mac:WindowDidUpdateCollectionProperties", + WindowDidUpdateShadow: "mac:WindowDidUpdateShadow", + WindowDidUpdateTitle: "mac:WindowDidUpdateTitle", + WindowDidUpdateToolbar: "mac:WindowDidUpdateToolbar", + WindowDidUpdateVisibility: "mac:WindowDidUpdateVisibility", + WindowShouldClose: "mac:WindowShouldClose!", + WindowWillBecomeKey: "mac:WindowWillBecomeKey", + WindowWillBecomeMain: "mac:WindowWillBecomeMain", + WindowWillBeginSheet: "mac:WindowWillBeginSheet", + WindowWillChangeOrderingMode: "mac:WindowWillChangeOrderingMode", + WindowWillClose: "mac:WindowWillClose", + WindowWillDeminiaturize: "mac:WindowWillDeminiaturize", + WindowWillEnterFullScreen: "mac:WindowWillEnterFullScreen", + WindowWillEnterVersionBrowser: "mac:WindowWillEnterVersionBrowser", + WindowWillExitFullScreen: "mac:WindowWillExitFullScreen", + WindowWillExitVersionBrowser: "mac:WindowWillExitVersionBrowser", + WindowWillFocus: "mac:WindowWillFocus", + WindowWillMiniaturize: "mac:WindowWillMiniaturize", + WindowWillMove: "mac:WindowWillMove", + WindowWillOrderOffScreen: "mac:WindowWillOrderOffScreen", + WindowWillOrderOnScreen: "mac:WindowWillOrderOnScreen", + WindowWillResignMain: "mac:WindowWillResignMain", + WindowWillResize: "mac:WindowWillResize", + WindowWillUnfocus: "mac:WindowWillUnfocus", + WindowWillUpdate: "mac:WindowWillUpdate", + WindowWillUpdateAlpha: "mac:WindowWillUpdateAlpha", + WindowWillUpdateCollectionBehavior: "mac:WindowWillUpdateCollectionBehavior", + WindowWillUpdateCollectionProperties: "mac:WindowWillUpdateCollectionProperties", + WindowWillUpdateShadow: "mac:WindowWillUpdateShadow", + WindowWillUpdateTitle: "mac:WindowWillUpdateTitle", + WindowWillUpdateToolbar: "mac:WindowWillUpdateToolbar", + WindowWillUpdateVisibility: "mac:WindowWillUpdateVisibility", + WindowWillUseStandardFrame: "mac:WindowWillUseStandardFrame", + MenuWillOpen: "mac:MenuWillOpen", + MenuDidOpen: "mac:MenuDidOpen", + MenuDidClose: "mac:MenuDidClose", + MenuWillSendAction: "mac:MenuWillSendAction", + MenuDidSendAction: "mac:MenuDidSendAction", + MenuWillHighlightItem: "mac:MenuWillHighlightItem", + MenuDidHighlightItem: "mac:MenuDidHighlightItem", + MenuWillDisplayItem: "mac:MenuWillDisplayItem", + MenuDidDisplayItem: "mac:MenuDidDisplayItem", + MenuWillAddItem: "mac:MenuWillAddItem", + MenuDidAddItem: "mac:MenuDidAddItem", + MenuWillRemoveItem: "mac:MenuWillRemoveItem", + MenuDidRemoveItem: "mac:MenuDidRemoveItem", + MenuWillBeginTracking: "mac:MenuWillBeginTracking", + MenuDidBeginTracking: "mac:MenuDidBeginTracking", + MenuWillEndTracking: "mac:MenuWillEndTracking", + MenuDidEndTracking: "mac:MenuDidEndTracking", + MenuWillUpdate: "mac:MenuWillUpdate", + MenuDidUpdate: "mac:MenuDidUpdate", + MenuWillPopUp: "mac:MenuWillPopUp", + MenuDidPopUp: "mac:MenuDidPopUp", + MenuWillSendActionToItem: "mac:MenuWillSendActionToItem", + MenuDidSendActionToItem: "mac:MenuDidSendActionToItem", + WebViewDidStartProvisionalNavigation: "mac:WebViewDidStartProvisionalNavigation", + WebViewDidReceiveServerRedirectForProvisionalNavigation: "mac:WebViewDidReceiveServerRedirectForProvisionalNavigation", + WebViewDidFinishNavigation: "mac:WebViewDidFinishNavigation", + WebViewDidCommitNavigation: "mac:WebViewDidCommitNavigation", + WindowFileDraggingEntered: "mac:WindowFileDraggingEntered", + WindowFileDraggingPerformed: "mac:WindowFileDraggingPerformed", + WindowFileDraggingExited: "mac:WindowFileDraggingExited", + SystemThemeChanged: "windows:SystemThemeChanged", + APMPowerStatusChange: "windows:APMPowerStatusChange", + APMSuspend: "windows:APMSuspend", + APMResumeAutomatic: "windows:APMResumeAutomatic", + APMResumeSuspend: "windows:APMResumeSuspend", + APMPowerSettingChange: "windows:APMPowerSettingChange", + WebViewNavigationCompleted: "windows:WebViewNavigationCompleted", + ApplicationStarted: "common:ApplicationStarted", + WindowMaximise: "common:WindowMaximise", + WindowUnMaximise: "common:WindowUnMaximise", + WindowFullscreen: "common:WindowFullscreen", + WindowUnFullscreen: "common:WindowUnFullscreen", + WindowRestore: "common:WindowRestore", + WindowMinimise: "common:WindowMinimise", + WindowUnMinimise: "common:WindowUnMinimise", + WindowClosing: "common:WindowClosing", + WindowZoom: "common:WindowZoom", + WindowZoomIn: "common:WindowZoomIn", + WindowZoomOut: "common:WindowZoomOut", + WindowZoomReset: "common:WindowZoomReset", + WindowFocus: "common:WindowFocus", + WindowUnFocus: "common:WindowUnFocus", + WindowShow: "common:WindowShow", + WindowHide: "common:WindowHide", + WindowDPIChanged: "common:WindowDPIChanged", + }, +}; diff --git a/v3/internal/runtime/desktop/api/events.js b/v3/internal/runtime/desktop/api/events.js index b705f1da2..208177978 100644 --- a/v3/internal/runtime/desktop/api/events.js +++ b/v3/internal/runtime/desktop/api/events.js @@ -10,6 +10,7 @@ The electron alternative for Go /* jshint esversion: 9 */ +import {EventTypes} from './event_types'; /** * The Events API provides methods to interact with the event system. @@ -65,4 +66,9 @@ export const Events = { OffAll: () => { wails.Events.OffAll(); }, + + Windows: EventTypes.Windows, + Mac: EventTypes.Mac, + Common: EventTypes.Common, + }; diff --git a/v3/internal/runtime/desktop/events.js b/v3/internal/runtime/desktop/events.js index b1d740092..c48ad86f8 100644 --- a/v3/internal/runtime/desktop/events.js +++ b/v3/internal/runtime/desktop/events.js @@ -137,7 +137,6 @@ function listenerOff(listener) { * @param {WailsEvent} event */ export function dispatchWailsEvent(event) { - console.log("dispatching event: ", {event}); let listeners = eventListeners.get(event.name); if (listeners) { // iterate listeners and call callback. If callback returns true, remove listener diff --git a/v3/pkg/application/webview_window.go b/v3/pkg/application/webview_window.go index 1fdf8777d..840301aa8 100644 --- a/v3/pkg/application/webview_window.go +++ b/v3/pkg/application/webview_window.go @@ -520,10 +520,11 @@ func (w *WebviewWindow) On(eventType events.WindowEventType, callback func(ctx * func (w *WebviewWindow) handleWindowEvent(id uint) { w.eventListenersLock.RLock() + defer w.eventListenersLock.RUnlock() for _, listener := range w.eventListeners[id] { go listener.callback(blankWindowEventContext) } - w.eventListenersLock.RUnlock() + w.dispatchWindowEvent(id) } // Width returns the width of the window @@ -810,9 +811,19 @@ func (w *WebviewWindow) SetFrameless(frameless bool) *WebviewWindow { func (w *WebviewWindow) dispatchWailsEvent(event *WailsEvent) { msg := fmt.Sprintf("_wails.dispatchWailsEvent(%s);", event.ToJSON()) + println("Dispatching event: " + msg) w.ExecJS(msg) } +func (w *WebviewWindow) dispatchWindowEvent(id uint) { + // TODO: Make this more efficient by keeping a list of which events have been registered + // and only dispatching those. + jsEvent := &WailsEvent{ + Name: events.JSEvent(id), + } + w.dispatchWailsEvent(jsEvent) +} + func (w *WebviewWindow) info(message string, args ...any) { globalApplication.Log(&logger.Message{ diff --git a/v3/pkg/application/webview_window_windows.go b/v3/pkg/application/webview_window_windows.go index f90e8357f..1ff4b011e 100644 --- a/v3/pkg/application/webview_window_windows.go +++ b/v3/pkg/application/webview_window_windows.go @@ -146,7 +146,7 @@ func (w *windowsWebviewWindow) setMaxSize(width, height int) { } func (w *windowsWebviewWindow) execJS(js string) { - invokeSync(func() { + globalApplication.dispatchOnMainThread(func() { w.chromium.Eval(js) }) } @@ -446,7 +446,7 @@ func (w *windowsWebviewWindow) setRelativePosition(x int, y int) { } // on is used to indicate that a particular event should be listened for -func (w *windowsWebviewWindow) on(eventID uint) { +func (w *windowsWebviewWindow) on(_ uint) { // We don't need to worry about this in Windows as we do not need // to optimise cgo calls } diff --git a/v3/pkg/events/events.go b/v3/pkg/events/events.go index 57a99b7e9..b6e2d3add 100644 --- a/v3/pkg/events/events.go +++ b/v3/pkg/events/events.go @@ -332,3 +332,158 @@ func newWindowsEvents() windowsEvents { WebViewNavigationCompleted: 1153, } } + +func JSEvent(event uint) string { + return eventToJS[event] +} + +var eventToJS = map[uint]string{ + 1024: "mac:ApplicationDidBecomeActive", + 1025: "mac:ApplicationDidChangeBackingProperties", + 1026: "mac:ApplicationDidChangeEffectiveAppearance", + 1027: "mac:ApplicationDidChangeIcon", + 1028: "mac:ApplicationDidChangeOcclusionState", + 1029: "mac:ApplicationDidChangeScreenParameters", + 1030: "mac:ApplicationDidChangeStatusBarFrame", + 1031: "mac:ApplicationDidChangeStatusBarOrientation", + 1032: "mac:ApplicationDidFinishLaunching", + 1033: "mac:ApplicationDidHide", + 1034: "mac:ApplicationDidResignActive", + 1035: "mac:ApplicationDidUnhide", + 1036: "mac:ApplicationDidUpdate", + 1037: "mac:ApplicationWillBecomeActive", + 1038: "mac:ApplicationWillFinishLaunching", + 1039: "mac:ApplicationWillHide", + 1040: "mac:ApplicationWillResignActive", + 1041: "mac:ApplicationWillTerminate", + 1042: "mac:ApplicationWillUnhide", + 1043: "mac:ApplicationWillUpdate", + 1044: "mac:WindowDidBecomeKey", + 1045: "mac:WindowDidBecomeMain", + 1046: "mac:WindowDidBeginSheet", + 1047: "mac:WindowDidChangeAlpha", + 1048: "mac:WindowDidChangeBackingLocation", + 1049: "mac:WindowDidChangeBackingProperties", + 1050: "mac:WindowDidChangeCollectionBehavior", + 1051: "mac:WindowDidChangeEffectiveAppearance", + 1052: "mac:WindowDidChangeOcclusionState", + 1053: "mac:WindowDidChangeOrderingMode", + 1054: "mac:WindowDidChangeScreen", + 1055: "mac:WindowDidChangeScreenParameters", + 1056: "mac:WindowDidChangeScreenProfile", + 1057: "mac:WindowDidChangeScreenSpace", + 1058: "mac:WindowDidChangeScreenSpaceProperties", + 1059: "mac:WindowDidChangeSharingType", + 1060: "mac:WindowDidChangeSpace", + 1061: "mac:WindowDidChangeSpaceOrderingMode", + 1062: "mac:WindowDidChangeTitle", + 1063: "mac:WindowDidChangeToolbar", + 1064: "mac:WindowDidChangeVisibility", + 1065: "mac:WindowDidDeminiaturize", + 1066: "mac:WindowDidEndSheet", + 1067: "mac:WindowDidEnterFullScreen", + 1068: "mac:WindowDidEnterVersionBrowser", + 1069: "mac:WindowDidExitFullScreen", + 1070: "mac:WindowDidExitVersionBrowser", + 1071: "mac:WindowDidExpose", + 1072: "mac:WindowDidFocus", + 1073: "mac:WindowDidMiniaturize", + 1074: "mac:WindowDidMove", + 1075: "mac:WindowDidOrderOffScreen", + 1076: "mac:WindowDidOrderOnScreen", + 1077: "mac:WindowDidResignKey", + 1078: "mac:WindowDidResignMain", + 1079: "mac:WindowDidResize", + 1080: "mac:WindowDidUnfocus", + 1081: "mac:WindowDidUpdate", + 1082: "mac:WindowDidUpdateAlpha", + 1083: "mac:WindowDidUpdateCollectionBehavior", + 1084: "mac:WindowDidUpdateCollectionProperties", + 1085: "mac:WindowDidUpdateShadow", + 1086: "mac:WindowDidUpdateTitle", + 1087: "mac:WindowDidUpdateToolbar", + 1088: "mac:WindowDidUpdateVisibility", + 1089: "mac:WindowShouldClose!", + 1090: "mac:WindowWillBecomeKey", + 1091: "mac:WindowWillBecomeMain", + 1092: "mac:WindowWillBeginSheet", + 1093: "mac:WindowWillChangeOrderingMode", + 1094: "mac:WindowWillClose", + 1095: "mac:WindowWillDeminiaturize", + 1096: "mac:WindowWillEnterFullScreen", + 1097: "mac:WindowWillEnterVersionBrowser", + 1098: "mac:WindowWillExitFullScreen", + 1099: "mac:WindowWillExitVersionBrowser", + 1100: "mac:WindowWillFocus", + 1101: "mac:WindowWillMiniaturize", + 1102: "mac:WindowWillMove", + 1103: "mac:WindowWillOrderOffScreen", + 1104: "mac:WindowWillOrderOnScreen", + 1105: "mac:WindowWillResignMain", + 1106: "mac:WindowWillResize", + 1107: "mac:WindowWillUnfocus", + 1108: "mac:WindowWillUpdate", + 1109: "mac:WindowWillUpdateAlpha", + 1110: "mac:WindowWillUpdateCollectionBehavior", + 1111: "mac:WindowWillUpdateCollectionProperties", + 1112: "mac:WindowWillUpdateShadow", + 1113: "mac:WindowWillUpdateTitle", + 1114: "mac:WindowWillUpdateToolbar", + 1115: "mac:WindowWillUpdateVisibility", + 1116: "mac:WindowWillUseStandardFrame", + 1117: "mac:MenuWillOpen", + 1118: "mac:MenuDidOpen", + 1119: "mac:MenuDidClose", + 1120: "mac:MenuWillSendAction", + 1121: "mac:MenuDidSendAction", + 1122: "mac:MenuWillHighlightItem", + 1123: "mac:MenuDidHighlightItem", + 1124: "mac:MenuWillDisplayItem", + 1125: "mac:MenuDidDisplayItem", + 1126: "mac:MenuWillAddItem", + 1127: "mac:MenuDidAddItem", + 1128: "mac:MenuWillRemoveItem", + 1129: "mac:MenuDidRemoveItem", + 1130: "mac:MenuWillBeginTracking", + 1131: "mac:MenuDidBeginTracking", + 1132: "mac:MenuWillEndTracking", + 1133: "mac:MenuDidEndTracking", + 1134: "mac:MenuWillUpdate", + 1135: "mac:MenuDidUpdate", + 1136: "mac:MenuWillPopUp", + 1137: "mac:MenuDidPopUp", + 1138: "mac:MenuWillSendActionToItem", + 1139: "mac:MenuDidSendActionToItem", + 1140: "mac:WebViewDidStartProvisionalNavigation", + 1141: "mac:WebViewDidReceiveServerRedirectForProvisionalNavigation", + 1142: "mac:WebViewDidFinishNavigation", + 1143: "mac:WebViewDidCommitNavigation", + 1144: "mac:WindowFileDraggingEntered", + 1145: "mac:WindowFileDraggingPerformed", + 1146: "mac:WindowFileDraggingExited", + 1147: "windows:SystemThemeChanged", + 1148: "windows:APMPowerStatusChange", + 1149: "windows:APMSuspend", + 1150: "windows:APMResumeAutomatic", + 1151: "windows:APMResumeSuspend", + 1152: "windows:APMPowerSettingChange", + 1153: "windows:WebViewNavigationCompleted", + 1154: "common:ApplicationStarted", + 1155: "common:WindowMaximise", + 1156: "common:WindowUnMaximise", + 1157: "common:WindowFullscreen", + 1158: "common:WindowUnFullscreen", + 1159: "common:WindowRestore", + 1160: "common:WindowMinimise", + 1161: "common:WindowUnMinimise", + 1162: "common:WindowClosing", + 1163: "common:WindowZoom", + 1164: "common:WindowZoomIn", + 1165: "common:WindowZoomOut", + 1166: "common:WindowZoomReset", + 1167: "common:WindowFocus", + 1168: "common:WindowUnFocus", + 1169: "common:WindowShow", + 1170: "common:WindowHide", + 1171: "common:WindowDPIChanged", +} diff --git a/v3/tasks/events/generate.go b/v3/tasks/events/generate.go index b7ac0f2cb..7b34287f5 100644 --- a/v3/tasks/events/generate.go +++ b/v3/tasks/events/generate.go @@ -46,6 +46,12 @@ func newWindowsEvents() windowsEvents { $$WINDOWSEVENTSVALUES } } +func JSEvent(event uint) string { + return eventToJS[event] +} + +var eventToJS = map[uint]string{ +$$EVENTTOJS} ` @@ -61,6 +67,17 @@ $$CHEADEREVENTS #endif` +var eventsJS = ` +export const EventTypes = { + Windows: { +$$WINDOWSJSEVENTS }, + Mac: { +$$MACJSEVENTS }, + Common: { +$$COMMONJSEVENTS }, +}; +` + func main() { eventNames, err := os.ReadFile("../../pkg/events/events.txt") @@ -81,6 +98,12 @@ func main() { commonEventsDecl := bytes.NewBufferString("") commonEventsValues := bytes.NewBufferString("") + macJSEvents := bytes.NewBufferString("") + windowsJSEvents := bytes.NewBufferString("") + commonJSEvents := bytes.NewBufferString("") + + eventToJS := bytes.NewBufferString("") + var id int var maxMacEvents int var line []byte @@ -122,7 +145,10 @@ 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") + commonJSEvents.WriteString("\t\t" + event + ": \"" + strings.TrimSpace(string(line)) + "\",\n") cHeaderEvents.WriteString("#define Event" + eventTitle + " " + strconv.Itoa(id) + "\n") + eventToJS.WriteString("\t" + strconv.Itoa(id) + ": \"" + strings.TrimSpace(string(line)) + "\",\n") maxMacEvents = id if ignoreEvent { continue @@ -168,6 +194,8 @@ 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") + eventToJS.WriteString("\t" + strconv.Itoa(id) + ": \"" + strings.TrimSpace(string(line)) + "\",\n") case "windows": eventType := "ApplicationEventType" if strings.HasPrefix(event, "Window") { @@ -178,6 +206,9 @@ 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") + commonJSEvents.WriteString("\t\t" + event + ": \"" + strings.TrimSpace(string(line)) + "\",\n") + eventToJS.WriteString("\t" + strconv.Itoa(id) + ": \"" + strings.TrimSpace(string(line)) + "\",\n") } } @@ -190,11 +221,21 @@ func main() { templateToWrite = strings.ReplaceAll(templateToWrite, "$$WINDOWSEVENTSVALUES", windowsEventsValues.String()) templateToWrite = strings.ReplaceAll(templateToWrite, "$$COMMONEVENTSDECL", commonEventsDecl.String()) templateToWrite = strings.ReplaceAll(templateToWrite, "$$COMMONEVENTSVALUES", commonEventsValues.String()) + templateToWrite = strings.ReplaceAll(templateToWrite, "$$EVENTTOJS", eventToJS.String()) err = os.WriteFile("../../pkg/events/events.go", []byte(templateToWrite), 0644) if err != nil { panic(err) } + // 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, "$$COMMONJSEVENTS", commonJSEvents.String()) + err = os.WriteFile("../../internal/runtime/desktop/api/event_types.js", []byte(templateToWrite), 0644) + if err != nil { + panic(err) + } + // Save the eventsH template substituting the values and decls templateToWrite = strings.ReplaceAll(eventsH, "$$CHEADEREVENTS", cHeaderEvents.String()) err = os.WriteFile("../../pkg/events/events.h", []byte(templateToWrite), 0644)