@nativescript/windows 0.1.0-alpha.21 → 0.1.0-alpha.23

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.
@@ -1,10 +1,12 @@
1
1
  using System;
2
2
  using System.IO;
3
3
  using System.Text;
4
+ using System.Text.RegularExpressions;
4
5
  using System.Threading.Tasks;
5
6
  using Windows.ApplicationModel.Core;
6
7
  using Windows.ApplicationModel.DataTransfer;
7
8
  using Windows.Storage;
9
+ using Windows.System;
8
10
  using Windows.UI.Popups;
9
11
 
10
12
  namespace __PROJECT_NAME__
@@ -118,6 +120,31 @@ namespace __PROJECT_NAME__
118
120
  catch { return null; }
119
121
  }
120
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
+
121
148
  public static async Task ShowCrashDialogAsync(string heading, string errorReport)
122
149
  {
123
150
  try
@@ -139,16 +166,40 @@ namespace __PROJECT_NAME__
139
166
 
140
167
  var dialog = new MessageDialog(summary, "NativeScript Runtime Error");
141
168
 
142
- dialog.Commands.Add(new UICommand("Copy Details", _ =>
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)
143
175
  {
144
- try
176
+ var (srcFile, srcLine, srcCol) = srcLocation.Value;
177
+ dialog.Commands.Add(new UICommand("Open Source File", async _ =>
145
178
  {
146
- var dp = new DataPackage();
147
- dp.SetText(errorReport);
148
- Clipboard.SetContent(dp);
149
- }
150
- catch { }
151
- }));
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
+ }
152
203
 
153
204
  dialog.Commands.Add(new UICommand("Restart App", async _ =>
154
205
  {
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nativescript/windows",
3
- "version": "0.1.0-alpha.21",
3
+ "version": "0.1.0-alpha.23",
4
4
  "description": "NativeScript for using Windows v8",
5
5
  "repository": {
6
6
  "type": "git",