@nativescript/windows 0.1.0-alpha.11 → 0.1.0-alpha.13

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.
@@ -19,16 +19,44 @@ namespace __PROJECT_NAME__
19
19
  this.UnhandledException += OnUnhandledException;
20
20
  }
21
21
 
22
- protected override void OnLaunched(LaunchActivatedEventArgs e)
22
+ protected override async void OnLaunched(LaunchActivatedEventArgs e)
23
23
  {
24
24
  _runtimeHost.Initialize();
25
+
26
+ // Show crash report from the previous run if one exists.
27
+ try
28
+ {
29
+ var panicLogPath = System.IO.Path.Combine(
30
+ ApplicationData.Current.LocalFolder.Path, "nativescript-panic.log");
31
+ if (System.IO.File.Exists(panicLogPath))
32
+ {
33
+ var content = System.IO.File.ReadAllText(panicLogPath);
34
+ System.IO.File.Delete(panicLogPath);
35
+ if (!string.IsNullOrWhiteSpace(content))
36
+ await CrashDiagnostics.ShowCrashDialogAsync("Crash from previous run", content);
37
+ }
38
+ }
39
+ catch { }
40
+
41
+ string jsError = null;
25
42
  try
26
43
  {
27
44
  _runtimeHost.RunMainScript();
45
+ jsError = _runtimeHost.GetLastJsError();
46
+ if (!string.IsNullOrEmpty(jsError))
47
+ {
48
+ CrashDiagnostics.WriteMessage("JS Error", jsError);
49
+ var report = CrashDiagnostics.BuildErrorReport(null, jsError);
50
+ await CrashDiagnostics.ShowCrashDialogAsync("JavaScript Error", report);
51
+ }
28
52
  }
29
53
  catch (Exception scriptEx)
30
54
  {
55
+ jsError = _runtimeHost.GetLastJsError();
31
56
  System.Diagnostics.Debug.WriteLine($"[NativeScript] Script exception: {scriptEx.Message}");
57
+ CrashDiagnostics.WriteExceptionReport("RunMainScript", scriptEx, null);
58
+ var report = CrashDiagnostics.BuildErrorReport(scriptEx, jsError);
59
+ await CrashDiagnostics.ShowCrashDialogAsync("Script Execution Error", report);
32
60
  }
33
61
 
34
62
  #if DEBUG
@@ -66,10 +94,16 @@ namespace __PROJECT_NAME__
66
94
 
67
95
  private void OnUnhandledException(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e)
68
96
  {
97
+ e.Handled = true;
98
+ var jsError = _runtimeHost.GetLastJsError();
69
99
  CrashDiagnostics.WriteExceptionReport(
70
100
  "Xaml.UnhandledException",
71
101
  e.Exception,
72
- "Message=" + e.Message + "; Handled=" + e.Handled);
102
+ "JsError=" + (jsError ?? "<none>"));
103
+
104
+ var report = CrashDiagnostics.BuildErrorReport(e.Exception, jsError);
105
+ var _ = CrashDiagnostics.ShowCrashDialogAsync(
106
+ e.Message ?? "Unhandled exception", report);
73
107
  }
74
108
 
75
109
  #if DEBUG
@@ -2,7 +2,10 @@ using System;
2
2
  using System.IO;
3
3
  using System.Text;
4
4
  using System.Threading.Tasks;
5
+ using Windows.ApplicationModel.Core;
6
+ using Windows.ApplicationModel.DataTransfer;
5
7
  using Windows.Storage;
8
+ using Windows.UI.Popups;
6
9
 
7
10
  namespace __PROJECT_NAME__
8
11
  {
@@ -53,6 +56,118 @@ namespace __PROJECT_NAME__
53
56
  AppendToLog(sb.ToString());
54
57
  }
55
58
 
59
+ public static string BuildErrorReport(Exception ex, string jsError = null, string extraDetails = null)
60
+ {
61
+ var sb = new StringBuilder();
62
+
63
+ if (!string.IsNullOrWhiteSpace(jsError))
64
+ {
65
+ sb.AppendLine("── JavaScript Error ──────────────────────────────────────");
66
+ sb.AppendLine(jsError.Trim());
67
+ sb.AppendLine();
68
+ }
69
+
70
+ if (ex != null)
71
+ {
72
+ sb.AppendLine("── Native Exception ──────────────────────────────────────");
73
+ sb.AppendLine(ex.GetType().Name + ": " + ex.Message);
74
+ if (ex.StackTrace != null) sb.AppendLine(ex.StackTrace);
75
+ var inner = ex.InnerException;
76
+ while (inner != null)
77
+ {
78
+ sb.AppendLine("Caused by: " + inner.GetType().Name + ": " + inner.Message);
79
+ if (inner.StackTrace != null) sb.AppendLine(inner.StackTrace);
80
+ inner = inner.InnerException;
81
+ }
82
+ sb.AppendLine();
83
+ }
84
+
85
+ // Include panic log from previous or current run
86
+ try
87
+ {
88
+ var panicLog = Path.Combine(ApplicationData.Current.LocalFolder.Path, "nativescript-panic.log");
89
+ if (File.Exists(panicLog))
90
+ {
91
+ var content = File.ReadAllText(panicLog, Encoding.UTF8).Trim();
92
+ if (!string.IsNullOrEmpty(content))
93
+ {
94
+ sb.AppendLine("── Rust Panic Log ────────────────────────────────────────");
95
+ sb.AppendLine(content);
96
+ sb.AppendLine();
97
+ }
98
+ }
99
+ }
100
+ catch { }
101
+
102
+ if (!string.IsNullOrWhiteSpace(extraDetails))
103
+ {
104
+ sb.AppendLine("── Additional Info ───────────────────────────────────────");
105
+ sb.AppendLine(extraDetails);
106
+ sb.AppendLine();
107
+ }
108
+
109
+ sb.AppendLine("──────────────────────────────────────────────────────────");
110
+ sb.AppendLine("Timestamp: " + DateTimeOffset.UtcNow.ToString("o"));
111
+
112
+ return sb.ToString();
113
+ }
114
+
115
+ public static string CrashLogPath()
116
+ {
117
+ try { return Path.Combine(ApplicationData.Current.LocalFolder.Path, "nativescript-crash.log"); }
118
+ catch { return null; }
119
+ }
120
+
121
+ public static async Task ShowCrashDialogAsync(string heading, string errorReport)
122
+ {
123
+ try
124
+ {
125
+ // Write full details to log so developer can access them even if the
126
+ // dialog summary is truncated.
127
+ var logPath = CrashLogPath();
128
+ if (logPath != null)
129
+ File.WriteAllText(logPath, errorReport, Encoding.UTF8);
130
+
131
+ // Truncate for the dialog (MessageDialog has practical limits).
132
+ const int MaxLen = 800;
133
+ var summary = errorReport.Length > MaxLen
134
+ ? errorReport.Substring(0, MaxLen) + "\n\n[truncated — see log for full details]"
135
+ : errorReport;
136
+
137
+ if (logPath != null)
138
+ summary += "\n\nFull log: " + logPath;
139
+
140
+ var dialog = new MessageDialog(summary, "NativeScript Runtime Error");
141
+
142
+ dialog.Commands.Add(new UICommand("Copy Details", _ =>
143
+ {
144
+ try
145
+ {
146
+ var dp = new DataPackage();
147
+ dp.SetText(errorReport);
148
+ Clipboard.SetContent(dp);
149
+ }
150
+ catch { }
151
+ }));
152
+
153
+ dialog.Commands.Add(new UICommand("Restart App", async _ =>
154
+ {
155
+ try { await CoreApplication.RequestRestartAsync("crash-restart"); }
156
+ catch { }
157
+ }));
158
+
159
+ dialog.Commands.Add(new UICommand("Dismiss"));
160
+ dialog.DefaultCommandIndex = 0;
161
+ dialog.CancelCommandIndex = 2;
162
+
163
+ await dialog.ShowAsync();
164
+ }
165
+ catch (Exception ex)
166
+ {
167
+ System.Diagnostics.Debug.WriteLine("[NativeScript] Failed to show crash dialog: " + ex.Message);
168
+ }
169
+ }
170
+
56
171
  private static void AppendToLog(string content)
57
172
  {
58
173
  try
@@ -27,6 +27,18 @@ namespace __PROJECT_NAME__
27
27
  [DllImport(NativeScriptLibrary, EntryPoint = nameof(runtime_install_ctrlc_handler))]
28
28
  private static extern void runtime_install_ctrlc_handler(int exitCode);
29
29
 
30
+ [DllImport(NativeScriptLibrary, EntryPoint = nameof(runtime_set_local_folder))]
31
+ private static extern void runtime_set_local_folder([MarshalAs(UnmanagedType.LPUTF8Str)] string localFolder);
32
+
33
+ [DllImport(NativeScriptLibrary, EntryPoint = nameof(runtime_get_last_js_error))]
34
+ private static extern IntPtr runtime_get_last_js_error();
35
+
36
+ [DllImport(NativeScriptLibrary, EntryPoint = nameof(runtime_free_js_error))]
37
+ private static extern void runtime_free_js_error(IntPtr ptr);
38
+
39
+ [DllImport(NativeScriptLibrary, EntryPoint = nameof(runtime_has_devtools))]
40
+ private static extern bool runtime_has_devtools();
41
+
30
42
  #if DEBUG
31
43
  [DllImport(NativeScriptLibrary, EntryPoint = nameof(runtime_devtools_start))]
32
44
  private static extern IntPtr runtime_devtools_start(long runtime, ushort port);
@@ -39,17 +51,12 @@ namespace __PROJECT_NAME__
39
51
 
40
52
  public string DevtoolsFrontendUrl { get; private set; }
41
53
 
42
- private bool _devtoolsPumpAvailable = true;
54
+ private bool _devtoolsAvailable;
43
55
 
44
56
  public void PumpDevtools()
45
57
  {
46
- if (!_initialized || !_devtoolsPumpAvailable) return;
58
+ if (!_initialized || !_devtoolsAvailable) return;
47
59
  try { runtime_devtools_pump(_runtime); }
48
- catch (System.EntryPointNotFoundException)
49
- {
50
- // DLL built without devtools feature — stop trying.
51
- _devtoolsPumpAvailable = false;
52
- }
53
60
  catch (Exception ex)
54
61
  {
55
62
  System.Diagnostics.Debug.WriteLine($"[NativeScript DevTools] Pump failed: {ex.Message}");
@@ -58,6 +65,7 @@ namespace __PROJECT_NAME__
58
65
 
59
66
  private void StartDevtoolsSafely()
60
67
  {
68
+ if (!runtime_has_devtools()) return;
61
69
  IntPtr urlPtr = IntPtr.Zero;
62
70
  try
63
71
  {
@@ -68,7 +76,10 @@ namespace __PROJECT_NAME__
68
76
  ? $"devtools://devtools/bundled/inspector.html?ws={wsUrl.Replace("ws://", "")}"
69
77
  : null;
70
78
  if (DevtoolsFrontendUrl != null)
79
+ {
80
+ _devtoolsAvailable = true;
71
81
  System.Diagnostics.Debug.WriteLine($"[NativeScript DevTools] {DevtoolsFrontendUrl}");
82
+ }
72
83
  }
73
84
  catch (Exception ex)
74
85
  {
@@ -90,6 +101,7 @@ namespace __PROJECT_NAME__
90
101
  if (_initialized) return;
91
102
  AttachConsole(ATTACH_PARENT_PROCESS);
92
103
  runtime_install_ctrlc_handler(0);
104
+ runtime_set_local_folder(Windows.Storage.ApplicationData.Current.LocalFolder.Path);
93
105
  _runtime = runtime_init(AppContext.BaseDirectory);
94
106
  #if DEBUG
95
107
  if (ConsumeDebugBreakMarker())
@@ -234,6 +246,24 @@ namespace __PROJECT_NAME__
234
246
  return null;
235
247
  }
236
248
 
249
+ /// Returns the last JavaScript error (message + stack trace) captured during
250
+ /// script execution, or null if no error was recorded since the last call.
251
+ public string GetLastJsError()
252
+ {
253
+ if (!_initialized) return null;
254
+ IntPtr ptr = IntPtr.Zero;
255
+ try
256
+ {
257
+ ptr = runtime_get_last_js_error();
258
+ return ptr == IntPtr.Zero ? null : Marshal.PtrToStringUTF8(ptr);
259
+ }
260
+ catch { return null; }
261
+ finally
262
+ {
263
+ if (ptr != IntPtr.Zero) runtime_free_js_error(ptr);
264
+ }
265
+ }
266
+
237
267
  public void Dispose()
238
268
  {
239
269
  if (!_initialized) return;
@@ -25,6 +25,10 @@
25
25
  <NSLibPlatform Condition="'$(Platform)' != ''">$(Platform)</NSLibPlatform>
26
26
  <NSLibPlatform Condition="'$(NSLibPlatform)' == '' and '$(RuntimeIdentifier)' != ''">$([System.Text.RegularExpressions.Regex]::Replace('$(RuntimeIdentifier)','^win-',''))</NSLibPlatform>
27
27
  <NSLibPlatform Condition="'$(NSLibPlatform)' == ''">x64</NSLibPlatform>
28
+ <!-- Windows SDK .NET runtime pack location (resolved from NuGet cache) -->
29
+ <_WinSdkNetRefPkg>$(NuGetPackageRoot)microsoft.windows.sdk.net.ref</_WinSdkNetRefPkg>
30
+ <_WinSdkNetRefVer Condition="Exists('$(_WinSdkNetRefPkg)\10.0.26100.57')">10.0.26100.57</_WinSdkNetRefVer>
31
+ <_WinSdkNetRefLib Condition="'$(_WinSdkNetRefVer)' != ''">$(_WinSdkNetRefPkg)\$(_WinSdkNetRefVer)\lib\net8.0</_WinSdkNetRefLib>
28
32
  </PropertyGroup>
29
33
 
30
34
  <ItemGroup>
@@ -46,6 +50,24 @@
46
50
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
47
51
  </Content>
48
52
 
53
+ <!-- Windows SDK .NET runtime pack assemblies — required when the dotnet workload
54
+ is not installed; copied from the NuGet package cache. -->
55
+ <Content Include="$(_WinSdkNetRefLib)\Microsoft.Windows.UI.Xaml.dll"
56
+ Condition="'$(_WinSdkNetRefLib)' != '' and Exists('$(_WinSdkNetRefLib)\Microsoft.Windows.UI.Xaml.dll')">
57
+ <Link>Microsoft.Windows.UI.Xaml.dll</Link>
58
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
59
+ </Content>
60
+ <Content Include="$(_WinSdkNetRefLib)\WinRT.Runtime.dll"
61
+ Condition="'$(_WinSdkNetRefLib)' != '' and Exists('$(_WinSdkNetRefLib)\WinRT.Runtime.dll')">
62
+ <Link>WinRT.Runtime.dll</Link>
63
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
64
+ </Content>
65
+ <Content Include="$(_WinSdkNetRefLib)\Microsoft.Windows.SDK.NET.dll"
66
+ Condition="'$(_WinSdkNetRefLib)' != '' and Exists('$(_WinSdkNetRefLib)\Microsoft.Windows.SDK.NET.dll')">
67
+ <Link>Microsoft.Windows.SDK.NET.dll</Link>
68
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
69
+ </Content>
70
+
49
71
  <!-- Debug: devtools-enabled runtime DLL (platform fallback via NSLibPlatform) -->
50
72
  <Content Include="$(NSWindowsRoot)\libs\devtools\$(NSLibPlatform)\nativescript.dll"
51
73
  Condition="'$(Configuration)' == 'Debug' and Exists('$(NSWindowsRoot)\libs\devtools\$(NSLibPlatform)\nativescript.dll')">
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nativescript/windows",
3
- "version": "0.1.0-alpha.11",
3
+ "version": "0.1.0-alpha.13",
4
4
  "description": "NativeScript for using Windows v8",
5
5
  "repository": {
6
6
  "type": "git",