@nativescript/windows 0.1.0-alpha.5 → 0.1.0-alpha.50

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.
package/build.ps1 CHANGED
@@ -119,14 +119,16 @@ foreach ($t in $Targets) {
119
119
 
120
120
  if (-not $SkipRelease) {
121
121
  Write-Host "`n=== Release ($arch) ===" -ForegroundColor Cyan
122
- Build-Crate -Profile "release" -Target $rustTarget
122
+ $releaseArgs = @()
123
+ Build-Crate -Profile "release" -Target $rustTarget -ExtraArgs $releaseArgs
123
124
  $dll = Join-Path $RepoRoot "target\$rustTarget\release\nativescript.dll"
124
125
  Copy-Dll -Src $dll -Dest (Join-Path $FrameworkLibs "$arch\nativescript.dll")
125
126
  }
126
127
 
127
128
  if (-not $SkipDevtools) {
128
129
  Write-Host "`n=== Release-with-devtools ($arch) ===" -ForegroundColor Cyan
129
- Build-Crate -Profile "release-with-devtools" -Target $rustTarget -ExtraArgs @("--features", "devtools")
130
+ $devtoolsArgs = @("--features", "devtools")
131
+ Build-Crate -Profile "release-with-devtools" -Target $rustTarget -ExtraArgs $devtoolsArgs
130
132
  $dll = Join-Path $RepoRoot "target\$rustTarget\release-with-devtools\nativescript.dll"
131
133
  Copy-Dll -Src $dll -Dest (Join-Path $FrameworkLibs "devtools\$arch\nativescript.dll")
132
134
  }
@@ -19,46 +19,80 @@ 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
+ // Capture before any await — continuations may resume on a thread pool thread.
27
+ var dispatcher = Window.Current.Dispatcher;
28
+
29
+ // Show crash report from the previous run if one exists.
30
+ try
31
+ {
32
+ var panicLogPath = System.IO.Path.Combine(
33
+ ApplicationData.Current.LocalFolder.Path, "nativescript-panic.log");
34
+ if (System.IO.File.Exists(panicLogPath))
35
+ {
36
+ var content = System.IO.File.ReadAllText(panicLogPath);
37
+ System.IO.File.Delete(panicLogPath);
38
+ if (!string.IsNullOrWhiteSpace(content))
39
+ await CrashDiagnostics.ShowCrashDialogAsync("Crash from previous run", content);
40
+ }
41
+ }
42
+ catch { }
43
+
44
+ string jsError = null;
25
45
  try
26
46
  {
27
47
  _runtimeHost.RunMainScript();
48
+ jsError = _runtimeHost.GetLastJsError();
49
+ if (!string.IsNullOrEmpty(jsError))
50
+ {
51
+ CrashDiagnostics.WriteMessage("JS Error", jsError);
52
+ var report = CrashDiagnostics.BuildErrorReport(null, jsError);
53
+ CrashDiagnostics.WriteToTraceLog(report);
54
+ await CrashDiagnostics.ShowCrashDialogAsync("JavaScript Error", report);
55
+ }
28
56
  }
29
57
  catch (Exception scriptEx)
30
58
  {
59
+ jsError = _runtimeHost.GetLastJsError();
31
60
  System.Diagnostics.Debug.WriteLine($"[NativeScript] Script exception: {scriptEx.Message}");
61
+ CrashDiagnostics.WriteExceptionReport("RunMainScript", scriptEx, null);
62
+ var report = CrashDiagnostics.BuildErrorReport(scriptEx, jsError);
63
+ CrashDiagnostics.WriteToTraceLog(report);
64
+ await CrashDiagnostics.ShowCrashDialogAsync("Script Execution Error", report);
32
65
  }
33
66
 
34
- #if DEBUG
35
- Windows.UI.Xaml.Media.CompositionTarget.Rendering += OnRenderFrame;
36
- #endif
37
-
38
- if (Window.Current.Content == null)
67
+ // After any await, the continuation may run on a thread pool thread.
68
+ // Schedule all UI-thread-required operations through the dispatcher.
69
+ _ = dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
39
70
  {
40
- Window.Current.Content = new Windows.UI.Xaml.Controls.TextBlock
71
+ Windows.UI.Xaml.Media.CompositionTarget.Rendering += OnRenderFrame;
72
+
73
+ if (Window.Current.Content == null)
41
74
  {
42
- Text = "NativeScript runtime initialized but no UI was rendered.\n" +
43
- "Check the Output window for JS errors.",
44
- Margin = new Windows.UI.Xaml.Thickness(20),
45
- TextWrapping = Windows.UI.Xaml.TextWrapping.Wrap,
46
- FontSize = 16,
47
- };
48
- }
75
+ Window.Current.Content = new Windows.UI.Xaml.Controls.TextBlock
76
+ {
77
+ Text = "NativeScript runtime initialized but no UI was rendered.\n" +
78
+ "Check the Output window for JS errors.",
79
+ Margin = new Windows.UI.Xaml.Thickness(20),
80
+ TextWrapping = Windows.UI.Xaml.TextWrapping.Wrap,
81
+ FontSize = 16,
82
+ };
83
+ }
49
84
 
50
- if (!e.PrelaunchActivated)
51
- {
52
- Window.Current.Activate();
53
- }
85
+ if (!e.PrelaunchActivated)
86
+ {
87
+ Window.Current.Activate();
88
+ }
89
+ });
54
90
  }
55
91
 
56
92
  private void OnSuspending(object sender, SuspendingEventArgs e)
57
93
  {
58
94
  var deferral = e.SuspendingOperation.GetDeferral();
59
- #if DEBUG
60
95
  Windows.UI.Xaml.Media.CompositionTarget.Rendering -= OnRenderFrame;
61
- #endif
62
96
  ApplicationData.Current.LocalSettings.Values[LastLaunchArgsKey] = string.Empty;
63
97
  _runtimeHost.Dispose();
64
98
  deferral.Complete();
@@ -66,14 +100,25 @@ namespace __PROJECT_NAME__
66
100
 
67
101
  private void OnUnhandledException(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e)
68
102
  {
103
+ e.Handled = true;
104
+ var jsError = _runtimeHost.GetLastJsError();
69
105
  CrashDiagnostics.WriteExceptionReport(
70
106
  "Xaml.UnhandledException",
71
107
  e.Exception,
72
- "Message=" + e.Message + "; Handled=" + e.Handled);
108
+ "JsError=" + (jsError ?? "<none>"));
109
+
110
+ var report = CrashDiagnostics.BuildErrorReport(e.Exception, jsError);
111
+ CrashDiagnostics.WriteToTraceLog(report);
112
+ var _ = CrashDiagnostics.ShowCrashDialogAsync(
113
+ e.Message ?? "Unhandled exception", report);
73
114
  }
74
115
 
116
+ private void OnRenderFrame(object sender, object e)
117
+ {
118
+ _runtimeHost.PumpTimers();
75
119
  #if DEBUG
76
- private void OnRenderFrame(object sender, object e) => _runtimeHost.PumpDevtools();
120
+ _runtimeHost.PumpDevtools();
77
121
  #endif
122
+ }
78
123
  }
79
124
  }
@@ -1,66 +1,249 @@
1
- using System;
2
- using System.IO;
3
- using System.Text;
4
- using System.Threading.Tasks;
5
- using Windows.Storage;
6
-
7
- namespace __PROJECT_NAME__
8
- {
9
- internal static class CrashDiagnostics
10
- {
11
- private static bool _installed;
12
-
13
- public static void InstallGlobalHandlers()
14
- {
15
- if (_installed) return;
16
- _installed = true;
17
-
18
- AppDomain.CurrentDomain.UnhandledException += (_, args) =>
19
- {
20
- var ex = args.ExceptionObject as Exception;
21
- WriteExceptionReport("AppDomain.UnhandledException", ex, "IsTerminating=" + args.IsTerminating);
22
- };
23
-
24
- TaskScheduler.UnobservedTaskException += (_, args) =>
25
- {
26
- WriteExceptionReport("TaskScheduler.UnobservedTaskException", args.Exception, null);
27
- };
28
- }
29
-
30
- public static void WriteExceptionReport(string source, Exception ex, string details)
31
- {
32
- var sb = new StringBuilder();
33
- sb.AppendLine("============================================================");
34
- sb.AppendLine("Timestamp: " + DateTimeOffset.UtcNow.ToString("o"));
35
- sb.AppendLine("Source: " + source);
36
- if (!string.IsNullOrWhiteSpace(details)) sb.AppendLine("Details: " + details);
37
- if (ex != null) { sb.AppendLine("Exception:"); sb.AppendLine(ex.ToString()); }
38
- else sb.AppendLine("Exception: <null>");
39
- sb.AppendLine("Managed stack snapshot:");
40
- sb.AppendLine(Environment.StackTrace);
41
- sb.AppendLine();
42
- AppendToLog(sb.ToString());
43
- }
44
-
45
- public static void WriteMessage(string source, string message)
46
- {
47
- var sb = new StringBuilder();
48
- sb.AppendLine("============================================================");
49
- sb.AppendLine("Timestamp: " + DateTimeOffset.UtcNow.ToString("o"));
50
- sb.AppendLine("Source: " + source);
51
- sb.AppendLine("Message: " + message);
52
- sb.AppendLine();
53
- AppendToLog(sb.ToString());
54
- }
55
-
56
- private static void AppendToLog(string content)
57
- {
58
- try
59
- {
60
- var logPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "nativescript-crash.log");
61
- File.AppendAllText(logPath, content, Encoding.UTF8);
62
- }
63
- catch { }
64
- }
65
- }
66
- }
1
+ using System;
2
+ using System.IO;
3
+ using System.Text;
4
+ using System.Text.RegularExpressions;
5
+ using System.Threading.Tasks;
6
+ using Windows.ApplicationModel.Core;
7
+ using Windows.ApplicationModel.DataTransfer;
8
+ using Windows.Storage;
9
+ using Windows.System;
10
+ using Windows.UI.Popups;
11
+
12
+ namespace __PROJECT_NAME__
13
+ {
14
+ internal static class CrashDiagnostics
15
+ {
16
+ private static bool _installed;
17
+
18
+ public static void InstallGlobalHandlers()
19
+ {
20
+ if (_installed) return;
21
+ _installed = true;
22
+
23
+ AppDomain.CurrentDomain.UnhandledException += (_, args) =>
24
+ {
25
+ var ex = args.ExceptionObject as Exception;
26
+ WriteExceptionReport("AppDomain.UnhandledException", ex, "IsTerminating=" + args.IsTerminating);
27
+ };
28
+
29
+ TaskScheduler.UnobservedTaskException += (_, args) =>
30
+ {
31
+ WriteExceptionReport("TaskScheduler.UnobservedTaskException", args.Exception, null);
32
+ };
33
+ }
34
+
35
+ public static void WriteExceptionReport(string source, Exception ex, string details)
36
+ {
37
+ var sb = new StringBuilder();
38
+ sb.AppendLine("============================================================");
39
+ sb.AppendLine("Timestamp: " + DateTimeOffset.UtcNow.ToString("o"));
40
+ sb.AppendLine("Source: " + source);
41
+ if (!string.IsNullOrWhiteSpace(details)) sb.AppendLine("Details: " + details);
42
+ if (ex != null) { sb.AppendLine("Exception:"); sb.AppendLine(ex.ToString()); }
43
+ else sb.AppendLine("Exception: <null>");
44
+ sb.AppendLine("Managed stack snapshot:");
45
+ sb.AppendLine(Environment.StackTrace);
46
+ sb.AppendLine();
47
+ AppendToLog(sb.ToString());
48
+ }
49
+
50
+ public static void WriteMessage(string source, string message)
51
+ {
52
+ var sb = new StringBuilder();
53
+ sb.AppendLine("============================================================");
54
+ sb.AppendLine("Timestamp: " + DateTimeOffset.UtcNow.ToString("o"));
55
+ sb.AppendLine("Source: " + source);
56
+ sb.AppendLine("Message: " + message);
57
+ sb.AppendLine();
58
+ AppendToLog(sb.ToString());
59
+ }
60
+
61
+ public static string BuildErrorReport(Exception ex, string jsError = null, string extraDetails = null)
62
+ {
63
+ var sb = new StringBuilder();
64
+
65
+ if (!string.IsNullOrWhiteSpace(jsError))
66
+ {
67
+ sb.AppendLine("── JavaScript Error ──────────────────────────────────────");
68
+ sb.AppendLine(jsError.Trim());
69
+ sb.AppendLine();
70
+ }
71
+
72
+ if (ex != null)
73
+ {
74
+ sb.AppendLine("── Native Exception ──────────────────────────────────────");
75
+ sb.AppendLine(ex.GetType().Name + ": " + ex.Message);
76
+ if (ex.StackTrace != null) sb.AppendLine(ex.StackTrace);
77
+ var inner = ex.InnerException;
78
+ while (inner != null)
79
+ {
80
+ sb.AppendLine("Caused by: " + inner.GetType().Name + ": " + inner.Message);
81
+ if (inner.StackTrace != null) sb.AppendLine(inner.StackTrace);
82
+ inner = inner.InnerException;
83
+ }
84
+ sb.AppendLine();
85
+ }
86
+
87
+ // Include panic log from previous or current run
88
+ try
89
+ {
90
+ var panicLog = Path.Combine(ApplicationData.Current.LocalFolder.Path, "nativescript-panic.log");
91
+ if (File.Exists(panicLog))
92
+ {
93
+ var content = File.ReadAllText(panicLog, Encoding.UTF8).Trim();
94
+ if (!string.IsNullOrEmpty(content))
95
+ {
96
+ sb.AppendLine("── Rust Panic Log ────────────────────────────────────────");
97
+ sb.AppendLine(content);
98
+ sb.AppendLine();
99
+ }
100
+ }
101
+ }
102
+ catch { }
103
+
104
+ if (!string.IsNullOrWhiteSpace(extraDetails))
105
+ {
106
+ sb.AppendLine("── Additional Info ───────────────────────────────────────");
107
+ sb.AppendLine(extraDetails);
108
+ sb.AppendLine();
109
+ }
110
+
111
+ sb.AppendLine("──────────────────────────────────────────────────────────");
112
+ sb.AppendLine("Timestamp: " + DateTimeOffset.UtcNow.ToString("o"));
113
+
114
+ return sb.ToString();
115
+ }
116
+
117
+ public static string CrashLogPath()
118
+ {
119
+ try { return Path.Combine(ApplicationData.Current.LocalFolder.Path, "nativescript-crash.log"); }
120
+ catch { return null; }
121
+ }
122
+
123
+ /// Parses the first "path:line:col" source location from a JS stack trace.
124
+ /// Returns null if none found. Handles Windows drive-letter paths (C:\...).
125
+ public static (string file, int line, int col)? TryExtractSourceLocation(string errorReport)
126
+ {
127
+ if (string.IsNullOrEmpty(errorReport)) return null;
128
+
129
+ // Match the contents of the first (path:line:col) group in the stack trace.
130
+ var m = Regex.Match(errorReport, @"\(([^)]+)\)");
131
+ if (!m.Success) return null;
132
+
133
+ var inner = m.Groups[1].Value; // e.g. "C:\app\bundle.js:42:13"
134
+
135
+ // Parse col from the right (last :digits).
136
+ var lastColon = inner.LastIndexOf(':');
137
+ if (lastColon < 0 || !int.TryParse(inner.Substring(lastColon + 1), out int col)) return null;
138
+ inner = inner.Substring(0, lastColon);
139
+
140
+ // Parse line from the right (second-to-last :digits).
141
+ lastColon = inner.LastIndexOf(':');
142
+ if (lastColon < 0 || !int.TryParse(inner.Substring(lastColon + 1), out int line)) return null;
143
+ var file = inner.Substring(0, lastColon);
144
+
145
+ return string.IsNullOrEmpty(file) ? null : (file, line, col);
146
+ }
147
+
148
+ public static async Task ShowCrashDialogAsync(string heading, string errorReport)
149
+ {
150
+ try
151
+ {
152
+ // Write full details to log so developer can access them even if the
153
+ // dialog summary is truncated.
154
+ var logPath = CrashLogPath();
155
+ if (logPath != null)
156
+ File.WriteAllText(logPath, errorReport, Encoding.UTF8);
157
+
158
+ // Truncate for the dialog (MessageDialog has practical limits).
159
+ const int MaxLen = 800;
160
+ var summary = errorReport.Length > MaxLen
161
+ ? errorReport.Substring(0, MaxLen) + "\n\n[truncated — see log for full details]"
162
+ : errorReport;
163
+
164
+ if (logPath != null)
165
+ summary += "\n\nFull log: " + logPath;
166
+
167
+ var dialog = new MessageDialog(summary, "NativeScript Runtime Error");
168
+
169
+ // MessageDialog supports at most 3 commands. When a source location is
170
+ // available, swap "Copy Details" for "Open in VS Code" so the user can
171
+ // choose between jumping to the error or restarting. Full details are
172
+ // always written to the log file shown in the dialog text.
173
+ var srcLocation = TryExtractSourceLocation(errorReport);
174
+ if (srcLocation.HasValue)
175
+ {
176
+ var (srcFile, srcLine, srcCol) = srcLocation.Value;
177
+ dialog.Commands.Add(new UICommand("Open Source File", async _ =>
178
+ {
179
+ try
180
+ {
181
+ var normalizedPath = srcFile.Replace('\\', '/');
182
+ var uriStr = $"file:///{normalizedPath}";
183
+ if (Uri.TryCreate(uriStr, UriKind.Absolute, out var fileUri))
184
+ await Launcher.LaunchUriAsync(fileUri,
185
+ new LauncherOptions { DisplayApplicationPicker = true });
186
+ }
187
+ catch { }
188
+ }));
189
+ }
190
+ else
191
+ {
192
+ dialog.Commands.Add(new UICommand("Copy Details", _ =>
193
+ {
194
+ try
195
+ {
196
+ var dp = new DataPackage();
197
+ dp.SetText(errorReport);
198
+ Clipboard.SetContent(dp);
199
+ }
200
+ catch { }
201
+ }));
202
+ }
203
+
204
+ dialog.Commands.Add(new UICommand("Restart App", async _ =>
205
+ {
206
+ try { await CoreApplication.RequestRestartAsync("crash-restart"); }
207
+ catch { }
208
+ }));
209
+
210
+ dialog.Commands.Add(new UICommand("Dismiss"));
211
+ dialog.DefaultCommandIndex = 0;
212
+ dialog.CancelCommandIndex = 2;
213
+
214
+ await dialog.ShowAsync();
215
+ }
216
+ catch (Exception ex)
217
+ {
218
+ System.Diagnostics.Debug.WriteLine("[NativeScript] Failed to show crash dialog: " + ex.Message);
219
+ }
220
+ }
221
+
222
+ /// <summary>
223
+ /// Appends <paramref name="message"/> to ns_trace.log using the Win32 temp path.
224
+ /// Inside UWP, GetTempPath() virtualises to AC\Temp — the same folder Rust's
225
+ /// std::env::temp_dir() uses — so this write appears in the CLI's log stream.
226
+ /// </summary>
227
+ public static void WriteToTraceLog(string message)
228
+ {
229
+ try
230
+ {
231
+ // System.IO.Path.GetTempPath() calls Win32 GetTempPathW() which inside a
232
+ // UWP process returns the container's AC\Temp folder, matching Rust.
233
+ var tracePath = Path.Combine(System.IO.Path.GetTempPath(), "ns_trace.log");
234
+ File.AppendAllText(tracePath, message, Encoding.UTF8);
235
+ }
236
+ catch { }
237
+ }
238
+
239
+ private static void AppendToLog(string content)
240
+ {
241
+ try
242
+ {
243
+ var logPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "nativescript-crash.log");
244
+ File.AppendAllText(logPath, content, Encoding.UTF8);
245
+ }
246
+ catch { }
247
+ }
248
+ }
249
+ }
@@ -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>