@geastack/apple 0.2.15 → 0.2.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,28 @@
1
1
  #pragma once
2
2
 
3
3
  #ifdef __OBJC__
4
- #import <Foundation/Foundation.h>
4
+ #import <AppKit/AppKit.h>
5
5
 
6
- @interface PressBridge : NSObject
6
+ @interface GeaRetiredPress : NSObject {
7
+ @private
8
+ void *_geaRetiredState;
9
+ }
10
+ - (void)emitCancellation;
11
+ @end
12
+
13
+ @interface PressBridge : NSObject {
14
+ @private
15
+ void *_geaPressState;
16
+ }
7
17
  @property(nonatomic, assign) int nodeId;
18
+ // Non-pointer tracking is used only for genuine keyboard default activation.
19
+ - (NSUInteger)beginPress:(id)sender;
20
+ - (NSUInteger)beginKeyboardPress:(id)sender;
21
+ - (NSUInteger)beginPointerPress:(NSEvent *)event;
22
+ - (void)endPressTracking:(NSUInteger)ticket;
23
+ - (void)cancelPress:(id)sender;
24
+ // Close the old native binding before any cancellation callback can reenter.
25
+ - (GeaRetiredPress *)closeInputBinding;
8
26
  - (void)fire:(id)sender;
9
27
  @end
10
28
  #endif
@@ -13,7 +31,7 @@
13
31
  extern "C" {
14
32
  #endif
15
33
 
16
- // Dispatches a Click + Press event to the given node id via Tree::dispatchEvent.
34
+ // Programmatic atomic activation. Physical controls use begin/release/cancel.
17
35
  void gea_macos_fire_press_for_node(int nodeId);
18
36
 
19
37
  #ifdef __cplusplus
@@ -5,30 +5,42 @@
5
5
 
6
6
  #include <cstring>
7
7
 
8
+ #include "ui/node.h"
9
+ #include "macos_key_event.h"
10
+ #include "macos_control_admission.h"
11
+
12
+ namespace {
13
+ struct NativePress {
14
+ gea::framework::identity::Owner binding, owner;
15
+ int node = -1;
16
+ NSUInteger ticket = 0;
17
+ bool tracking = false, active = false, completed = false;
18
+ bool pointerGesture = false;
19
+ int button = -1;
20
+ std::uint32_t buttons = 0;
21
+ bool current() const {
22
+ return owner==binding && gea::framework::identity::current(node,owner);
23
+ }
24
+ void emit(gea::framework::events::PointerEventType type) const {
25
+ if(!current())return;
26
+ gea::framework::events::PointerEvent event;
27
+ event.type=type;event.targetId=node;event.pointerId=1;
28
+ if(pointerGesture){
29
+ event.button=type==gea::framework::events::PointerEventType::PointerCancel?-1:button;
30
+ event.buttons=type==gea::framework::events::PointerEventType::TouchStart?buttons:0;
31
+ }
32
+ gea::embedded::ui::Tree::instance().dispatchEvent(event);
33
+ }
34
+ };
35
+ }
8
36
  extern "C" void gea_macos_fire_press_for_node(int nodeId)
9
37
  {
10
- using gea::framework::events::PointerEvent;
11
- using gea::framework::events::PointerEventType;
12
- if (nodeId < 0) return;
13
- auto &tree = gea::embedded::ui::Tree::instance();
14
- if (nodeId >= tree.nodeCount()) return;
15
-
16
- // A native click on macOS corresponds to a full press-and-release cycle.
17
- // Apps may listen for any of these — the browser equivalent fires the
18
- // whole sequence too — so dispatch them in browser order:
19
- // touchstart → touchend → click
20
- // This way apps written for the ESP32 touchscreen (which only sees
21
- // touchstart/touchend) still respond to mouse clicks, and JSX onClick
22
- // handlers fire consistently with the web target.
23
- auto fire = [&](PointerEventType type) {
24
- PointerEvent ev;
25
- ev.type = type;
26
- ev.targetId = nodeId;
27
- tree.dispatchEvent(ev);
28
- };
29
- fire(PointerEventType::TouchStart);
30
- fire(PointerEventType::TouchEnd);
31
- fire(PointerEventType::Click);
38
+ const auto owner=gea::framework::identity::node(nodeId);
39
+ if(!gea::macos::controlAdmitted(nodeId,owner))return;
40
+ gea::framework::events::PointerEvent event{};
41
+ event.type=gea::framework::events::PointerEventType::Click;
42
+ event.targetId=nodeId;
43
+ gea::embedded::ui::Tree::instance().dispatchEvent(event);
32
44
  }
33
45
 
34
46
  // Headless equivalent of a keystroke into the first `<input>` / `<textarea>`:
@@ -54,6 +66,7 @@ extern "C" int gea_macos_fire_input_for_node(int nodeId, const char *text)
54
66
  }
55
67
  }
56
68
  if (target < 0 || target >= tree.nodeCount()) return -1;
69
+ if (!gea::macos::controlAdmitted(target, gea::framework::identity::node(target))) return -1;
57
70
  tree.setAttribute(target, "value", text ? text : "");
58
71
  PointerEvent ev;
59
72
  ev.type = PointerEventType::Input;
@@ -63,10 +76,97 @@ extern "C" int gea_macos_fire_input_for_node(int nodeId, const char *text)
63
76
  return target;
64
77
  }
65
78
 
79
+ @interface GeaRetiredPress ()
80
+ - (instancetype)initWithState:(const NativePress &)state;
81
+ @end
82
+ @implementation GeaRetiredPress
83
+ - (instancetype)initWithState:(const NativePress &)state {
84
+ if((self=[super init]))_geaRetiredState=new NativePress(state);
85
+ return self;
86
+ }
87
+ - (void)dealloc {delete static_cast<NativePress *>(_geaRetiredState);}
88
+ - (void)emitCancellation {
89
+ auto &state=*static_cast<NativePress *>(_geaRetiredState);
90
+ if(!state.active || state.completed)return;
91
+ state.active=false;state.completed=true;
92
+ state.emit(gea::framework::events::PointerEventType::PointerCancel);
93
+ }
94
+ @end
95
+
66
96
  @implementation PressBridge
67
- - (void)fire:(id)sender
68
- {
69
- (void)sender;
70
- gea_macos_fire_press_for_node(self.nodeId);
97
+ - (instancetype)init {
98
+ if((self=[super init])){_nodeId=-1;_geaPressState=new NativePress;}
99
+ return self;
100
+ }
101
+ - (void)dealloc { delete static_cast<NativePress *>(_geaPressState); }
102
+ - (void)setNodeId:(int)nodeId {
103
+ auto &state=*static_cast<NativePress *>(_geaPressState);
104
+ auto binding=gea::framework::identity::node(nodeId);
105
+ if(_nodeId!=nodeId || state.binding!=binding)[self cancelPress:nil];
106
+ _nodeId=nodeId;state.binding=std::move(binding);
107
+ }
108
+ - (NSUInteger)beginPress:(id)sender {
109
+ (void)sender;[self cancelPress:nil];
110
+ auto &state=*static_cast<NativePress *>(_geaPressState);
111
+ state.node=_nodeId;state.owner=state.binding;
112
+ if(!state.current() || !gea::macos::controlAdmitted(state.node,state.owner))return 0;
113
+ ++state.ticket;if(!state.ticket)++state.ticket;
114
+ state.tracking=true;state.active=true;state.completed=false;
115
+ state.pointerGesture=false;state.button=-1;state.buttons=0;
116
+ const auto ticket=state.ticket;
117
+ return ticket;
118
+ }
119
+ - (NSUInteger)beginKeyboardPress:(id)sender { return [self beginPress:sender]; }
120
+ - (NSUInteger)beginPointerPress:(NSEvent *)event {
121
+ if(!event || (event.type!=NSEventTypeLeftMouseDown && event.type!=NSEventTypeRightMouseDown && event.type!=NSEventTypeOtherMouseDown))return 0;
122
+ // Left/right event kinds carry the changed edge even when AppKit authored
123
+ // mouseEventWithType reports buttonNumber zero for a right event. Other
124
+ // events require an actual additional-button number; unknown is refused.
125
+ const NSInteger nativeButton=event.type==NSEventTypeLeftMouseDown?0:event.type==NSEventTypeRightMouseDown?1:event.buttonNumber;
126
+ if(nativeButton<0 || nativeButton>31 || (event.type==NSEventTypeOtherMouseDown && nativeButton<2))return 0;
127
+ const auto ticket=[self beginPress:nil];if(!ticket)return 0;
128
+ auto &state=*static_cast<NativePress *>(_geaPressState);
129
+ state.pointerGesture=true;
130
+ state.button=nativeButton==1?2:nativeButton==2?1:static_cast<int>(nativeButton);
131
+ // Track this owned gesture's changed edge, not unrelated global mouse work.
132
+ // A directly delivered native down event need not change pressedMouseButtons.
133
+ state.buttons=std::uint32_t(1)<<nativeButton;
134
+ state.emit(gea::framework::events::PointerEventType::TouchStart);
135
+ return ticket;
136
+ }
137
+ - (void)cancelPress:(id)sender {
138
+ (void)sender;auto &state=*static_cast<NativePress *>(_geaPressState);
139
+ if(!state.active)return;
140
+ state.active=false;state.completed=true;
141
+ state.emit(gea::framework::events::PointerEventType::PointerCancel);
142
+ }
143
+ - (GeaRetiredPress *)closeInputBinding {
144
+ auto &state=*static_cast<NativePress *>(_geaPressState);
145
+ GeaRetiredPress *retired=[[GeaRetiredPress alloc] initWithState:state];
146
+ _nodeId=-1;state.node=-1;state.owner={};state.binding={};
147
+ state.active=false;state.completed=true;state.tracking=true;++state.ticket;
148
+ return retired;
149
+ }
150
+ - (void)endPressTracking:(NSUInteger)ticket {
151
+ auto &state=*static_cast<NativePress *>(_geaPressState);
152
+ if(state.ticket!=ticket)return;
153
+ [self cancelPress:nil];if(state.ticket==ticket)state.tracking=false;
154
+ }
155
+ - (void)fire:(id)sender {
156
+ auto &state=*static_cast<NativePress *>(_geaPressState);
157
+ if(!gea::macos::controlAdmitted(_nodeId,state.binding)){[self cancelPress:nil];return;}
158
+ if([sender isKindOfClass:[NSControl class]] && ![(NSControl *)sender isEnabled]) {
159
+ [self cancelPress:nil];return;
160
+ }
161
+ if(!state.tracking){
162
+ if(gea::framework::identity::current(_nodeId,state.binding))gea_macos_fire_press_for_node(_nodeId);
163
+ return;
164
+ }
165
+ if(!state.active || state.completed)return; // native action repeats/echo
166
+ const auto ticket=state.ticket;
167
+ state.active=false;state.completed=true;
168
+ if(!state.current())return;
169
+ if(state.pointerGesture)state.emit(gea::framework::events::PointerEventType::TouchEnd);
170
+ if(state.ticket==ticket && state.current() && gea::macos::controlAdmitted(state.node,state.owner))state.emit(gea::framework::events::PointerEventType::Click);
71
171
  }
72
172
  @end
@@ -84,6 +84,7 @@ function walkCss(root, visit) {
84
84
  // collisions, but keep an owned manifest so removed @font-face declarations do
85
85
  // not leave stale resources in the app bundle.
86
86
  const desiredFonts = new Map()
87
+ const desiredFontLicenses = new Map()
87
88
  for (const root of [...appDirs, ...sharedCssDirs]) {
88
89
  walkCss(root, (cssPath) => {
89
90
  const css = fs.readFileSync(cssPath, 'utf8').replace(/\/\*[\s\S]*?\*\//g, '')
@@ -98,7 +99,18 @@ for (const root of [...appDirs, ...sharedCssDirs]) {
98
99
  const resolved = path.resolve(path.dirname(cssPath), clean)
99
100
  if (!fs.existsSync(resolved) || !fs.statSync(resolved).isFile()) continue
100
101
  const basename = path.basename(resolved)
101
- if (!desiredFonts.has(basename)) desiredFonts.set(basename, resolved)
102
+ if (!desiredFonts.has(basename)) {
103
+ desiredFonts.set(basename, resolved)
104
+ // Preserve licenses alongside packaged font bytes, using a font-specific
105
+ // name so independent families with OFL.txt cannot overwrite each other.
106
+ for (const name of ['OFL.txt', 'LICENSE.txt', 'LICENSE']) {
107
+ const license = path.join(path.dirname(resolved), name)
108
+ if (fs.existsSync(license) && fs.statSync(license).isFile()) {
109
+ desiredFontLicenses.set(`${basename}.license.txt`, license)
110
+ break
111
+ }
112
+ }
113
+ }
102
114
  }
103
115
  })
104
116
  }
@@ -134,6 +146,16 @@ if (fs.existsSync(fontsDir) && fs.readdirSync(fontsDir).length === 0) {
134
146
  fs.rmdirSync(fontsDir)
135
147
  }
136
148
 
149
+ const fontLicensesDir = path.join(resourcesDir, 'FontLicenses')
150
+ if (fs.existsSync(fontLicensesDir)) {
151
+ for (const entry of fs.readdirSync(fontLicensesDir, {withFileTypes: true})) {
152
+ if ((entry.isFile() || entry.isSymbolicLink()) && !desiredFontLicenses.has(entry.name))
153
+ removeFile(path.join(fontLicensesDir, entry.name))
154
+ }
155
+ }
156
+ for (const [name, source] of desiredFontLicenses) syncFile(source, path.join(fontLicensesDir, name))
157
+ if (fs.existsSync(fontLicensesDir) && fs.readdirSync(fontLicensesDir).length === 0) fs.rmdirSync(fontLicensesDir)
158
+
137
159
  const windowConfig = path.join(resourcesDir, 'window.json')
138
160
  for (const entry of fs.readdirSync(resourcesDir, { withFileTypes: true })) {
139
161
  if (entry.isFile() && /^window\.json\.tmp\.\d+$/.test(entry.name)) removeFile(path.join(resourcesDir, entry.name))
@@ -142,7 +164,7 @@ const configSource = configDir ? path.join(configDir, 'macos.json') : ''
142
164
  if (configSource && fs.existsSync(configSource)) syncFile(configSource, windowConfig)
143
165
  else removeFile(windowConfig)
144
166
 
145
- const manifest = `${JSON.stringify({ fonts: [...desiredFonts.keys()].sort() }, null, 2)}\n`
167
+ const manifest = `${JSON.stringify({ fonts: [...desiredFonts.keys()].sort(), fontLicenses: [...desiredFontLicenses.keys()].sort() }, null, 2)}\n`
146
168
  fs.mkdirSync(path.dirname(manifestPath), { recursive: true })
147
169
  if (!fs.existsSync(manifestPath) || fs.readFileSync(manifestPath, 'utf8') !== manifest) {
148
170
  const temporary = `${manifestPath}.tmp.${process.pid}`