@nativescript/windows 0.1.0-alpha.10 → 0.1.0-alpha.12

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
@@ -2,17 +2,14 @@
2
2
 
3
3
  <Package
4
4
  xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
5
- xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
6
5
  xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
7
- IgnorableNamespaces="uap mp">
6
+ IgnorableNamespaces="uap">
8
7
 
9
8
  <Identity
10
9
  Name="__APP_IDENTIFIER__"
11
10
  Publisher="CN=__PROJECT_NAME__"
12
11
  Version="1.0.0.0" />
13
12
 
14
- <mp:PhoneIdentity PhoneProductId="__APP_IDENTIFIER__" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
15
-
16
13
  <Properties>
17
14
  <DisplayName>__PROJECT_NAME__</DisplayName>
18
15
  <PublisherDisplayName>__PROJECT_NAME__</PublisherDisplayName>
@@ -24,7 +21,7 @@
24
21
  </Dependencies>
25
22
 
26
23
  <Resources>
27
- <Resource Language="x-generate"/>
24
+ <Resource Language="en-US"/>
28
25
  </Resources>
29
26
 
30
27
  <Applications>
@@ -27,6 +27,15 @@ 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
+
30
39
  #if DEBUG
31
40
  [DllImport(NativeScriptLibrary, EntryPoint = nameof(runtime_devtools_start))]
32
41
  private static extern IntPtr runtime_devtools_start(long runtime, ushort port);
@@ -39,10 +48,17 @@ namespace __PROJECT_NAME__
39
48
 
40
49
  public string DevtoolsFrontendUrl { get; private set; }
41
50
 
51
+ private bool _devtoolsPumpAvailable = true;
52
+
42
53
  public void PumpDevtools()
43
54
  {
44
- if (!_initialized) return;
55
+ if (!_initialized || !_devtoolsPumpAvailable) return;
45
56
  try { runtime_devtools_pump(_runtime); }
57
+ catch (System.EntryPointNotFoundException)
58
+ {
59
+ // DLL built without devtools feature — stop trying.
60
+ _devtoolsPumpAvailable = false;
61
+ }
46
62
  catch (Exception ex)
47
63
  {
48
64
  System.Diagnostics.Debug.WriteLine($"[NativeScript DevTools] Pump failed: {ex.Message}");
@@ -83,6 +99,7 @@ namespace __PROJECT_NAME__
83
99
  if (_initialized) return;
84
100
  AttachConsole(ATTACH_PARENT_PROCESS);
85
101
  runtime_install_ctrlc_handler(0);
102
+ runtime_set_local_folder(Windows.Storage.ApplicationData.Current.LocalFolder.Path);
86
103
  _runtime = runtime_init(AppContext.BaseDirectory);
87
104
  #if DEBUG
88
105
  if (ConsumeDebugBreakMarker())
@@ -227,6 +244,24 @@ namespace __PROJECT_NAME__
227
244
  return null;
228
245
  }
229
246
 
247
+ /// Returns the last JavaScript error (message + stack trace) captured during
248
+ /// script execution, or null if no error was recorded since the last call.
249
+ public string GetLastJsError()
250
+ {
251
+ if (!_initialized) return null;
252
+ IntPtr ptr = IntPtr.Zero;
253
+ try
254
+ {
255
+ ptr = runtime_get_last_js_error();
256
+ return ptr == IntPtr.Zero ? null : Marshal.PtrToStringUTF8(ptr);
257
+ }
258
+ catch { return null; }
259
+ finally
260
+ {
261
+ if (ptr != IntPtr.Zero) runtime_free_js_error(ptr);
262
+ }
263
+ }
264
+
230
265
  public void Dispose()
231
266
  {
232
267
  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>
@@ -41,6 +45,29 @@
41
45
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
42
46
  </Content>
43
47
 
48
+ <!-- UWP logo/splash assets required for Add-AppxPackage -Register -->
49
+ <Content Include="Assets\**\*" Condition="Exists('Assets')">
50
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
51
+ </Content>
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
+
44
71
  <!-- Debug: devtools-enabled runtime DLL (platform fallback via NSLibPlatform) -->
45
72
  <Content Include="$(NSWindowsRoot)\libs\devtools\$(NSLibPlatform)\nativescript.dll"
46
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.10",
3
+ "version": "0.1.0-alpha.12",
4
4
  "description": "NativeScript for using Windows v8",
5
5
  "repository": {
6
6
  "type": "git",