@devscholar/node-ps1-dotnet 0.0.0 → 0.0.2
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/README.md +3 -43
- package/__tests__/basic.test.ts +24 -0
- package/__tests__/dotnet-console.test.ts +30 -0
- package/__tests__/dotnet-enums.test.ts +55 -0
- package/__tests__/dotnet-io.test.ts +57 -0
- package/__tests__/dotnet-misc.test.ts +95 -0
- package/__tests__/dotnet-runtime.test.ts +99 -0
- package/__tests__/dotnet-task.test.ts +35 -0
- package/__tests__/gui-events.test.ts +147 -0
- package/__tests__/ipc.test.ts +43 -0
- package/__tests__/winforms.test.ts +136 -0
- package/__tests__/wpf.test.ts +135 -0
- package/docs/testing.md +30 -0
- package/jest.config.js +31 -0
- package/package.json +18 -5
- package/scripts/PsBridge/Reflection.cs +14 -0
- package/src/index.ts +53 -369
- package/src/namespace.ts +116 -0
- package/src/proxy.ts +330 -0
- package/src/state.ts +17 -0
- package/src/types.ts +2 -0
- package/test-utils.ts +64 -0
- package/tsconfig.json +15 -7
- package/tsconfig.tsbuildinfo +1 -0
- package/types/index.d.ts +17 -0
- package/types/ipc.d.ts +17 -0
- package/types/namespace.d.ts +2 -0
- package/types/proxy.d.ts +16 -0
- package/types/state.d.ts +16 -0
- package/types/types.d.ts +21 -0
- package/types/utils.d.ts +1 -0
- package/examples/console/await-delay/await-delay.ts +0 -14
- package/examples/console/console-input/console-input.ts +0 -18
- package/examples/winforms/counter/counter.ts +0 -47
- package/examples/winforms/drag-box/drag-box.ts +0 -62
- package/examples/wpf/counter/counter.ts +0 -55
- package/examples/wpf/drag-box/drag-box.ts +0 -84
- package/examples/wpf/webview2-browser/WebView2Libs/Microsoft.Web.WebView2.Core.dll +0 -0
- package/examples/wpf/webview2-browser/WebView2Libs/Microsoft.Web.WebView2.Core.dll.backup +0 -0
- package/examples/wpf/webview2-browser/WebView2Libs/Microsoft.Web.WebView2.Wpf.dll +0 -0
- package/examples/wpf/webview2-browser/WebView2Libs/Microsoft.Web.WebView2.Wpf.dll.backup +0 -0
- package/examples/wpf/webview2-browser/WebView2Libs/WebView2License.txt +0 -27
- package/examples/wpf/webview2-browser/counter.html +0 -31
- package/examples/wpf/webview2-browser/webview2-browser.ts +0 -90
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
// examples/winforms/drag-box/drag-box.ts
|
|
2
|
-
import dotnet from '../../../src/index.ts';
|
|
3
|
-
|
|
4
|
-
dotnet.load('System.Windows.Forms');
|
|
5
|
-
dotnet.load('System.Drawing');
|
|
6
|
-
|
|
7
|
-
const System = dotnet.System as any;
|
|
8
|
-
const Forms = System.Windows.Forms;
|
|
9
|
-
const Drawing = System.Drawing;
|
|
10
|
-
|
|
11
|
-
console.log("--- WinForms Draggable Box ---");
|
|
12
|
-
|
|
13
|
-
Forms.Application.EnableVisualStyles();
|
|
14
|
-
Forms.Application.SetCompatibleTextRenderingDefault(false);
|
|
15
|
-
|
|
16
|
-
const form = new Forms.Form();
|
|
17
|
-
form.Text = "Draggable Box Example (High Frequency IPC)";
|
|
18
|
-
form.Width = 800;
|
|
19
|
-
form.Height = 600;
|
|
20
|
-
form.StartPosition = 1; // CenterScreen
|
|
21
|
-
|
|
22
|
-
const box = new Forms.Panel();
|
|
23
|
-
box.BackColor = Drawing.Color.Red;
|
|
24
|
-
box.Width = 100;
|
|
25
|
-
box.Height = 100;
|
|
26
|
-
|
|
27
|
-
// Track position locally to avoid synchronous read overhead over IPC
|
|
28
|
-
let currentX = 350;
|
|
29
|
-
let currentY = 250;
|
|
30
|
-
box.Location = new Drawing.Point(currentX, currentY);
|
|
31
|
-
|
|
32
|
-
form.Controls.Add(box);
|
|
33
|
-
|
|
34
|
-
// State tracking for drag and drop
|
|
35
|
-
let isDragging = false;
|
|
36
|
-
let startDragOffsetX = 0;
|
|
37
|
-
let startDragOffsetY = 0;
|
|
38
|
-
|
|
39
|
-
box.add_MouseDown((sender: any, e: any) => {
|
|
40
|
-
isDragging = true;
|
|
41
|
-
startDragOffsetX = e.X;
|
|
42
|
-
startDragOffsetY = e.Y;
|
|
43
|
-
box.BackColor = Drawing.Color.DarkRed; // Visual feedback
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
box.add_MouseUp((sender: any, e: any) => {
|
|
47
|
-
isDragging = false;
|
|
48
|
-
box.BackColor = Drawing.Color.Red;
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
box.add_MouseMove((sender: any, e: any) => {
|
|
52
|
-
if (isDragging) {
|
|
53
|
-
currentX = currentX + e.X - startDragOffsetX;
|
|
54
|
-
currentY = currentY + e.Y - startDragOffsetY;
|
|
55
|
-
|
|
56
|
-
box.Left = currentX;
|
|
57
|
-
box.Top = currentY;
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
console.log("Initialization complete. Try dragging the red box!");
|
|
62
|
-
Forms.Application.Run(form);
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import dotnet from '../../../src/index.ts';
|
|
2
|
-
|
|
3
|
-
dotnet.load('PresentationFramework');
|
|
4
|
-
dotnet.load('PresentationCore');
|
|
5
|
-
dotnet.load('WindowsBase');
|
|
6
|
-
|
|
7
|
-
const System = dotnet.System as any;
|
|
8
|
-
const Windows = System.Windows;
|
|
9
|
-
const Controls = System.Windows.Controls;
|
|
10
|
-
const Media = System.Windows.Media;
|
|
11
|
-
|
|
12
|
-
let clickCount = 0;
|
|
13
|
-
|
|
14
|
-
console.log("--- WPF Counter ---");
|
|
15
|
-
|
|
16
|
-
const mainWindow = new Windows.Window();
|
|
17
|
-
mainWindow.Title = "WPF Counter App";
|
|
18
|
-
mainWindow.Width = 400;
|
|
19
|
-
mainWindow.Height = 300;
|
|
20
|
-
mainWindow.WindowStartupLocation = Windows.WindowStartupLocation.CenterScreen;
|
|
21
|
-
|
|
22
|
-
const stackPanel = new Controls.StackPanel();
|
|
23
|
-
stackPanel.Margin = new Windows.Thickness(20);
|
|
24
|
-
stackPanel.HorizontalAlignment = Windows.HorizontalAlignment.Center;
|
|
25
|
-
stackPanel.VerticalAlignment = Windows.VerticalAlignment.Center;
|
|
26
|
-
|
|
27
|
-
const label = new Controls.Label();
|
|
28
|
-
label.Content = "Clicks: 0";
|
|
29
|
-
label.FontSize = 32;
|
|
30
|
-
label.FontFamily = new Media.FontFamily("Arial");
|
|
31
|
-
label.HorizontalContentAlignment = Windows.HorizontalAlignment.Center;
|
|
32
|
-
label.Margin = new Windows.Thickness(0, 0, 0, 20);
|
|
33
|
-
stackPanel.Children.Add(label);
|
|
34
|
-
|
|
35
|
-
const button = new Controls.Button();
|
|
36
|
-
button.Content = "Click to Add";
|
|
37
|
-
button.FontSize = 18;
|
|
38
|
-
button.Padding = new Windows.Thickness(20, 10, 20, 10);
|
|
39
|
-
button.HorizontalAlignment = Windows.HorizontalAlignment.Center;
|
|
40
|
-
|
|
41
|
-
button.add_Click((sender: any, e: any) => {
|
|
42
|
-
clickCount++;
|
|
43
|
-
const message = `Clicked ${clickCount} times`;
|
|
44
|
-
label.Content = message;
|
|
45
|
-
console.log(message);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
stackPanel.Children.Add(button);
|
|
49
|
-
|
|
50
|
-
mainWindow.Content = stackPanel;
|
|
51
|
-
|
|
52
|
-
console.log("Click the button to increase the counter...");
|
|
53
|
-
|
|
54
|
-
const app = new Windows.Application();
|
|
55
|
-
app.Run(mainWindow);
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
// examples/wpf/drag-box/drag-box.ts
|
|
2
|
-
import dotnet from '../../../src/index.ts';
|
|
3
|
-
|
|
4
|
-
dotnet.load('PresentationFramework');
|
|
5
|
-
dotnet.load('PresentationCore');
|
|
6
|
-
dotnet.load('WindowsBase');
|
|
7
|
-
|
|
8
|
-
const System = dotnet.System as any;
|
|
9
|
-
const Windows = System.Windows;
|
|
10
|
-
const Controls = System.Windows.Controls;
|
|
11
|
-
const Media = System.Windows.Media;
|
|
12
|
-
const Input = System.Windows.Input;
|
|
13
|
-
|
|
14
|
-
console.log("--- WPF Draggable Box ---");
|
|
15
|
-
|
|
16
|
-
const mainWindow = new Windows.Window();
|
|
17
|
-
mainWindow.Title = "WPF Draggable Box Example (High Frequency IPC)";
|
|
18
|
-
mainWindow.Width = 800;
|
|
19
|
-
mainWindow.Height = 600;
|
|
20
|
-
mainWindow.WindowStartupLocation = Windows.WindowStartupLocation.CenterScreen;
|
|
21
|
-
|
|
22
|
-
// Create a canvas for absolute positioning
|
|
23
|
-
const canvas = new Controls.Canvas();
|
|
24
|
-
canvas.Background = Media.Brushes.LightGray;
|
|
25
|
-
|
|
26
|
-
// Create the draggable box
|
|
27
|
-
const box = new Controls.Border();
|
|
28
|
-
box.Width = 100;
|
|
29
|
-
box.Height = 100;
|
|
30
|
-
box.Background = Media.Brushes.Red;
|
|
31
|
-
box.BorderBrush = Media.Brushes.DarkRed;
|
|
32
|
-
box.BorderThickness = new Windows.Thickness(2);
|
|
33
|
-
|
|
34
|
-
const transform = new Media.TranslateTransform();
|
|
35
|
-
box.RenderTransform = transform;
|
|
36
|
-
|
|
37
|
-
transform.X = 350;
|
|
38
|
-
transform.Y = 250;
|
|
39
|
-
|
|
40
|
-
canvas.Children.Add(box);
|
|
41
|
-
|
|
42
|
-
// State tracking for drag and drop
|
|
43
|
-
let isDragging = false;
|
|
44
|
-
let startMouseX = 0;
|
|
45
|
-
let startMouseY = 0;
|
|
46
|
-
let startBoxX = 0;
|
|
47
|
-
let startBoxY = 0;
|
|
48
|
-
|
|
49
|
-
box.add_MouseDown((sender: any, e: any) => {
|
|
50
|
-
console.log('[DEBUG] MouseDown');
|
|
51
|
-
isDragging = true;
|
|
52
|
-
const pos = e.GetPosition(canvas);
|
|
53
|
-
startMouseX = pos.X;
|
|
54
|
-
startMouseY = pos.Y;
|
|
55
|
-
startBoxX = transform.X;
|
|
56
|
-
startBoxY = transform.Y;
|
|
57
|
-
box.Background = Media.Brushes.DarkRed;
|
|
58
|
-
box.CaptureMouse();
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
// Mouse up event - stop dragging
|
|
62
|
-
box.add_MouseUp((sender: any, e: any) => {
|
|
63
|
-
console.log('[DEBUG] MouseUp');
|
|
64
|
-
isDragging = false;
|
|
65
|
-
box.Background = Media.Brushes.Red;
|
|
66
|
-
box.ReleaseMouseCapture();
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
// Mouse move event - handle dragging
|
|
70
|
-
box.add_MouseMove((sender: any, e: any) => {
|
|
71
|
-
if (isDragging) {
|
|
72
|
-
const currentPos = e.GetPosition(canvas);
|
|
73
|
-
|
|
74
|
-
transform.X = startBoxX + (currentPos.X - startMouseX);
|
|
75
|
-
transform.Y = startBoxY + (currentPos.Y - startMouseY);
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
mainWindow.Content = canvas;
|
|
80
|
-
|
|
81
|
-
console.log("Initialization complete. Try dragging the red box!");
|
|
82
|
-
|
|
83
|
-
const app = new Windows.Application();
|
|
84
|
-
app.Run(mainWindow);
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
Copyright (C) Microsoft Corporation. All rights reserved.
|
|
2
|
-
|
|
3
|
-
Redistribution and use in source and binary forms, with or without
|
|
4
|
-
modification, are permitted provided that the following conditions are
|
|
5
|
-
met:
|
|
6
|
-
|
|
7
|
-
* Redistributions of source code must retain the above copyright
|
|
8
|
-
notice, this list of conditions and the following disclaimer.
|
|
9
|
-
* Redistributions in binary form must reproduce the above
|
|
10
|
-
copyright notice, this list of conditions and the following disclaimer
|
|
11
|
-
in the documentation and/or other materials provided with the
|
|
12
|
-
distribution.
|
|
13
|
-
* The name of Microsoft Corporation, or the names of its contributors
|
|
14
|
-
may not be used to endorse or promote products derived from this
|
|
15
|
-
software without specific prior written permission.
|
|
16
|
-
|
|
17
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
18
|
-
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
19
|
-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
20
|
-
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
21
|
-
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
22
|
-
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
23
|
-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
24
|
-
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
25
|
-
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
26
|
-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
27
|
-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<title>Counter</title>
|
|
5
|
-
<meta charset="UTF-8">
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
-
</head>
|
|
8
|
-
<body>
|
|
9
|
-
<h1>Counter App</h1>
|
|
10
|
-
<p id="display">Clicks: 0</p>
|
|
11
|
-
<button id="btn">Click to Add</button>
|
|
12
|
-
|
|
13
|
-
<script>
|
|
14
|
-
let clickCount = 0;
|
|
15
|
-
const display = document.getElementById('display');
|
|
16
|
-
const button = document.getElementById('btn');
|
|
17
|
-
|
|
18
|
-
button.addEventListener('click', function() {
|
|
19
|
-
clickCount++;
|
|
20
|
-
const message = 'Button clicked ' + clickCount + ' times';
|
|
21
|
-
display.textContent = message;
|
|
22
|
-
|
|
23
|
-
if (window.chrome && window.chrome.webview) {
|
|
24
|
-
window.chrome.webview.postMessage(message);
|
|
25
|
-
} else {
|
|
26
|
-
alert('chrome.webview not available! Click: ' + message);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
</script>
|
|
30
|
-
</body>
|
|
31
|
-
</html>
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import dotnet from '../../../src/index.ts';
|
|
2
|
-
import * as fs from 'node:fs';
|
|
3
|
-
import * as path from 'node:path';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
|
|
6
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
-
const __dirname = path.dirname(__filename);
|
|
8
|
-
|
|
9
|
-
const System = dotnet.System as any;
|
|
10
|
-
const Windows = System.Windows;
|
|
11
|
-
const Controls = System.Windows.Controls;
|
|
12
|
-
|
|
13
|
-
const webview2LibPath = path.join(__dirname, 'WebView2Libs');
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
System.Reflection.Assembly.LoadFrom(path.join(webview2LibPath, 'Microsoft.Web.WebView2.Core.dll'));
|
|
17
|
-
System.Reflection.Assembly.LoadFrom(path.join(webview2LibPath, 'Microsoft.Web.WebView2.Wpf.dll'));
|
|
18
|
-
} catch (e) {
|
|
19
|
-
console.error("Core Dll Load Failed:", e);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const WebView2WpfAssembly = System.Reflection.Assembly.LoadFrom(path.join(webview2LibPath, 'Microsoft.Web.WebView2.Wpf.dll'));
|
|
23
|
-
|
|
24
|
-
const USER_DATA_FOLDER = path.join(__dirname, 'WebView2_Data');
|
|
25
|
-
const COUNTER_HTML_PATH = path.join(__dirname, 'counter.html');
|
|
26
|
-
|
|
27
|
-
console.log('--- Initializing WebView2 (Counter App) ---');
|
|
28
|
-
|
|
29
|
-
const WebView2Type = WebView2WpfAssembly.GetType('Microsoft.Web.WebView2.Wpf.WebView2');
|
|
30
|
-
const webView = new WebView2Type();
|
|
31
|
-
|
|
32
|
-
const CreationPropertiesType = WebView2WpfAssembly.GetType('Microsoft.Web.WebView2.Wpf.CoreWebView2CreationProperties');
|
|
33
|
-
const props = new CreationPropertiesType();
|
|
34
|
-
if (!fs.existsSync(USER_DATA_FOLDER)) fs.mkdirSync(USER_DATA_FOLDER, { recursive: true });
|
|
35
|
-
props.UserDataFolder = USER_DATA_FOLDER;
|
|
36
|
-
props.Language = "zh-CN";
|
|
37
|
-
webView.CreationProperties = props;
|
|
38
|
-
|
|
39
|
-
const browserWindow = new Windows.Window();
|
|
40
|
-
browserWindow.Title = 'Counter App - WebView2';
|
|
41
|
-
browserWindow.Width = 500;
|
|
42
|
-
browserWindow.Height = 400;
|
|
43
|
-
browserWindow.WindowStartupLocation = Windows.WindowStartupLocation.CenterScreen;
|
|
44
|
-
|
|
45
|
-
const grid = new Controls.Grid();
|
|
46
|
-
browserWindow.Content = grid;
|
|
47
|
-
grid.Children.Add(webView);
|
|
48
|
-
|
|
49
|
-
webView.add_CoreWebView2InitializationCompleted((sender: any, e: any) => {
|
|
50
|
-
if (e.IsSuccess) {
|
|
51
|
-
console.log('WebView2 Initialized Successfully');
|
|
52
|
-
|
|
53
|
-
const coreWebView2 = webView.CoreWebView2;
|
|
54
|
-
|
|
55
|
-
coreWebView2.add_WebMessageReceived((sender2: any, e2: any) => {
|
|
56
|
-
const message = e2.TryGetWebMessageAsString();
|
|
57
|
-
if (message) {
|
|
58
|
-
console.log('[WebView2] ' + message);
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
const script = `
|
|
63
|
-
(function() {
|
|
64
|
-
var originalLog = console.log;
|
|
65
|
-
console.log = function(msg) {
|
|
66
|
-
originalLog(msg);
|
|
67
|
-
if (window.chrome && window.chrome.webview) {
|
|
68
|
-
window.chrome.webview.postMessage(msg);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
})();
|
|
72
|
-
`;
|
|
73
|
-
coreWebView2.ExecuteJavaScript(script);
|
|
74
|
-
} else {
|
|
75
|
-
console.error('FAILURE: Init failed', e.InitializationException?.Message);
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
webView.add_NavigationCompleted((sender: any, e: any) => {
|
|
80
|
-
console.log('Page Loaded Successfully');
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
webView.Source = new System.Uri(COUNTER_HTML_PATH);
|
|
84
|
-
|
|
85
|
-
browserWindow.add_Closed((sender: any, e: any) => {
|
|
86
|
-
process.exit(0);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
const app = new Windows.Application();
|
|
90
|
-
app.Run(browserWindow);
|