@osmn-byhn/widget-core-windows 1.0.0 → 1.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/LICENSE +21 -21
- package/README.md +154 -162
- package/binding.gyp +44 -69
- package/dist/autostart.d.ts +1 -7
- package/dist/autostart.d.ts.map +1 -1
- package/dist/autostart.js +8 -106
- package/dist/autostart.js.map +1 -1
- package/dist/autostart.test.js +4 -20
- package/dist/autostart.test.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -16
- package/dist/index.js.map +1 -1
- package/dist/test.d.ts +1 -1
- package/dist/test.js +53 -53
- package/native/WidgetManager.h +29 -26
- package/native/host.cpp +70 -70
- package/native/main.cpp +65 -57
- package/native/win32/WidgetManager.cpp +246 -246
- package/package.json +49 -49
- package/native/linux/WidgetManager.cpp +0 -278
- package/native/macos/WidgetManager.mm +0 -87
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Osman Beyhan
|
|
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.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Osman Beyhan
|
|
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
CHANGED
|
@@ -1,162 +1,154 @@
|
|
|
1
|
-
# WidgetCore 🚀
|
|
2
|
-
|
|
3
|
-
**WidgetCore** is a high-performance,
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## 🏗️ Architecture
|
|
8
|
-
|
|
9
|
-
WidgetCore uses a hybrid architecture
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
---
|
|
152
|
-
|
|
153
|
-
##
|
|
154
|
-
|
|
155
|
-
- **Widget background is white on Linux**: Ensure your compositor supports transparency. We use ARGB visual for the GTK window.
|
|
156
|
-
- **Keyboard input not working**: Set `interactive: true` in the options.
|
|
157
|
-
- **Widget doesn't appear after restart**: Check if the registry file `~/.config/widget-core-windows/widgets.json` exists and the autostart entry is correct.
|
|
158
|
-
|
|
159
|
-
---
|
|
160
|
-
|
|
161
|
-
## 📝 License
|
|
162
|
-
MIT License. Copyright (c) 2026 Osman Beyhan. Contributions are welcome!
|
|
1
|
+
# WidgetCore 🚀 (Windows Optimized)
|
|
2
|
+
|
|
3
|
+
**WidgetCore** is a high-performance, Windows-optimized library built with Node.js and C++ for creating interactive and persistent desktop widgets. By leveraging the native **Win32 API** and **WebView2**, WidgetCore provides a lightweight, hardware-accelerated experience that feels like a natural part of the Windows desktop.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 🏗️ Architecture: The Node-Native Bridge
|
|
8
|
+
|
|
9
|
+
WidgetCore uses a sophisticated hybrid architecture to combine the rapid development of web technologies with the power of native system APIs.
|
|
10
|
+
|
|
11
|
+
### 1. The Win32 Message Loop
|
|
12
|
+
Unlike standard Node.js applications that run on a single thread, WidgetCore spawns a **dedicated, detached Win32 thread** for each widget. This ensures that:
|
|
13
|
+
- The Node.js event loop remains unblocked.
|
|
14
|
+
- Window messages (resizing, clicking, painting) are handled with sub-millisecond latency.
|
|
15
|
+
- The widget remains responsive even if the main Node.js process is busy with heavy computations.
|
|
16
|
+
|
|
17
|
+
### 2. OLE/COM Browser Hosting
|
|
18
|
+
WidgetCore embeds the **Microsoft WebView2** engine (Edge/Chromium) using the `IWebBrowser2` interface (via OLE). This provides:
|
|
19
|
+
- Full HTML5/CSS3/ES6 support.
|
|
20
|
+
- Hardware-accelerated rendering.
|
|
21
|
+
- Low memory footprint compared to full Electron shells.
|
|
22
|
+
|
|
23
|
+
```mermaid
|
|
24
|
+
graph TD
|
|
25
|
+
A[Node.js Logic] -- Node-API (C++) --> B[WidgetManager]
|
|
26
|
+
B -- std::thread --> C[Detached Message Loop]
|
|
27
|
+
C -- Win32 API --> D[WS_EX_LAYERED Window]
|
|
28
|
+
D -- OLE/COM --> E[WebView2 Engine]
|
|
29
|
+
E --> F[Example: Cyber-Glow Widget]
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## ✨ The "Cyber-Glow" Mode (Native Features)
|
|
35
|
+
|
|
36
|
+
WidgetCore is designed for high-end desktop aesthetics. It implements several advanced Win32 techniques:
|
|
37
|
+
|
|
38
|
+
### 🖼️ Aggressive Transparency
|
|
39
|
+
Using `WS_EX_LAYERED` and `LWA_COLORKEY`, WidgetCore achieves true transparency. The native layer uses a specific color key (`RGB(1, 1, 1)`) as the transparency mask, allowing for:
|
|
40
|
+
- Non-rectangular widget shapes.
|
|
41
|
+
- Anti-aliased "glow" effects that blend into the wallpaper.
|
|
42
|
+
- No ugly borders or standard window decorations.
|
|
43
|
+
|
|
44
|
+
### 🌌 DWM Blur Behind
|
|
45
|
+
By interfacing with `dwmapi.dll`, WidgetCore can enable the **Aero Glass / Acrylic** effect behind your widget.
|
|
46
|
+
- **Config**: Set `blur: true` in `WidgetOptions`.
|
|
47
|
+
- **Effect**: The background of your widget will have a beautiful, frosted-glass blur that interacts with the wallpaper.
|
|
48
|
+
|
|
49
|
+
### 🖱️ Click-Through Interactivity
|
|
50
|
+
You can control how the widget interacts with the mouse:
|
|
51
|
+
- **Interactive (`true`)**: The widget behaves like a normal window (receives clicks).
|
|
52
|
+
- **Click-Through (`false`)**: Mouse events pass directly through the widget to the desktop icons or other windows behind it.
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## 🔒 Security Shield Architecture
|
|
57
|
+
|
|
58
|
+
Security is baked into the core. Every widget is wrapped in a multi-stage **Security Shield**:
|
|
59
|
+
|
|
60
|
+
1. **Context Isolation**: Injected CSS and JS freeze the environment. Standard Node.js entry points (`process`, `require`) are purged before the widget content loads.
|
|
61
|
+
2. **Protocol Filtering**: Only `http:`, `https:`, and strictly validated `file:///` protocols are permitted. This prevent `javascript:` or `data:` URL exploits.
|
|
62
|
+
3. **Keyword Scanning**: All input triggers (URLs and HTML blobs) are scanned for high-risk system keywords (`shell`, `exec`, `eval`, `process`).
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## 💾 Persistence & Standalone Execution
|
|
67
|
+
|
|
68
|
+
WidgetCore widgets can survive system reboots and process crashes.
|
|
69
|
+
|
|
70
|
+
### 1. The Registry Lifecycle
|
|
71
|
+
The `AutostartManager` interfaces with the Windows Registry:
|
|
72
|
+
`HKCU\Software\Microsoft\Windows\CurrentVersion\Run`
|
|
73
|
+
It creates a unique entry for each persistent widget that triggers a `runner.js` script on login.
|
|
74
|
+
|
|
75
|
+
### 2. Standalone Runner
|
|
76
|
+
The `runner.js` is a lightweight entry point that reconstructs a widget instance from the `widgets.json` registry file without requiring the primary application to be running.
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## 🚀 Getting Started
|
|
81
|
+
|
|
82
|
+
### Installation
|
|
83
|
+
```bash
|
|
84
|
+
npm install @osmn-byhn/widget-core-windows
|
|
85
|
+
```
|
|
86
|
+
*Note: Requires Visual Studio Build Tools and Node-GYP for native compilation.*
|
|
87
|
+
|
|
88
|
+
### Basic Usage
|
|
89
|
+
```typescript
|
|
90
|
+
import { DesktopWidget } from '@osmn-byhn/widget-core-windows';
|
|
91
|
+
|
|
92
|
+
const widget = new DesktopWidget("https://my-widget-dashboard.com", {
|
|
93
|
+
width: 350,
|
|
94
|
+
height: 500,
|
|
95
|
+
x: 100,
|
|
96
|
+
y: 100,
|
|
97
|
+
opacity: 0.9,
|
|
98
|
+
blur: true, // Glass effect
|
|
99
|
+
sticky: true // Stays on bottom
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## 🛠️ API Reference
|
|
106
|
+
|
|
107
|
+
### Per-widget JSON, CSS, JavaScript, and keys
|
|
108
|
+
|
|
109
|
+
Create a JSON file for each widget and pass its path with `configPath`. CSS and JavaScript are injected into the document. `keys` and `data` are available as `window.widgetConfig.keys` and `window.widgetConfig.data`.
|
|
110
|
+
|
|
111
|
+
```json
|
|
112
|
+
{
|
|
113
|
+
"css": "body { color: white; background: transparent; }",
|
|
114
|
+
"js": "document.querySelector('#title').textContent = window.widgetConfig.keys.title;",
|
|
115
|
+
"keys": { "title": "Hello" },
|
|
116
|
+
"data": { "refreshMs": 5000 }
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
new DesktopWidget("file:///widgets/clock/index.html", {
|
|
122
|
+
width: 360, height: 180, x: 20, y: 20,
|
|
123
|
+
configPath: "C:/widgets/clock/widget.json"
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
`window.widgetConfig` exposes widget-specific JSON values to the page. JavaScript support follows the browser engine available on the system.
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
### `WidgetOptions`
|
|
131
|
+
| Property | Type | Default | Description |
|
|
132
|
+
| :--- | :--- | :--- | :--- |
|
|
133
|
+
| `width` / `height` | `number` | `400` | Dimensions in pixels. |
|
|
134
|
+
| `x` / `y` | `number` | `100` | Screen coordinates (0,0 is top-left). |
|
|
135
|
+
| `opacity` | `number` | `1.0` | Global alpha (0.0 - 1.0). |
|
|
136
|
+
| `blur` | `boolean` | `false` | Enables DWM Blur Behind (Acrylic look). |
|
|
137
|
+
| `sticky` | `boolean` | `true` | Pins the widget to the bottom layer (desktop). |
|
|
138
|
+
| `interactive` | `boolean` | `true` | Set to `false` for click-through mode. |
|
|
139
|
+
| `html` | `string` | `""` | Direct HTML string if no URL is provided. |
|
|
140
|
+
| `configPath` | `string` | — | Path to a widget-specific JSON settings file. |
|
|
141
|
+
| `css` / `js` | `string` | — | CSS and JavaScript source for the widget. |
|
|
142
|
+
| `keys` / `data` | `object` | `{}` | Custom JSON values available through `window.widgetConfig`. |
|
|
143
|
+
| `detached` | `boolean` | `false` | Runs the widget in the standalone native host. |
|
|
144
|
+
|
|
145
|
+
### `DesktopWidget` Methods
|
|
146
|
+
- `setPosition(x, y)`: Real-time window movement.
|
|
147
|
+
- `setOpacity(value)`: Smooth alpha transitions.
|
|
148
|
+
- `makePersistent(options)`: Registers the widget for autostart.
|
|
149
|
+
- `static stopAll()`: Kills all running widget processes across the system.
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## 📝 License
|
|
154
|
+
MIT License. Copyright (c) 2026 Osman Beyhan.
|
package/binding.gyp
CHANGED
|
@@ -1,69 +1,44 @@
|
|
|
1
|
-
{
|
|
2
|
-
"targets": [
|
|
3
|
-
{
|
|
4
|
-
"target_name": "widget_shield_native",
|
|
5
|
-
"sources": [ "native/main.cpp" ],
|
|
6
|
-
"include_dirs": [
|
|
7
|
-
"native",
|
|
8
|
-
"<!@(node -p \"require('node-addon-api').include\")"
|
|
9
|
-
],
|
|
10
|
-
"dependencies": [
|
|
11
|
-
"<!(node -p \"require('node-addon-api').gyp\")"
|
|
12
|
-
],
|
|
13
|
-
"conditions": [
|
|
14
|
-
["OS=='
|
|
15
|
-
"sources": [ "native/
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
]
|
|
46
|
-
}
|
|
47
|
-
}]
|
|
48
|
-
],
|
|
49
|
-
"defines": [ "NAPI_DISABLE_CPP_EXCEPTIONS", "NODE_ADDON_API_CPP_EXCEPTIONS" ]
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
"target_name": "widget_host",
|
|
53
|
-
"type": "executable",
|
|
54
|
-
"sources": [ "native/host.cpp" ],
|
|
55
|
-
"include_dirs": [ "native" ],
|
|
56
|
-
"conditions": [
|
|
57
|
-
["OS=='win'", {
|
|
58
|
-
"sources": [ "native/win32/WidgetManager.cpp" ],
|
|
59
|
-
"libraries": ["dwmapi.lib", "user32.lib", "ole32.lib", "oleaut32.lib"],
|
|
60
|
-
"msvs_settings": {
|
|
61
|
-
"VCCLCompilerTool": {
|
|
62
|
-
"AdditionalOptions": [ "/std:c++17" ]
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}]
|
|
66
|
-
]
|
|
67
|
-
}
|
|
68
|
-
]
|
|
69
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"targets": [
|
|
3
|
+
{
|
|
4
|
+
"target_name": "widget_shield_native",
|
|
5
|
+
"sources": [ "native/main.cpp" ],
|
|
6
|
+
"include_dirs": [
|
|
7
|
+
"native",
|
|
8
|
+
"<!@(node -p \"require('node-addon-api').include\")"
|
|
9
|
+
],
|
|
10
|
+
"dependencies": [
|
|
11
|
+
"<!(node -p \"require('node-addon-api').gyp\")"
|
|
12
|
+
],
|
|
13
|
+
"conditions": [
|
|
14
|
+
["OS=='win'", {
|
|
15
|
+
"sources": [ "native/win32/WidgetManager.cpp" ],
|
|
16
|
+
"libraries": ["dwmapi.lib", "user32.lib", "ole32.lib", "oleaut32.lib"],
|
|
17
|
+
"msvs_settings": {
|
|
18
|
+
"VCCLCompilerTool": {
|
|
19
|
+
"AdditionalOptions": [ "/std:c++17" ]
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}]
|
|
23
|
+
],
|
|
24
|
+
"defines": [ "NAPI_DISABLE_CPP_EXCEPTIONS", "NODE_ADDON_API_CPP_EXCEPTIONS" ]
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"target_name": "widget_host",
|
|
28
|
+
"type": "executable",
|
|
29
|
+
"sources": [ "native/host.cpp" ],
|
|
30
|
+
"include_dirs": [ "native" ],
|
|
31
|
+
"conditions": [
|
|
32
|
+
["OS=='win'", {
|
|
33
|
+
"sources": [ "native/win32/WidgetManager.cpp" ],
|
|
34
|
+
"libraries": ["dwmapi.lib", "user32.lib", "ole32.lib", "oleaut32.lib"],
|
|
35
|
+
"msvs_settings": {
|
|
36
|
+
"VCCLCompilerTool": {
|
|
37
|
+
"AdditionalOptions": [ "/std:c++17" ]
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}]
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
}
|
package/dist/autostart.d.ts
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
export declare class AutostartManager {
|
|
2
|
-
private platform;
|
|
3
2
|
constructor();
|
|
4
|
-
|
|
5
|
-
enable(id: string, name: string, command: string): boolean;
|
|
3
|
+
enable(id: string, _name: string, command: string): boolean;
|
|
6
4
|
disable(id: string): boolean;
|
|
7
|
-
private enableLinux;
|
|
8
|
-
private disableLinux;
|
|
9
5
|
private enableWindows;
|
|
10
6
|
private disableWindows;
|
|
11
|
-
private enableMacOS;
|
|
12
|
-
private disableMacOS;
|
|
13
7
|
}
|
|
14
8
|
//# sourceMappingURL=autostart.d.ts.map
|
package/dist/autostart.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autostart.d.ts","sourceRoot":"","sources":["../src/autostart.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"autostart.d.ts","sourceRoot":"","sources":["../src/autostart.ts"],"names":[],"mappings":"AAEA,qBAAa,gBAAgB;;IAOlB,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO;IAS3D,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IASnC,OAAO,CAAC,aAAa;IAcrB,OAAO,CAAC,cAAc;CAWzB"}
|
package/dist/autostart.js
CHANGED
|
@@ -1,85 +1,25 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import os from 'os';
|
|
4
1
|
import { execSync } from 'child_process';
|
|
5
2
|
export class AutostartManager {
|
|
6
|
-
platform;
|
|
7
3
|
constructor() {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
ensureDir() {
|
|
12
|
-
if (this.platform === 'linux') {
|
|
13
|
-
const dir = path.join(os.homedir(), '.config', 'autostart');
|
|
14
|
-
if (!fs.existsSync(dir))
|
|
15
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
16
|
-
}
|
|
17
|
-
else if (this.platform === 'darwin') {
|
|
18
|
-
const dir = path.join(os.homedir(), 'Library', 'LaunchAgents');
|
|
19
|
-
if (!fs.existsSync(dir))
|
|
20
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
4
|
+
if (process.platform !== 'win32') {
|
|
5
|
+
console.warn("AutostartManager is only supported on Windows.");
|
|
21
6
|
}
|
|
22
7
|
}
|
|
23
|
-
enable(id,
|
|
24
|
-
|
|
25
|
-
if (this.platform === 'linux') {
|
|
26
|
-
return this.enableLinux(id, name, command);
|
|
27
|
-
}
|
|
28
|
-
else if (this.platform === 'win32') {
|
|
29
|
-
return this.enableWindows(id, command);
|
|
30
|
-
}
|
|
31
|
-
else if (this.platform === 'darwin') {
|
|
32
|
-
return this.enableMacOS(id, name, command);
|
|
33
|
-
}
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
catch (e) {
|
|
8
|
+
enable(id, _name, command) {
|
|
9
|
+
if (process.platform !== 'win32')
|
|
37
10
|
return false;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
disable(id) {
|
|
41
11
|
try {
|
|
42
|
-
|
|
43
|
-
return this.disableLinux(id);
|
|
44
|
-
}
|
|
45
|
-
else if (this.platform === 'win32') {
|
|
46
|
-
return this.disableWindows(id);
|
|
47
|
-
}
|
|
48
|
-
else if (this.platform === 'darwin') {
|
|
49
|
-
return this.disableMacOS(id);
|
|
50
|
-
}
|
|
51
|
-
return false;
|
|
12
|
+
return this.enableWindows(id, command);
|
|
52
13
|
}
|
|
53
14
|
catch (e) {
|
|
54
15
|
return false;
|
|
55
16
|
}
|
|
56
17
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const dir = path.join(os.homedir(), '.config', 'autostart');
|
|
60
|
-
const file = path.join(dir, `widget-${id}.desktop`);
|
|
61
|
-
const content = `[Desktop Entry]
|
|
62
|
-
Type=Application
|
|
63
|
-
Name=Desktop Widget - ${name}
|
|
64
|
-
Exec=${command}
|
|
65
|
-
Hidden=false
|
|
66
|
-
NoDisplay=false
|
|
67
|
-
X-GNOME-Autostart-enabled=true
|
|
68
|
-
Comment=Auto-started desktop widget
|
|
69
|
-
`;
|
|
70
|
-
fs.writeFileSync(file, content);
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
catch (e) {
|
|
18
|
+
disable(id) {
|
|
19
|
+
if (process.platform !== 'win32')
|
|
74
20
|
return false;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
disableLinux(id) {
|
|
78
21
|
try {
|
|
79
|
-
|
|
80
|
-
if (fs.existsSync(file))
|
|
81
|
-
fs.unlinkSync(file);
|
|
82
|
-
return true;
|
|
22
|
+
return this.disableWindows(id);
|
|
83
23
|
}
|
|
84
24
|
catch (e) {
|
|
85
25
|
return false;
|
|
@@ -111,43 +51,5 @@ Comment=Auto-started desktop widget
|
|
|
111
51
|
return true;
|
|
112
52
|
}
|
|
113
53
|
}
|
|
114
|
-
enableMacOS(id, name, command) {
|
|
115
|
-
try {
|
|
116
|
-
const dir = path.join(os.homedir(), 'Library', 'LaunchAgents');
|
|
117
|
-
const file = path.join(dir, `com.widget.${id}.plist`);
|
|
118
|
-
const content = `<?xml version="1.0" encoding="UTF-8"?>
|
|
119
|
-
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
120
|
-
<plist version="1.0">
|
|
121
|
-
<dict>
|
|
122
|
-
<key>Label</key>
|
|
123
|
-
<string>com.widget.${id}</string>
|
|
124
|
-
<key>ProgramArguments</key>
|
|
125
|
-
<array>
|
|
126
|
-
<string>sh</string>
|
|
127
|
-
<string>-c</string>
|
|
128
|
-
<string>${command}</string>
|
|
129
|
-
</array>
|
|
130
|
-
<key>RunAtLoad</key>
|
|
131
|
-
<true/>
|
|
132
|
-
</dict>
|
|
133
|
-
</plist>`;
|
|
134
|
-
fs.writeFileSync(file, content);
|
|
135
|
-
return true;
|
|
136
|
-
}
|
|
137
|
-
catch (e) {
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
disableMacOS(id) {
|
|
142
|
-
try {
|
|
143
|
-
const file = path.join(os.homedir(), 'Library', 'LaunchAgents', `com.widget.${id}.plist`);
|
|
144
|
-
if (fs.existsSync(file))
|
|
145
|
-
fs.unlinkSync(file);
|
|
146
|
-
return true;
|
|
147
|
-
}
|
|
148
|
-
catch (e) {
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
54
|
}
|
|
153
55
|
//# sourceMappingURL=autostart.js.map
|