@nativescript/windows-v8 0.1.0-alpha.146 → 0.1.0-beta.5

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.
@@ -53,6 +53,7 @@ namespace __PROJECT_NAME__
53
53
  private static extern void runtime_free_js_error(IntPtr ptr);
54
54
 
55
55
  [DllImport(NativeScriptLibrary, EntryPoint = nameof(runtime_has_devtools))]
56
+ [return: MarshalAs(UnmanagedType.U1)]
56
57
  private static extern bool runtime_has_devtools();
57
58
 
58
59
  [DllImport(NativeScriptLibrary, EntryPoint = nameof(runtime_pump_timers))]
@@ -110,6 +111,21 @@ namespace __PROJECT_NAME__
110
111
  [DllImport(NativeScriptLibrary, EntryPoint = nameof(runtime_free_string))]
111
112
  private static extern void runtime_free_string(IntPtr ptr);
112
113
 
114
+ [DllImport(NativeScriptLibrary, EntryPoint = nameof(runtime_devtools_wait_for_debugger))]
115
+ [return: MarshalAs(UnmanagedType.U1)]
116
+ private static extern bool runtime_devtools_wait_for_debugger(long runtime, uint timeoutMs);
117
+
118
+ // iOS uses 41000 and Android 42000.
119
+ private const ushort DevtoolsPort = 43000;
120
+ private const uint DebuggerWaitTimeoutMs = 30000;
121
+
122
+ // LocalFolder sentinel files shared with the CLI's WindowsApplicationManager.
123
+ private const string InspectorMarker = "ns-inspector";
124
+ private const string DebugBreakMarker = "ns-debugbreak";
125
+ private const string DebuggerStartedMarker = "ns-debugger-started";
126
+
127
+ private bool _waitForDebugger;
128
+
113
129
  public string DevtoolsFrontendUrl { get; private set; }
114
130
 
115
131
  private bool _devtoolsAvailable;
@@ -130,7 +146,7 @@ namespace __PROJECT_NAME__
130
146
  IntPtr urlPtr = IntPtr.Zero;
131
147
  try
132
148
  {
133
- urlPtr = runtime_devtools_start(_runtime, 42000);
149
+ urlPtr = runtime_devtools_start(_runtime, DevtoolsPort);
134
150
  if (urlPtr == IntPtr.Zero) return;
135
151
  var wsUrl = Marshal.PtrToStringUTF8(urlPtr);
136
152
  DevtoolsFrontendUrl = wsUrl != null
@@ -139,6 +155,8 @@ namespace __PROJECT_NAME__
139
155
  if (DevtoolsFrontendUrl != null)
140
156
  {
141
157
  _devtoolsAvailable = true;
158
+ // The server may fall back to the next free port.
159
+ WriteMarker(DebuggerStartedMarker, new Uri(wsUrl).Port.ToString());
142
160
  System.Diagnostics.Debug.WriteLine($"[NativeScript DevTools] {DevtoolsFrontendUrl}");
143
161
  }
144
162
  }
@@ -191,31 +209,48 @@ namespace __PROJECT_NAME__
191
209
  }
192
210
  }
193
211
  catch { }
194
- if (ConsumeDebugBreakMarker())
212
+ DeleteMarker(DebuggerStartedMarker);
213
+ var debugBreak = ConsumeMarker(DebugBreakMarker);
214
+ if (ConsumeMarker(InspectorMarker) || debugBreak)
215
+ {
195
216
  StartDevtoolsSafely();
217
+ _waitForDebugger = debugBreak && _devtoolsAvailable;
218
+ }
196
219
  #endif
197
220
  _initialized = true;
198
221
  }
199
222
 
200
223
  #if DEBUG
201
- /// <summary>
202
- /// Returns true and deletes the marker if the CLI wrote ns-debugbreak to LocalFolder,
203
- /// matching the Android sentinel-file pattern used by the NativeScript CLI.
204
- /// </summary>
205
- private static bool ConsumeDebugBreakMarker()
224
+ private static string MarkerPath(string name) =>
225
+ Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, name);
226
+
227
+ private static bool ConsumeMarker(string name)
206
228
  {
207
229
  try
208
230
  {
209
- var markerPath = System.IO.Path.Combine(
210
- Windows.Storage.ApplicationData.Current.LocalFolder.Path,
211
- "ns-debugbreak");
212
- if (!System.IO.File.Exists(markerPath))
231
+ var markerPath = MarkerPath(name);
232
+ if (!File.Exists(markerPath))
213
233
  return false;
214
- System.IO.File.Delete(markerPath);
234
+ File.Delete(markerPath);
215
235
  return true;
216
236
  }
217
237
  catch { return false; }
218
238
  }
239
+
240
+ private static void WriteMarker(string name, string contents)
241
+ {
242
+ try { File.WriteAllText(MarkerPath(name), contents); }
243
+ catch (Exception ex)
244
+ {
245
+ System.Diagnostics.Debug.WriteLine($"[NativeScript DevTools] Could not write {name}: {ex.Message}");
246
+ }
247
+ }
248
+
249
+ private static void DeleteMarker(string name)
250
+ {
251
+ try { File.Delete(MarkerPath(name)); }
252
+ catch { }
253
+ }
219
254
  #endif
220
255
 
221
256
  /// Reads a file that may live inside a sealed app.nsbundle instead of on disk: tries the
@@ -244,6 +279,15 @@ namespace __PROJECT_NAME__
244
279
  if (!_initialized)
245
280
  throw new InvalidOperationException("Runtime must be initialized before running scripts.");
246
281
 
282
+ #if DEBUG
283
+ if (_waitForDebugger)
284
+ {
285
+ // --debug-brk: hold the first script until DevTools attaches.
286
+ _waitForDebugger = false;
287
+ if (!runtime_devtools_wait_for_debugger(_runtime, DebuggerWaitTimeoutMs))
288
+ System.Diagnostics.Debug.WriteLine("[NativeScript DevTools] No debugger attached, continuing.");
289
+ }
290
+ #endif
247
291
  var entryPath = ResolveEntryScriptPath();
248
292
  if (entryPath == null)
249
293
  {
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nativescript/windows-v8",
3
- "version": "0.1.0-alpha.146",
3
+ "version": "0.1.0-beta.5",
4
4
  "description": "NativeScript Windows runtime (V8 engine) with a WinUI 3 app template",
5
5
  "keywords": [
6
6
  "NativeScript",