@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 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, cross-platform library built with Node.js and C++ for creating interactive and persistent desktop widgets. It leverages native OS webview engines (**WebView2** on Windows, **WKWebView** on macOS, and **WebKitGTK** on Linux) to provide a seamless, lightweight, and hardware-accelerated widget experience.
4
-
5
- ---
6
-
7
- ## 🏗️ Architecture Overview
8
-
9
- WidgetCore uses a hybrid architecture where the core logic is managed in Node.js, while windowing and webview rendering are handled by a native C++ module (`widget_core.node`).
10
-
11
- ```mermaid
12
- graph TD
13
- A[Node.js App] --> B[DesktopWidget Class]
14
- B --> C[WidgetRegistry]
15
- B --> D[AutostartManager]
16
- B --> E[Native Module C++]
17
- E --> F{Platform}
18
- F -->|Linux| G[WebKitGTK + GTK3]
19
- F -->|macOS| H[WKWebView + Cocoa]
20
- F -->|Windows| I[WebView2 + Win32]
21
- G --> J[Desktop Widget Window]
22
- H --> J
23
- I --> J
24
- ```
25
-
26
- ---
27
-
28
- ## ✨ Core Capabilities
29
-
30
- - **🚀 HTML/JS Power**: Build widgets using any web technology. No restricted environments.
31
- - **🖼️ Native Transparency**: Aggressive transparency settings ensure widgets blend perfectly with wallpapers.
32
- - **🖇️ System Integration**: Widgets are pinned below icons (on supported platforms) and removed from taskbars/app-switchers.
33
- - **🖱️ Full Interactivity**: Toggle `interactive: true` to allow mouse clicks and keyboard input directly on the desktop background.
34
- - **💾 Auto-Persistence**: Automatically saves widget state and ensures they reappear after system reboots.
35
- - **🧩 Scroll-Free Design**: Scrollbars are hidden by default via CSS injection, with optional overflow prevention.
36
-
37
- ---
38
-
39
- ## 🔒 Security Shield
40
-
41
- Security is a primary concern for widgets. **WidgetCore** implements a multi-layer "Shield" to protect the host system:
42
-
43
- 1. **API Isolation**: Injects a preload script that freezes `process`, `require`, and other sensitive Node.js globals.
44
- 2. **Context Separation**: The webview runs in a sandboxed environment where it cannot access the local filesystem or execute shell commands directly.
45
- 3. **Protocol Filtering**: Only `http:`, `https:`, and valid `file:` protocols are allowed for loading content.
46
- 4. **Keyword Blocking**: Input data and URLs are scanned for dangerous keywords like `shell`, `eval`, or `exec`.
47
-
48
- ---
49
-
50
- ## 🚀 Detailed Usage
51
-
52
- ### Advanced HTML Widget Example
53
- You can create complex, self-contained widgets using a single string:
54
-
55
- ```typescript
56
- import { DesktopWidget } from 'widget-core-windows';
57
-
58
- const clockHTML = `
59
- <div id="clock" style="font-size: 48px; font-weight: bold; color: #60A5FA; font-family: sans-serif; text-shadow: 2px 2px 10px rgba(0,0,0,0.5);">00:00:00</div>
60
- <script>
61
- setInterval(() => {
62
- document.getElementById('clock').innerText = new Date().toLocaleTimeString();
63
- }, 1000);
64
- </script>
65
- `;
66
-
67
- const widget = new DesktopWidget("", {
68
- html: clockHTML,
69
- width: 300,
70
- height: 100,
71
- x: 50,
72
- y: 50,
73
- scroll: false,
74
- interactive: false // Clocks usually don't need input
75
- });
76
-
77
- // Make it stay after reboot
78
- await widget.makePersistent(widget.options);
79
- ```
80
-
81
- ### Static Global Management
82
- ```typescript
83
- // Stop all running widgets across the system
84
- const stopped = DesktopWidget.stopAll();
85
-
86
- // Get list of all registered widgets
87
- const widgets = DesktopWidget.listWidgets();
88
- widgets.forEach(w => console.log(`ID: ${w.id}, URL: ${w.url}, Active: ${w.active}`));
89
- ```
90
-
91
- ---
92
-
93
- ## 🛠️ API Documentation
94
-
95
- ### `WidgetOptions`
96
- | Property | Type | Description |
97
- | :--- | :--- | :--- |
98
- | `width` | `number` | Width in pixels. |
99
- | `height` | `number` | Height in pixels. |
100
- | `x` | `number` | X coordinate from top-left. |
101
- | `y` | `number` | Y coordinate from top-left. |
102
- | `opacity` | `number` | Window opacity (0.0 to 1.0). Default: `1.0`. |
103
- | `interactive` | `boolean` | If `true`, clicks pass through to the widget. Default: `false`. |
104
- | `html` | `string` | Raw HTML/CSS source code to load. |
105
- | `scroll` | `boolean` | If `false`, `overflow: hidden` is applied. Default: `true`. |
106
- | `blur` | `boolean` | Platform-specific background blur effect. |
107
-
108
- ### Instance Methods
109
- - **`makePersistent(options): Promise<boolean>`**: Saves to disk and enables autostart.
110
- - **`activate(): boolean`**: Enables autostart and launches the process.
111
- - **`deactivate(): boolean`**: Disables autostart and kills the process.
112
- - **`launchStandalone(): boolean`**: Spawns a background `runner.js` process for the widget.
113
-
114
- ---
115
-
116
- ## 🐧 Linux Platform Notes (GTK/WebKit)
117
- On Linux, WidgetCore uses GTK and WebKitGTK. For full transparency, ensure your window manager/compositor (like Mutter on GNOME or KWin on KDE) is configured correctly.
118
- - **Dependencies**: `libwebkit2gtk-4.0-dev` or `libwebkit2gtk-4.1-dev`.
119
- - **Autostart**: Creates `.desktop` files in `~/.config/autostart/`.
120
-
121
- ---
122
-
123
- ## 🍎 macOS Platform Notes (Cocoa/WKWebView)
124
- - **Engine**: WKWebView.
125
- - **Autostart**: Creates `.plist` files in `~/Library/LaunchAgents/`.
126
- - **Transparency**: Fully supported out-of-the-box.
127
-
128
- ---
129
-
130
- ## 💻 Windows Platform Notes (Win32/WebView2)
131
- - **Engine**: WebView2 (Evergreen Runtime required).
132
- - **Autostart**: Uses the `HKCU\Software\Microsoft\Windows\CurrentVersion\Run` registry key.
133
-
134
- ---
135
-
136
- ## 🧪 Development & Testing
137
-
138
- We use **Vitest** for unit testing. The native layer is mocked automatically during tests.
139
-
140
- ```bash
141
- # Install dependencies
142
- npm install
143
-
144
- # Build native module & TypeScript
145
- npm run build
146
-
147
- # Run tests
148
- npm test
149
- ```
150
-
151
- ---
152
-
153
- ## 🐛 Troubleshooting
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=='mac'", {
15
- "sources": [ "native/macos/WidgetManager.mm" ],
16
- "link_settings": {
17
- "libraries": ["-framework AppKit", "-framework WebKit"]
18
- },
19
- "xcode_settings": {
20
- "CLANG_CXX_LANGUAGE_STANDARD": "c++17",
21
- "MACOSX_DEPLOYMENT_TARGET": "10.15"
22
- }
23
- }],
24
- ["OS=='win'", {
25
- "sources": [ "native/win32/WidgetManager.cpp" ],
26
- "libraries": ["dwmapi.lib", "user32.lib", "ole32.lib", "oleaut32.lib"],
27
- "msvs_settings": {
28
- "VCCLCompilerTool": {
29
- "AdditionalOptions": [ "/std:c++17" ]
30
- }
31
- }
32
- }],
33
- ["OS=='linux'", {
34
- "sources": [ "native/linux/WidgetManager.cpp" ],
35
- "cflags": [ "<!@(pkg-config --cflags gtk+-3.0 webkit2gtk-4.1 gtk-layer-shell-0 2>/dev/null || pkg-config --cflags gtk+-3.0 webkit2gtk-4.0 2>/dev/null)" ],
36
- "cflags_cc": [
37
- "<!@(pkg-config --cflags gtk+-3.0 webkit2gtk-4.1 gtk-layer-shell-0 2>/dev/null || pkg-config --cflags gtk+-3.0 webkit2gtk-4.0 2>/dev/null)",
38
- "-std=c++17"
39
- ],
40
- "defines": [ "HAVE_GTK_LAYER_SHELL" ],
41
- "link_settings": {
42
- "libraries": [
43
- "<!@(pkg-config --libs gtk+-3.0 webkit2gtk-4.1 gtk-layer-shell-0 2>/dev/null || pkg-config --libs gtk+-3.0 webkit2gtk-4.0 2>/dev/null)",
44
- "-lX11"
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
+ }
@@ -1,14 +1,8 @@
1
1
  export declare class AutostartManager {
2
- private platform;
3
2
  constructor();
4
- private ensureDir;
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
@@ -1 +1 @@
1
- {"version":3,"file":"autostart.d.ts","sourceRoot":"","sources":["../src/autostart.ts"],"names":[],"mappings":"AAKA,qBAAa,gBAAgB;IACzB,OAAO,CAAC,QAAQ,CAAS;;IAOzB,OAAO,CAAC,SAAS;IAUV,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO;IAe1D,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAenC,OAAO,CAAC,WAAW;IAoBnB,OAAO,CAAC,YAAY;IAUpB,OAAO,CAAC,aAAa;IAcrB,OAAO,CAAC,cAAc;IAYtB,OAAO,CAAC,WAAW;IA2BnB,OAAO,CAAC,YAAY;CASvB"}
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
- this.platform = process.platform;
9
- this.ensureDir();
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, name, command) {
24
- try {
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
- if (this.platform === 'linux') {
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
- enableLinux(id, name, command) {
58
- try {
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
- const file = path.join(os.homedir(), '.config', 'autostart', `widget-${id}.desktop`);
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