@nativescript/windows 0.1.0-alpha.8 → 0.1.0-alpha.81
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 +44 -2
- package/framework/__PROJECT_NAME__/App.xaml.cs +67 -22
- package/framework/__PROJECT_NAME__/Assets/SplashScreen.png +0 -0
- package/framework/__PROJECT_NAME__/Assets/Square150x150Logo.png +0 -0
- package/framework/__PROJECT_NAME__/Assets/Square44x44Logo.png +0 -0
- package/framework/__PROJECT_NAME__/Assets/StoreLogo.png +0 -0
- package/framework/__PROJECT_NAME__/Assets/Wide310x150Logo.png +0 -0
- package/framework/__PROJECT_NAME__/CrashDiagnostics.cs +262 -66
- package/framework/__PROJECT_NAME__/Directory.Build.props +15 -0
- package/framework/__PROJECT_NAME__/Directory.Build.targets +153 -0
- package/framework/__PROJECT_NAME__/Package.appxmanifest +2 -5
- package/framework/__PROJECT_NAME__/RuntimeHost.cs +97 -10
- package/framework/__PROJECT_NAME__/__PROJECT_NAME__.csproj +90 -17
- package/framework/dotnet-bridge/BinaryProtocol.cs +145 -0
- package/framework/dotnet-bridge/Bridge.BinaryDispatch.cs +216 -0
- package/framework/dotnet-bridge/Bridge.Dispatch.cs +468 -0
- package/framework/dotnet-bridge/Bridge.JsDelegate.cs +96 -0
- package/framework/dotnet-bridge/Bridge.TaskHelper.cs +207 -0
- package/framework/dotnet-bridge/Bridge.cs +402 -263
- package/framework/dotnet-bridge/DispatchTypes.cs +317 -0
- package/framework/dotnet-bridge/DotNetBridge.csproj +7 -1
- package/framework/libs/arm64/nativescript.dll +0 -0
- package/framework/libs/devtools/arm64/nativescript.dll +0 -0
- package/framework/libs/devtools/x64/nativescript.dll +0 -0
- package/framework/libs/x64/nativescript.dll +0 -0
- package/framework/tools/dotnet-tool-arm64.exe +0 -0
- package/framework/tools/dotnet-tool-x64.exe +0 -0
- package/framework/tools/dotnet-tool.exe +0 -0
- package/package.json +19 -19
package/build.ps1
CHANGED
|
@@ -119,19 +119,61 @@ foreach ($t in $Targets) {
|
|
|
119
119
|
|
|
120
120
|
if (-not $SkipRelease) {
|
|
121
121
|
Write-Host "`n=== Release ($arch) ===" -ForegroundColor Cyan
|
|
122
|
-
|
|
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
|
-
|
|
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
|
}
|
|
133
135
|
}
|
|
134
136
|
|
|
137
|
+
# ── dotnet-tool prebuilt binaries ────────────────────────────────────────────
|
|
138
|
+
Write-Host "`n=== Build dotnet-tool prebuilt binaries ===" -ForegroundColor Cyan
|
|
139
|
+
# Place prebuilt tools into the framework folder so they are included in the
|
|
140
|
+
# packaged framework (npm publish copies framework/* into the package root).
|
|
141
|
+
$ToolsDir = Join-Path $ScriptDir "framework\tools"
|
|
142
|
+
if (-not (Test-Path $ToolsDir)) { New-Item -ItemType Directory -Force -Path $ToolsDir | Out-Null }
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
foreach ($t in $Targets) {
|
|
146
|
+
$arch = $t.Arch
|
|
147
|
+
$rustTarget = $t.RustTarget
|
|
148
|
+
Write-Host "Building dotnet-tool for $arch ($rustTarget)..."
|
|
149
|
+
Push-Location $RepoRoot
|
|
150
|
+
try {
|
|
151
|
+
& cargo build -p dotnet-tool --release --target $rustTarget
|
|
152
|
+
$buildExit = $LASTEXITCODE
|
|
153
|
+
} finally {
|
|
154
|
+
Pop-Location
|
|
155
|
+
}
|
|
156
|
+
if ($buildExit -ne 0) {
|
|
157
|
+
Write-Host "cargo build for dotnet-tool failed for target $rustTarget (exit $buildExit). Skipping copy for $arch." -ForegroundColor Yellow
|
|
158
|
+
continue
|
|
159
|
+
}
|
|
160
|
+
$candidate = Join-Path $RepoRoot "target\$rustTarget\release\dotnet-tool.exe"
|
|
161
|
+
if (Test-Path $candidate) {
|
|
162
|
+
$dest = Join-Path $ToolsDir "dotnet-tool-$arch.exe"
|
|
163
|
+
Copy-Item -Force $candidate $dest
|
|
164
|
+
Write-Host " copied dotnet-tool -> $(Resolve-Path $dest -Relative)"
|
|
165
|
+
} else {
|
|
166
|
+
Write-Host "Expected build output not found: $candidate" -ForegroundColor Yellow
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
# Provide a generic `dotnet-tool.exe` fallback (copy x64 if available)
|
|
171
|
+
$x64Path = Join-Path $ToolsDir "dotnet-tool-x64.exe"
|
|
172
|
+
if (Test-Path $x64Path) {
|
|
173
|
+
Copy-Item -Force $x64Path (Join-Path $ToolsDir "dotnet-tool.exe")
|
|
174
|
+
Write-Host " copied dotnet-tool-x64.exe -> dotnet-tool.exe"
|
|
175
|
+
}
|
|
176
|
+
|
|
135
177
|
Write-Host ""
|
|
136
178
|
Write-Host "Done." -ForegroundColor Green
|
|
137
179
|
Write-Host ""
|
|
@@ -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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
71
|
+
Windows.UI.Xaml.Media.CompositionTarget.Rendering += OnRenderFrame;
|
|
72
|
+
|
|
73
|
+
if (Window.Current.Content == null)
|
|
41
74
|
{
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
"
|
|
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
|
-
|
|
120
|
+
_runtimeHost.PumpDevtools();
|
|
77
121
|
#endif
|
|
122
|
+
}
|
|
78
123
|
}
|
|
79
124
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,66 +1,262 @@
|
|
|
1
|
-
using System;
|
|
2
|
-
using System.IO;
|
|
3
|
-
using System.Text;
|
|
4
|
-
using System.
|
|
5
|
-
using
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
WriteExceptionReport("
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
sb
|
|
51
|
-
sb.AppendLine("
|
|
52
|
-
sb.AppendLine();
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
+
// Always mark the exception as observed to prevent the finalizer
|
|
32
|
+
// from rethrowing it on the finalizer thread.
|
|
33
|
+
try { args.SetObserved(); } catch { }
|
|
34
|
+
|
|
35
|
+
// Log the exception but never allow logging failures to propagate
|
|
36
|
+
// (this handler runs on the finalizer thread in some cases).
|
|
37
|
+
try
|
|
38
|
+
{
|
|
39
|
+
WriteExceptionReport("TaskScheduler.UnobservedTaskException", args.Exception, null);
|
|
40
|
+
}
|
|
41
|
+
catch (Exception logEx)
|
|
42
|
+
{
|
|
43
|
+
try { WriteToTraceLog("[CrashDiagnostics] Failed to write unobserved exception: " + logEx); } catch { }
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public static void WriteExceptionReport(string source, Exception ex, string details)
|
|
49
|
+
{
|
|
50
|
+
var sb = new StringBuilder();
|
|
51
|
+
sb.AppendLine("============================================================");
|
|
52
|
+
sb.AppendLine("Timestamp: " + DateTimeOffset.UtcNow.ToString("o"));
|
|
53
|
+
sb.AppendLine("Source: " + source);
|
|
54
|
+
if (!string.IsNullOrWhiteSpace(details)) sb.AppendLine("Details: " + details);
|
|
55
|
+
if (ex != null) { sb.AppendLine("Exception:"); sb.AppendLine(ex.ToString()); }
|
|
56
|
+
else sb.AppendLine("Exception: <null>");
|
|
57
|
+
sb.AppendLine("Managed stack snapshot:");
|
|
58
|
+
sb.AppendLine(Environment.StackTrace);
|
|
59
|
+
sb.AppendLine();
|
|
60
|
+
AppendToLog(sb.ToString());
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public static void WriteMessage(string source, string message)
|
|
64
|
+
{
|
|
65
|
+
var sb = new StringBuilder();
|
|
66
|
+
sb.AppendLine("============================================================");
|
|
67
|
+
sb.AppendLine("Timestamp: " + DateTimeOffset.UtcNow.ToString("o"));
|
|
68
|
+
sb.AppendLine("Source: " + source);
|
|
69
|
+
sb.AppendLine("Message: " + message);
|
|
70
|
+
sb.AppendLine();
|
|
71
|
+
AppendToLog(sb.ToString());
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public static string BuildErrorReport(Exception ex, string jsError = null, string extraDetails = null)
|
|
75
|
+
{
|
|
76
|
+
var sb = new StringBuilder();
|
|
77
|
+
|
|
78
|
+
if (!string.IsNullOrWhiteSpace(jsError))
|
|
79
|
+
{
|
|
80
|
+
sb.AppendLine("── JavaScript Error ──────────────────────────────────────");
|
|
81
|
+
sb.AppendLine(jsError.Trim());
|
|
82
|
+
sb.AppendLine();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (ex != null)
|
|
86
|
+
{
|
|
87
|
+
sb.AppendLine("── Native Exception ──────────────────────────────────────");
|
|
88
|
+
sb.AppendLine(ex.GetType().Name + ": " + ex.Message);
|
|
89
|
+
if (ex.StackTrace != null) sb.AppendLine(ex.StackTrace);
|
|
90
|
+
var inner = ex.InnerException;
|
|
91
|
+
while (inner != null)
|
|
92
|
+
{
|
|
93
|
+
sb.AppendLine("Caused by: " + inner.GetType().Name + ": " + inner.Message);
|
|
94
|
+
if (inner.StackTrace != null) sb.AppendLine(inner.StackTrace);
|
|
95
|
+
inner = inner.InnerException;
|
|
96
|
+
}
|
|
97
|
+
sb.AppendLine();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Include panic log from previous or current run
|
|
101
|
+
try
|
|
102
|
+
{
|
|
103
|
+
var panicLog = Path.Combine(ApplicationData.Current.LocalFolder.Path, "nativescript-panic.log");
|
|
104
|
+
if (File.Exists(panicLog))
|
|
105
|
+
{
|
|
106
|
+
var content = File.ReadAllText(panicLog, Encoding.UTF8).Trim();
|
|
107
|
+
if (!string.IsNullOrEmpty(content))
|
|
108
|
+
{
|
|
109
|
+
sb.AppendLine("── Rust Panic Log ────────────────────────────────────────");
|
|
110
|
+
sb.AppendLine(content);
|
|
111
|
+
sb.AppendLine();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
catch { }
|
|
116
|
+
|
|
117
|
+
if (!string.IsNullOrWhiteSpace(extraDetails))
|
|
118
|
+
{
|
|
119
|
+
sb.AppendLine("── Additional Info ───────────────────────────────────────");
|
|
120
|
+
sb.AppendLine(extraDetails);
|
|
121
|
+
sb.AppendLine();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
sb.AppendLine("──────────────────────────────────────────────────────────");
|
|
125
|
+
sb.AppendLine("Timestamp: " + DateTimeOffset.UtcNow.ToString("o"));
|
|
126
|
+
|
|
127
|
+
return sb.ToString();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
public static string CrashLogPath()
|
|
131
|
+
{
|
|
132
|
+
try { return Path.Combine(ApplicationData.Current.LocalFolder.Path, "nativescript-crash.log"); }
|
|
133
|
+
catch { return null; }
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/// Parses the first "path:line:col" source location from a JS stack trace.
|
|
137
|
+
/// Returns null if none found. Handles Windows drive-letter paths (C:\...).
|
|
138
|
+
public static (string file, int line, int col)? TryExtractSourceLocation(string errorReport)
|
|
139
|
+
{
|
|
140
|
+
if (string.IsNullOrEmpty(errorReport)) return null;
|
|
141
|
+
|
|
142
|
+
// Match the contents of the first (path:line:col) group in the stack trace.
|
|
143
|
+
var m = Regex.Match(errorReport, @"\(([^)]+)\)");
|
|
144
|
+
if (!m.Success) return null;
|
|
145
|
+
|
|
146
|
+
var inner = m.Groups[1].Value; // e.g. "C:\app\bundle.js:42:13"
|
|
147
|
+
|
|
148
|
+
// Parse col from the right (last :digits).
|
|
149
|
+
var lastColon = inner.LastIndexOf(':');
|
|
150
|
+
if (lastColon < 0 || !int.TryParse(inner.Substring(lastColon + 1), out int col)) return null;
|
|
151
|
+
inner = inner.Substring(0, lastColon);
|
|
152
|
+
|
|
153
|
+
// Parse line from the right (second-to-last :digits).
|
|
154
|
+
lastColon = inner.LastIndexOf(':');
|
|
155
|
+
if (lastColon < 0 || !int.TryParse(inner.Substring(lastColon + 1), out int line)) return null;
|
|
156
|
+
var file = inner.Substring(0, lastColon);
|
|
157
|
+
|
|
158
|
+
return string.IsNullOrEmpty(file) ? null : (file, line, col);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
public static async Task ShowCrashDialogAsync(string heading, string errorReport)
|
|
162
|
+
{
|
|
163
|
+
try
|
|
164
|
+
{
|
|
165
|
+
// Write full details to log so developer can access them even if the
|
|
166
|
+
// dialog summary is truncated.
|
|
167
|
+
var logPath = CrashLogPath();
|
|
168
|
+
if (logPath != null)
|
|
169
|
+
File.WriteAllText(logPath, errorReport, Encoding.UTF8);
|
|
170
|
+
|
|
171
|
+
// Truncate for the dialog (MessageDialog has practical limits).
|
|
172
|
+
const int MaxLen = 800;
|
|
173
|
+
var summary = errorReport.Length > MaxLen
|
|
174
|
+
? errorReport.Substring(0, MaxLen) + "\n\n[truncated — see log for full details]"
|
|
175
|
+
: errorReport;
|
|
176
|
+
|
|
177
|
+
if (logPath != null)
|
|
178
|
+
summary += "\n\nFull log: " + logPath;
|
|
179
|
+
|
|
180
|
+
var dialog = new MessageDialog(summary, "NativeScript Runtime Error");
|
|
181
|
+
|
|
182
|
+
// MessageDialog supports at most 3 commands. When a source location is
|
|
183
|
+
// available, swap "Copy Details" for "Open in VS Code" so the user can
|
|
184
|
+
// choose between jumping to the error or restarting. Full details are
|
|
185
|
+
// always written to the log file shown in the dialog text.
|
|
186
|
+
var srcLocation = TryExtractSourceLocation(errorReport);
|
|
187
|
+
if (srcLocation.HasValue)
|
|
188
|
+
{
|
|
189
|
+
var (srcFile, srcLine, srcCol) = srcLocation.Value;
|
|
190
|
+
dialog.Commands.Add(new UICommand("Open Source File", async _ =>
|
|
191
|
+
{
|
|
192
|
+
try
|
|
193
|
+
{
|
|
194
|
+
var normalizedPath = srcFile.Replace('\\', '/');
|
|
195
|
+
var uriStr = $"file:///{normalizedPath}";
|
|
196
|
+
if (Uri.TryCreate(uriStr, UriKind.Absolute, out var fileUri))
|
|
197
|
+
await Launcher.LaunchUriAsync(fileUri,
|
|
198
|
+
new LauncherOptions { DisplayApplicationPicker = true });
|
|
199
|
+
}
|
|
200
|
+
catch { }
|
|
201
|
+
}));
|
|
202
|
+
}
|
|
203
|
+
else
|
|
204
|
+
{
|
|
205
|
+
dialog.Commands.Add(new UICommand("Copy Details", _ =>
|
|
206
|
+
{
|
|
207
|
+
try
|
|
208
|
+
{
|
|
209
|
+
var dp = new DataPackage();
|
|
210
|
+
dp.SetText(errorReport);
|
|
211
|
+
Clipboard.SetContent(dp);
|
|
212
|
+
}
|
|
213
|
+
catch { }
|
|
214
|
+
}));
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
dialog.Commands.Add(new UICommand("Restart App", async _ =>
|
|
218
|
+
{
|
|
219
|
+
try { await CoreApplication.RequestRestartAsync("crash-restart"); }
|
|
220
|
+
catch { }
|
|
221
|
+
}));
|
|
222
|
+
|
|
223
|
+
dialog.Commands.Add(new UICommand("Dismiss"));
|
|
224
|
+
dialog.DefaultCommandIndex = 0;
|
|
225
|
+
dialog.CancelCommandIndex = 2;
|
|
226
|
+
|
|
227
|
+
await dialog.ShowAsync();
|
|
228
|
+
}
|
|
229
|
+
catch (Exception ex)
|
|
230
|
+
{
|
|
231
|
+
System.Diagnostics.Debug.WriteLine("[NativeScript] Failed to show crash dialog: " + ex.Message);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/// <summary>
|
|
236
|
+
/// Appends <paramref name="message"/> to ns_trace.log using the Win32 temp path.
|
|
237
|
+
/// Inside UWP, GetTempPath() virtualises to AC\Temp — the same folder Rust's
|
|
238
|
+
/// std::env::temp_dir() uses — so this write appears in the CLI's log stream.
|
|
239
|
+
/// </summary>
|
|
240
|
+
public static void WriteToTraceLog(string message)
|
|
241
|
+
{
|
|
242
|
+
try
|
|
243
|
+
{
|
|
244
|
+
// System.IO.Path.GetTempPath() calls Win32 GetTempPathW() which inside a
|
|
245
|
+
// UWP process returns the container's AC\Temp folder, matching Rust.
|
|
246
|
+
var tracePath = Path.Combine(System.IO.Path.GetTempPath(), "ns_trace.log");
|
|
247
|
+
File.AppendAllText(tracePath, message, Encoding.UTF8);
|
|
248
|
+
}
|
|
249
|
+
catch { }
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
private static void AppendToLog(string content)
|
|
253
|
+
{
|
|
254
|
+
try
|
|
255
|
+
{
|
|
256
|
+
var logPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "nativescript-crash.log");
|
|
257
|
+
File.AppendAllText(logPath, content, Encoding.UTF8);
|
|
258
|
+
}
|
|
259
|
+
catch { }
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
2
|
+
<!-- Default property values for manifest overrides.
|
|
3
|
+
Override these in Directory.Build.props or via /p: properties. -->
|
|
4
|
+
<PropertyGroup>
|
|
5
|
+
<AppDisplayName Condition=" '$(AppDisplayName)' == '' ">$(MSBuildProjectName)</AppDisplayName>
|
|
6
|
+
<AppDescription Condition=" '$(AppDescription)' == '' ">A NativeScript Windows application</AppDescription>
|
|
7
|
+
<Square150x150Logo Condition=" '$(Square150x150Logo)' == '' ">Assets\Square150x150Logo.png</Square150x150Logo>
|
|
8
|
+
<Square44x44Logo Condition=" '$(Square44x44Logo)' == '' ">Assets\Square44x44Logo.png</Square44x44Logo>
|
|
9
|
+
<Wide310x150Logo Condition=" '$(Wide310x150Logo)' == '' ">Assets\Wide310x150Logo.png</Wide310x150Logo>
|
|
10
|
+
<StoreLogo Condition=" '$(StoreLogo)' == '' ">Assets\StoreLogo.png</StoreLogo>
|
|
11
|
+
<LockScreenLogo Condition=" '$(LockScreenLogo)' == '' ">Assets\LockScreenLogo.png</LockScreenLogo>
|
|
12
|
+
<SplashBackgroundColor Condition=" '$(SplashBackgroundColor)' == '' ">#65ADF1</SplashBackgroundColor>
|
|
13
|
+
<SplashImage Condition=" '$(SplashImage)' == '' ">Assets\SplashScreen.png</SplashImage>
|
|
14
|
+
</PropertyGroup>
|
|
15
|
+
</Project>
|