@nativescript/windows-v8 0.1.0-alpha.145 → 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
  {
@@ -351,7 +351,7 @@ public static partial class Bridge
351
351
  : DispatchResult.Handle(id, typeName);
352
352
  }
353
353
 
354
- private static bool IsAwaitable(object value, Type t)
354
+ private static bool IsAwaitable(object? value, Type t)
355
355
  {
356
356
  if (value is Task || value is ValueTask) return true;
357
357
  if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(ValueTask<>)) return true;
@@ -421,7 +421,6 @@ public static partial class Bridge
421
421
  // look up or dynamically emit a proxy for the correct base class.
422
422
  string? resolveFrom = typeName;
423
423
  if (!string.IsNullOrEmpty(assemblyName)
424
- && typeName != null
425
424
  && typeName.StartsWith("com.tns.gen.winrt.", StringComparison.Ordinal))
426
425
  {
427
426
  resolveFrom = assemblyName;
@@ -115,7 +115,7 @@ public static partial class Bridge
115
115
  var simple = Path.GetFileNameWithoutExtension(file);
116
116
  if (string.IsNullOrEmpty(simple)) continue;
117
117
 
118
- Assembly asm = AppDomain.CurrentDomain.GetAssemblies()
118
+ Assembly? asm = AppDomain.CurrentDomain.GetAssemblies()
119
119
  .FirstOrDefault(a => string.Equals(a.GetName().Name, simple, StringComparison.OrdinalIgnoreCase));
120
120
  if (asm is null)
121
121
  {
@@ -540,7 +540,7 @@ public static partial class Bridge
540
540
  {
541
541
  var handlerType = ev.EventHandlerType;
542
542
  var method = typeof(Bridge).GetMethod(nameof(CoreApplicationUnhandledErrorHandler), BindingFlags.NonPublic | BindingFlags.Static);
543
- if (method != null)
543
+ if (handlerType != null && method != null)
544
544
  {
545
545
  var del = Delegate.CreateDelegate(handlerType, method);
546
546
  ev.AddEventHandler(null, del);
@@ -633,7 +633,7 @@ public static partial class Bridge
633
633
  try
634
634
  {
635
635
  var iidLocal = s_iidIInspectable;
636
- var hr = Marshal.QueryInterface(iunknown, ref iidLocal, out var inspectable);
636
+ var hr = Marshal.QueryInterface(iunknown, in iidLocal, out var inspectable);
637
637
  if (hr == 0 && inspectable != IntPtr.Zero)
638
638
  {
639
639
  Marshal.Release(iunknown);
@@ -16,6 +16,14 @@
16
16
  host process is already running on net10. LatestMajor accepts any version >= 9. -->
17
17
  <RollForward>LatestMajor</RollForward>
18
18
  </PropertyGroup>
19
+ <ItemGroup>
20
+ <!-- The bridge only runs inside a Windows host, but the TFM stays plain net9.0 so the
21
+ net9.0 test/benchmark projects can reference it. Declaring the platform here keeps
22
+ CA1416 quiet for the Marshal COM APIs. Skipped when an OS-specific TFM already emits it. -->
23
+ <AssemblyAttribute Include="System.Runtime.Versioning.SupportedOSPlatformAttribute" Condition="'$(TargetPlatformIdentifier)' == ''">
24
+ <_Parameter1>windows</_Parameter1>
25
+ </AssemblyAttribute>
26
+ </ItemGroup>
19
27
  <Target Name="WriteDotNetToolDone" AfterTargets="Publish">
20
28
  <PropertyGroup>
21
29
  <DotNetToolDoneFile>$(MSBuildProjectDirectory)\publish\.dotnet_tool_done</DotNetToolDoneFile>
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.145",
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",