webview-napi 0.1.5
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/LICENSE +21 -0
- package/README.md +137 -0
- package/bindings.linux-x64-gnu.node +0 -0
- package/index.d.ts +1596 -0
- package/index.js +629 -0
- package/package.json +104 -0
- package/webview.linux-x64-gnu.node +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Twilight
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# Desktop Framework (NAPI-RS + Tao + Wry)
|
|
2
|
+
|
|
3
|
+
A high-performance desktop application framework for Node.js. This library provides native bindings to **Tao** for cross-platform window management and **Wry** for rendering web-based user interfaces.
|
|
4
|
+
|
|
5
|
+
## 🚀 Features
|
|
6
|
+
|
|
7
|
+
* **Native Performance**: Built with Rust via NAPI-RS for minimal overhead.
|
|
8
|
+
* **Window Management**: Robust window control (positioning, sizing, monitors) powered by Tao.
|
|
9
|
+
* **Webview Rendering**: Modern webview integration with IPC support via Wry.
|
|
10
|
+
* **Pixel Rendering**: Low-level `PixelRenderer` for software rendering or custom graphics buffers.
|
|
11
|
+
* **Event-Driven**: Flexible event loop management for responsive applications.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## 🛠Architecture
|
|
16
|
+
|
|
17
|
+
The framework consists of three main layers:
|
|
18
|
+
|
|
19
|
+
1. **Event Loop**: The core engine that manages system events.
|
|
20
|
+
2. **Window (Tao)**: The native OS window container.
|
|
21
|
+
3. **Webview (Wry)**: The browser engine running inside the window.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 📖 Basic Usage
|
|
26
|
+
|
|
27
|
+
### 1. Simple Application Pattern
|
|
28
|
+
|
|
29
|
+
The `Application` class provides a high-level wrapper to get started quickly.
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { Application } from './index';
|
|
33
|
+
|
|
34
|
+
const app = new Application({
|
|
35
|
+
controlFlow: 0 // Poll
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const window = app.createBrowserWindow({
|
|
39
|
+
title: "My Desktop App",
|
|
40
|
+
width: 800,
|
|
41
|
+
height: 600,
|
|
42
|
+
visible: true
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
app.run();
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### 2. Advanced Manual Control (Builder Pattern)
|
|
50
|
+
|
|
51
|
+
For more control, use the `EventLoop`, `WindowBuilder`, and `WebViewBuilder`.
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { EventLoopBuilder, WindowBuilder, WebViewBuilder } from './index';
|
|
55
|
+
|
|
56
|
+
const eventLoop = new EventLoopBuilder().build();
|
|
57
|
+
const window = new WindowBuilder()
|
|
58
|
+
.withTitle("Advanced Window")
|
|
59
|
+
.withInnerSize(1024, 768)
|
|
60
|
+
.build(eventLoop);
|
|
61
|
+
|
|
62
|
+
const webview = new WebViewBuilder()
|
|
63
|
+
.withUrl("https://github.com")
|
|
64
|
+
.build(eventLoop, "main-view");
|
|
65
|
+
|
|
66
|
+
eventLoop.run();
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## 📨 Inter-Process Communication (IPC)
|
|
73
|
+
|
|
74
|
+
Communicate between your Node.js logic and the JavaScript running inside the Webview.
|
|
75
|
+
|
|
76
|
+
### Node.js side
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
webview.on((err, message) => {
|
|
80
|
+
console.log("Received from Webview:", message);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Send message to Webview
|
|
84
|
+
webview.send("Hello from Node!");
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Webview side (Frontend)
|
|
89
|
+
|
|
90
|
+
The framework injects a global handler:
|
|
91
|
+
|
|
92
|
+
```javascript
|
|
93
|
+
window.__webview_on_message__ = (message) => {
|
|
94
|
+
console.log("Message from Node:", message);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// Send to Node
|
|
98
|
+
window.ipc.postMessage("Data from Frontend");
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## 🎨 Low-Level Rendering
|
|
105
|
+
|
|
106
|
+
If you aren't using a Webview and want to draw pixels directly (e.g., for an emulator or custom UI):
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
import { PixelRenderer, Window } from './index';
|
|
110
|
+
|
|
111
|
+
const win = new Window();
|
|
112
|
+
const renderer = new PixelRenderer(800, 600);
|
|
113
|
+
|
|
114
|
+
// buffer is a Node.js Buffer containing RGBA data
|
|
115
|
+
renderer.render(win, pixelBuffer);
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## 🗂 API Reference Summary
|
|
122
|
+
|
|
123
|
+
### Core Classes
|
|
124
|
+
|
|
125
|
+
| Class | Description |
|
|
126
|
+
| --- | --- |
|
|
127
|
+
| `Application` | High-level entry point for window/app management. |
|
|
128
|
+
| `EventLoop` | Manages the system event queue and window lifecycle. |
|
|
129
|
+
| `Window` | Controls native window properties (title, size, decorations). |
|
|
130
|
+
| `WebView` | The browser engine component (loads URLs, HTML, IPC). |
|
|
131
|
+
| `PixelRenderer` | Tool for rendering raw RGBA buffers to a window. |
|
|
132
|
+
|
|
133
|
+
### Key Utilities
|
|
134
|
+
|
|
135
|
+
* `primaryMonitor()`: Get details about the main display.
|
|
136
|
+
* `availableMonitors()`: List all connected displays and their resolutions.
|
|
137
|
+
* `getWebviewVersion()`: Check the underlying engine version.
|
|
Binary file
|