@osmn-byhn/widget-core-windows 1.0.0

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.
Files changed (54) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +162 -0
  3. package/binding.gyp +69 -0
  4. package/dist/autostart.d.ts +14 -0
  5. package/dist/autostart.d.ts.map +1 -0
  6. package/dist/autostart.js +153 -0
  7. package/dist/autostart.js.map +1 -0
  8. package/dist/autostart.test.d.ts +2 -0
  9. package/dist/autostart.test.d.ts.map +1 -0
  10. package/dist/autostart.test.js +39 -0
  11. package/dist/autostart.test.js.map +1 -0
  12. package/dist/index.d.ts +44 -0
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +306 -0
  15. package/dist/index.js.map +1 -0
  16. package/dist/index.test.d.ts +2 -0
  17. package/dist/index.test.d.ts.map +1 -0
  18. package/dist/index.test.js +60 -0
  19. package/dist/index.test.js.map +1 -0
  20. package/dist/mock_native.d.ts +7 -0
  21. package/dist/mock_native.d.ts.map +1 -0
  22. package/dist/mock_native.js +12 -0
  23. package/dist/mock_native.js.map +1 -0
  24. package/dist/registry.d.ts +24 -0
  25. package/dist/registry.d.ts.map +1 -0
  26. package/dist/registry.js +87 -0
  27. package/dist/registry.js.map +1 -0
  28. package/dist/registry.test.d.ts +2 -0
  29. package/dist/registry.test.d.ts.map +1 -0
  30. package/dist/registry.test.js +43 -0
  31. package/dist/registry.test.js.map +1 -0
  32. package/dist/runner.d.ts +2 -0
  33. package/dist/runner.d.ts.map +1 -0
  34. package/dist/runner.js +22 -0
  35. package/dist/runner.js.map +1 -0
  36. package/dist/shield.d.ts +5 -0
  37. package/dist/shield.d.ts.map +1 -0
  38. package/dist/shield.js +20 -0
  39. package/dist/shield.js.map +1 -0
  40. package/dist/shield.test.d.ts +2 -0
  41. package/dist/shield.test.d.ts.map +1 -0
  42. package/dist/shield.test.js +20 -0
  43. package/dist/shield.test.js.map +1 -0
  44. package/dist/test.d.ts +2 -0
  45. package/dist/test.d.ts.map +1 -0
  46. package/dist/test.js +54 -0
  47. package/dist/test.js.map +1 -0
  48. package/native/WidgetManager.h +26 -0
  49. package/native/host.cpp +70 -0
  50. package/native/linux/WidgetManager.cpp +278 -0
  51. package/native/macos/WidgetManager.mm +87 -0
  52. package/native/main.cpp +57 -0
  53. package/native/win32/WidgetManager.cpp +246 -0
  54. package/package.json +49 -0
@@ -0,0 +1,5 @@
1
+ export declare const createShield: (windowObj: any) => {
2
+ console: any;
3
+ setTimeout: any;
4
+ };
5
+ //# sourceMappingURL=shield.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shield.d.ts","sourceRoot":"","sources":["../src/shield.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,YAAY,GAAI,WAAW,GAAG;;;CAmB1C,CAAC"}
package/dist/shield.js ADDED
@@ -0,0 +1,20 @@
1
+ // Bu kod, widget yüklenmeden önce 'preload' script olarak çalıştırılmalı.
2
+ export const createShield = (windowObj) => {
3
+ const safeGlobals = {
4
+ console: windowObj.console,
5
+ setTimeout: windowObj.setTimeout,
6
+ // fs, process, vb. kesinlikle BURADA OLMAMALI
7
+ };
8
+ // Global nesneyi dondur ve tehlikeli her şeyi sil
9
+ const dangerousKeys = ["process", "require", "Buffer", "global"];
10
+ dangerousKeys.forEach((key) => {
11
+ Object.defineProperty(windowObj, key, {
12
+ get: () => {
13
+ throw new Error(`Security Shield: Access to ${key} is forbidden.`);
14
+ },
15
+ configurable: false,
16
+ });
17
+ });
18
+ return safeGlobals;
19
+ };
20
+ //# sourceMappingURL=shield.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shield.js","sourceRoot":"","sources":["../src/shield.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,SAAc,EAAE,EAAE;IAC7C,MAAM,WAAW,GAAG;QAClB,OAAO,EAAE,SAAS,CAAC,OAAO;QAC1B,UAAU,EAAE,SAAS,CAAC,UAAU;QAChC,8CAA8C;KAC/C,CAAC;IAEF,kDAAkD;IAClD,MAAM,aAAa,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACjE,aAAa,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QAC5B,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,GAAG,EAAE;YACpC,GAAG,EAAE,GAAG,EAAE;gBACR,MAAM,IAAI,KAAK,CAAC,8BAA8B,GAAG,gBAAgB,CAAC,CAAC;YACrE,CAAC;YACD,YAAY,EAAE,KAAK;SACpB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=shield.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shield.test.d.ts","sourceRoot":"","sources":["../src/shield.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,20 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { createShield } from './shield.js';
3
+ describe('SecurityShield', () => {
4
+ it('should return safe globals', () => {
5
+ const mockWindow = {
6
+ console: { log: () => { } },
7
+ setTimeout: () => { },
8
+ };
9
+ const safe = createShield(mockWindow);
10
+ expect(safe.console).toBe(mockWindow.console);
11
+ });
12
+ it('should block access to dangerous properties', () => {
13
+ const mockWindow = {};
14
+ createShield(mockWindow);
15
+ expect(() => mockWindow.process).toThrow(/Security Shield/);
16
+ expect(() => mockWindow.require).toThrow(/Security Shield/);
17
+ expect(() => mockWindow.global).toThrow(/Security Shield/);
18
+ });
19
+ });
20
+ //# sourceMappingURL=shield.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shield.test.js","sourceRoot":"","sources":["../src/shield.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,EAAE,CAAC,4BAA4B,EAAE,GAAG,EAAE;QACpC,MAAM,UAAU,GAAG;YACjB,OAAO,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE;YAC1B,UAAU,EAAE,GAAG,EAAE,GAAE,CAAC;SACrB,CAAC;QACF,MAAM,IAAI,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC;QACtC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE;QACrD,MAAM,UAAU,GAAQ,EAAE,CAAC;QAC3B,YAAY,CAAC,UAAU,CAAC,CAAC;QAEzB,MAAM,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;QAC5D,MAAM,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;QAC5D,MAAM,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC7D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/dist/test.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":""}
package/dist/test.js ADDED
@@ -0,0 +1,54 @@
1
+ import { DesktopWidget } from "./index.js";
2
+ async function main() {
3
+ console.log("🌟 Creating a widget from HTML SOURCE...");
4
+ DesktopWidget.killAllProcesses();
5
+ const html = `
6
+ <style>
7
+ body {
8
+ margin: 0;
9
+ padding: 100px 20px;
10
+ font-family: 'Inter', system-ui, sans-serif;
11
+ color: white;
12
+ height: 2000px; /* Long content */
13
+ background: transparent;
14
+ display: flex;
15
+ flex-direction: column;
16
+ align-items: center;
17
+ }
18
+ .content { font-size: 24px; text-align: center; }
19
+ </style>
20
+ <div class="content">
21
+ <h1>Scroll Test</h1>
22
+ <p>This content is 2000px tall.</p>
23
+ <p>Scrollbar should be HIDDEN.</p>
24
+ <p>If scroll: false, you should NOT be able to scroll.</p>
25
+ <div style="margin-top: 1500px;">YOU REACHED THE BOTTOM (if scrolling is on)</div>
26
+ </div>
27
+ `;
28
+ /*const options: WidgetOptions = {
29
+ width: 600,
30
+ height: 400,
31
+ x: 200,
32
+ y: 200,
33
+ opacity: 0.98,
34
+ sticky: true,
35
+ blur: true,
36
+ interactive: true,
37
+ html: html,
38
+ scroll: true // Disable scrolling
39
+ };
40
+
41
+ // No URL needed when html is provided
42
+ const widget = new DesktopWidget("", options);
43
+
44
+ console.log(`🚀 HTML Widget created with ID: ${widget.id}`);
45
+ await widget.makePersistent(options);
46
+
47
+ console.log("📡 Launching standalone...");
48
+ widget.launchStandalone();
49
+
50
+ console.log("\n✅ Done! HTML Widget is now running.");
51
+ console.log("Bu widget doğrudan kaynak kodundan (string) yüklenmiştir.");*/
52
+ }
53
+ main().catch(console.error);
54
+ //# sourceMappingURL=test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.js","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAsB,MAAM,YAAY,CAAC;AAE/D,KAAK,UAAU,IAAI;IACf,OAAO,CAAC,GAAG,CAAC,0CAA0C,CAAC,CAAC;IAExD,aAAa,CAAC,gBAAgB,EAAE,CAAA;IAEhC,MAAM,IAAI,GAAG;;;;;;;;;;;;;;;;;;;;;;KAsBZ,CAAC;IAEF;;;;;;;;;;;;;;;;;;;;;;;+EAuB2E;AAC/E,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"}
@@ -0,0 +1,26 @@
1
+ #ifndef WIDGET_MANAGER_H
2
+ #define WIDGET_MANAGER_H
3
+
4
+ #include <string>
5
+
6
+ struct WidgetOptions {
7
+ int width;
8
+ int height;
9
+ int x;
10
+ int y;
11
+ double opacity;
12
+ bool blur;
13
+ bool sticky;
14
+ bool interactive;
15
+ std::string html;
16
+ bool scroll;
17
+ };
18
+
19
+ class WidgetManager {
20
+ public:
21
+ static void* CreateWidget(const std::string& url, const WidgetOptions& options);
22
+ static void UpdateOpacity(void* handle, double opacity);
23
+ static void UpdatePosition(void* handle, int x, int y);
24
+ };
25
+
26
+ #endif
@@ -0,0 +1,70 @@
1
+ #include "WidgetManager.h"
2
+ #include <windows.h>
3
+ #include <string>
4
+ #include <vector>
5
+ #include <iostream>
6
+ #include <map>
7
+
8
+ // Simple argument parser
9
+ std::map<std::string, std::string> parse_args(int argc, char* argv[]) {
10
+ std::map<std::string, std::string> args;
11
+ for (int i = 1; i < argc; ++i) {
12
+ std::string arg = argv[i];
13
+ if (arg.substr(0, 2) == "--") {
14
+ size_t pos = arg.find('=');
15
+ if (pos != std::string::npos) {
16
+ args[arg.substr(2, pos - 2)] = arg.substr(pos + 1);
17
+ } else if (i + 1 < argc) {
18
+ args[arg.substr(2)] = argv[++i];
19
+ }
20
+ }
21
+ }
22
+ return args;
23
+ }
24
+
25
+ int main(int argc, char* argv[]) {
26
+ std::map<std::string, std::string> args = parse_args(argc, argv);
27
+
28
+ if (args.find("url") == args.end()) {
29
+ std::cerr << "Usage: widget_host --url <url> [options]" << std::endl;
30
+ return 1;
31
+ }
32
+
33
+ std::string url = args["url"];
34
+ WidgetOptions options;
35
+ options.width = args.count("width") ? std::stoi(args["width"]) : 400;
36
+ options.height = args.count("height") ? std::stoi(args["height"]) : 400;
37
+ options.x = args.count("x") ? std::stoi(args["x"]) : 100;
38
+ options.y = args.count("y") ? std::stoi(args["y"]) : 100;
39
+ options.opacity = args.count("opacity") ? std::stod(args["opacity"]) : 1.0;
40
+ options.blur = args.count("blur") ? (args["blur"] == "true") : false;
41
+ options.sticky = args.count("sticky") ? (args["sticky"] == "true") : true;
42
+ options.interactive = args.count("interactive") ? (args["interactive"] == "true") : true;
43
+ options.scroll = args.count("scroll") ? (args["scroll"] == "true") : true;
44
+
45
+ std::cout << "[Host] Starting widget for: " << url << std::endl;
46
+
47
+ // Direct call to CreateWidget (which starts the loop if needed)
48
+ void* handle = WidgetManager::CreateWidget(url, options);
49
+
50
+ if (!handle) {
51
+ std::cerr << "[Host] Failed to create widget." << std::endl;
52
+ return 1;
53
+ }
54
+
55
+ // In standalone mode, we need to keep the main thread alive
56
+ // since the loop runs in a detached thread in WidgetManager.cpp.
57
+ // However, it's better if we just wait for the window to close.
58
+
59
+ // For now, let's just sleep or wait for a signal.
60
+ // Ideally, WidgetManager should provide a way to wait for all windows to close.
61
+
62
+ std::cout << "[Host] Widget active. Press Ctrl+C to terminate host." << std::endl;
63
+
64
+ // Simple wait loop
65
+ while (true) {
66
+ Sleep(1000);
67
+ }
68
+
69
+ return 0;
70
+ }
@@ -0,0 +1,278 @@
1
+ #include "WidgetManager.h"
2
+ #include <gtk/gtk.h>
3
+ #include <webkit2/webkit2.h>
4
+ #include <thread>
5
+ #include <mutex>
6
+ #include <condition_variable>
7
+
8
+ // Try to use gtk-layer-shell for Wayland support
9
+ #ifdef HAVE_GTK_LAYER_SHELL
10
+ #include <gtk-layer-shell/gtk-layer-shell.h>
11
+ #endif
12
+
13
+ // X11 backend
14
+ #include <gdk/gdk.h>
15
+ #ifdef GDK_WINDOWING_X11
16
+ #include <X11/Xlib.h>
17
+ #include <X11/Xatom.h>
18
+ #include <gdk/gdkx.h>
19
+ #endif
20
+
21
+ struct GtkWidgetContext {
22
+ GtkWidget* window;
23
+ GtkWidget* webview;
24
+ bool wayland;
25
+ };
26
+
27
+ struct PosTask {
28
+ GtkWidget* w;
29
+ int x;
30
+ int y;
31
+ bool wayland;
32
+ };
33
+
34
+ static GMainContext* gtk_context = nullptr;
35
+
36
+ void run_gtk_loop() {
37
+ // Force XWayland (X11 compat layer) to enable EWMH keep-below on GNOME Wayland
38
+ setenv("GDK_BACKEND", "x11", 1);
39
+ gtk_init(NULL, NULL);
40
+ gtk_context = g_main_context_default();
41
+ gtk_main();
42
+ }
43
+
44
+ struct CreateTask {
45
+ const std::string* url;
46
+ const WidgetOptions* options;
47
+ void* result;
48
+ std::mutex mutex;
49
+ std::condition_variable cv;
50
+ bool done;
51
+ CreateTask(const std::string* u, const WidgetOptions* o)
52
+ : url(u), options(o), result(nullptr), done(false) {}
53
+ };
54
+
55
+ #ifdef GDK_WINDOWING_X11
56
+ // Proper EWMH way: send _NET_WM_STATE_BELOW client message to the WM
57
+ static void send_wm_below(Display* dpy, Window xid) {
58
+ XClientMessageEvent ev = {};
59
+ ev.type = ClientMessage;
60
+ ev.display = dpy;
61
+ ev.window = xid;
62
+ ev.message_type = XInternAtom(dpy, "_NET_WM_STATE", False);
63
+ ev.format = 32;
64
+ ev.data.l[0] = 1; // _NET_WM_STATE_ADD
65
+ ev.data.l[1] = (long)XInternAtom(dpy, "_NET_WM_STATE_BELOW", False);
66
+ ev.data.l[2] = 0;
67
+ ev.data.l[3] = 1;
68
+ ev.data.l[4] = 0;
69
+ XSendEvent(dpy, DefaultRootWindow(dpy), False,
70
+ SubstructureRedirectMask | SubstructureNotifyMask,
71
+ (XEvent*)&ev);
72
+ XFlush(dpy);
73
+ }
74
+
75
+ struct KeepBelowData {
76
+ Display* dpy;
77
+ Window xid;
78
+ };
79
+ #endif
80
+
81
+ gboolean create_widget_idle(gpointer data) {
82
+ CreateTask* task = (CreateTask*)data;
83
+
84
+ GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
85
+ gtk_window_set_default_size(GTK_WINDOW(window), task->options->width, task->options->height);
86
+ gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
87
+ gtk_window_set_skip_taskbar_hint(GTK_WINDOW(window), TRUE);
88
+ gtk_window_set_skip_pager_hint(GTK_WINDOW(window), TRUE);
89
+ gtk_window_set_accept_focus(GTK_WINDOW(window), task->options->interactive);
90
+ gtk_window_set_focus_on_map(GTK_WINDOW(window), task->options->interactive);
91
+
92
+ bool wayland_pinned = false;
93
+
94
+ // === WAYLAND: Use gtk-layer-shell ===
95
+ #ifdef HAVE_GTK_LAYER_SHELL
96
+ if (gtk_layer_is_supported()) {
97
+ gtk_layer_init_for_window(GTK_WINDOW(window));
98
+ gtk_layer_set_layer(GTK_WINDOW(window), GTK_LAYER_SHELL_LAYER_BACKGROUND);
99
+ gtk_layer_set_anchor(GTK_WINDOW(window), GTK_LAYER_SHELL_EDGE_LEFT, TRUE);
100
+ gtk_layer_set_anchor(GTK_WINDOW(window), GTK_LAYER_SHELL_EDGE_TOP, TRUE);
101
+ gtk_layer_set_margin(GTK_WINDOW(window), GTK_LAYER_SHELL_EDGE_LEFT, task->options->x);
102
+ gtk_layer_set_margin(GTK_WINDOW(window), GTK_LAYER_SHELL_EDGE_TOP, task->options->y);
103
+ gtk_layer_set_exclusive_zone(GTK_WINDOW(window), -1);
104
+ gtk_layer_set_keyboard_mode(GTK_WINDOW(window), task->options->interactive ? GTK_LAYER_SHELL_KEYBOARD_MODE_ON_DEMAND : GTK_LAYER_SHELL_KEYBOARD_MODE_NONE);
105
+ wayland_pinned = true;
106
+ }
107
+ #endif
108
+
109
+ // === X11 / XWayland: EWMH keep-below ===
110
+ if (!wayland_pinned && task->options->sticky) {
111
+ gtk_window_stick(GTK_WINDOW(window));
112
+ // Set keep_below hint BEFORE showing — WM respects this on map
113
+ gtk_window_set_keep_below(GTK_WINDOW(window), TRUE);
114
+ // DESKTOP hint removes the window from all WM management lists
115
+ gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DESKTOP);
116
+ }
117
+
118
+ GdkScreen* screen = gtk_widget_get_screen(window);
119
+ GdkVisual* visual = gdk_screen_get_rgba_visual(screen);
120
+ if (visual) gtk_widget_set_visual(window, visual);
121
+
122
+ GtkWidget* webview = webkit_web_view_new();
123
+ gtk_container_add(GTK_CONTAINER(window), webview);
124
+
125
+ if (!task->options->html.empty()) {
126
+ webkit_web_view_load_html(WEBKIT_WEB_VIEW(webview), task->options->html.c_str(), task->url->empty() ? NULL : task->url->c_str());
127
+ } else {
128
+ webkit_web_view_load_uri(WEBKIT_WEB_VIEW(webview), task->url->c_str());
129
+ }
130
+
131
+ // Apply opacity from options
132
+ if (task->options->opacity < 1.0) {
133
+ gtk_widget_set_opacity(window, task->options->opacity);
134
+ }
135
+
136
+ gtk_widget_set_app_paintable(window, TRUE);
137
+
138
+ // Apply blur: inject CSS into webview for backdrop blur effect
139
+ if (task->options->blur) {
140
+ const char* blur_css = "body { backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); }";
141
+ WebKitUserContentManager* ucm = webkit_web_view_get_user_content_manager(WEBKIT_WEB_VIEW(webview));
142
+ WebKitUserStyleSheet* sheet = webkit_user_style_sheet_new(
143
+ blur_css,
144
+ WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
145
+ WEBKIT_USER_STYLE_LEVEL_USER,
146
+ NULL, NULL);
147
+ webkit_user_content_manager_add_style_sheet(ucm, sheet);
148
+ }
149
+
150
+ // Hide Scrollbars and handle Overflow
151
+ {
152
+ std::string scroll_css = "::-webkit-scrollbar { display: none !important; width: 0 !important; } ";
153
+ if (!task->options->scroll) {
154
+ scroll_css += "body { overflow: hidden !important; }";
155
+ }
156
+ WebKitUserContentManager* ucm = webkit_web_view_get_user_content_manager(WEBKIT_WEB_VIEW(webview));
157
+ WebKitUserStyleSheet* sheet = webkit_user_style_sheet_new(
158
+ scroll_css.c_str(),
159
+ WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
160
+ WEBKIT_USER_STYLE_LEVEL_USER,
161
+ NULL, NULL);
162
+ webkit_user_content_manager_add_style_sheet(ucm, sheet);
163
+ }
164
+
165
+ // Aggressive Transparency
166
+ GdkRGBA rgba = {0, 0, 0, 0};
167
+ webkit_web_view_set_background_color(WEBKIT_WEB_VIEW(webview), &rgba);
168
+
169
+ // Explicitly set window background to transparent too
170
+ gtk_widget_override_background_color(window, GTK_STATE_FLAG_NORMAL, &rgba);
171
+
172
+ gtk_widget_show_all(window);
173
+
174
+ // Move AFTER show so the WM respects the position
175
+ gtk_window_move(GTK_WINDOW(window), task->options->x, task->options->y);
176
+
177
+ // X11: after show, send proper EWMH below request and start periodic re-enforcement
178
+ if (!wayland_pinned) {
179
+ #ifdef GDK_WINDOWING_X11
180
+ GdkWindow* gdk_win = gtk_widget_get_window(window);
181
+ if (GDK_IS_X11_WINDOW(gdk_win)) {
182
+ Display* dpy = GDK_WINDOW_XDISPLAY(gdk_win);
183
+ Window xid = GDK_WINDOW_XID(gdk_win);
184
+
185
+ // Force exact position via X11 (more reliable than GTK on XWayland)
186
+ XMoveWindow(dpy, xid, task->options->x, task->options->y);
187
+
188
+ // Initial below request
189
+ send_wm_below(dpy, xid);
190
+ XLowerWindow(dpy, xid);
191
+ XFlush(dpy);
192
+
193
+ // Periodic timer: re-send every 500ms to fight any WM restacking
194
+ auto* kd = new KeepBelowData{dpy, xid};
195
+ g_timeout_add(500, [](gpointer d) -> gboolean {
196
+ auto* data = static_cast<KeepBelowData*>(d);
197
+ send_wm_below(data->dpy, data->xid);
198
+ XLowerWindow(data->dpy, data->xid);
199
+ XFlush(data->dpy);
200
+ return G_SOURCE_CONTINUE;
201
+ }, kd);
202
+ }
203
+ #endif
204
+ }
205
+
206
+ GtkWidgetContext* ctx = new GtkWidgetContext();
207
+ ctx->window = window;
208
+ ctx->webview = webview;
209
+ ctx->wayland = wayland_pinned;
210
+
211
+ task->result = ctx;
212
+ {
213
+ std::lock_guard<std::mutex> lock(task->mutex);
214
+ task->done = true;
215
+ }
216
+ task->cv.notify_one();
217
+ return FALSE;
218
+ }
219
+
220
+ void* WidgetManager::CreateWidget(const std::string& url, const WidgetOptions& options) {
221
+ static std::once_flag init_flag;
222
+ std::call_once(init_flag, []() {
223
+ std::thread(run_gtk_loop).detach();
224
+ while (!gtk_context) std::this_thread::yield();
225
+ });
226
+
227
+ CreateTask task(&url, &options);
228
+ g_main_context_invoke(gtk_context, create_widget_idle, &task);
229
+
230
+ std::unique_lock<std::mutex> lock(task.mutex);
231
+ task.cv.wait(lock, [&]{ return task.done; });
232
+
233
+ return task.result;
234
+ }
235
+
236
+ void WidgetManager::UpdateOpacity(void* handle, double opacity) {
237
+ if (!handle) return;
238
+ g_main_context_invoke(gtk_context, [](gpointer data) -> gboolean {
239
+ auto pair = (std::pair<GtkWidget*, double>*)data;
240
+ gtk_widget_set_opacity(pair->first, pair->second);
241
+ delete pair;
242
+ return FALSE;
243
+ }, new std::pair<GtkWidget*, double>(((GtkWidgetContext*)handle)->window, opacity));
244
+ }
245
+
246
+ void WidgetManager::UpdatePosition(void* handle, int x, int y) {
247
+ if (!handle) return;
248
+ auto* ctx = static_cast<GtkWidgetContext*>(handle);
249
+ if (!ctx->window) return;
250
+
251
+ g_main_context_invoke(gtk_context, [](gpointer data) -> gboolean {
252
+ auto t = static_cast<PosTask*>(data);
253
+ if (!t->w) {
254
+ delete t;
255
+ return FALSE;
256
+ }
257
+
258
+ if (t->wayland) {
259
+ #ifdef HAVE_GTK_LAYER_SHELL
260
+ gtk_layer_set_margin(GTK_WINDOW(t->w), GTK_LAYER_SHELL_EDGE_LEFT, t->x);
261
+ gtk_layer_set_margin(GTK_WINDOW(t->w), GTK_LAYER_SHELL_EDGE_TOP, t->y);
262
+ #endif
263
+ } else {
264
+ gtk_window_move(GTK_WINDOW(t->w), t->x, t->y);
265
+ #ifdef GDK_WINDOWING_X11
266
+ GdkWindow* gdk_win = gtk_widget_get_window(t->w);
267
+ if (gdk_win && GDK_IS_X11_WINDOW(gdk_win)) {
268
+ Display* dpy = GDK_WINDOW_XDISPLAY(gdk_win);
269
+ Window xid = GDK_WINDOW_XID(gdk_win);
270
+ XMoveWindow(dpy, xid, t->x, t->y);
271
+ XFlush(dpy);
272
+ }
273
+ #endif
274
+ }
275
+ delete t;
276
+ return FALSE;
277
+ }, new PosTask{ctx->window, x, y, ctx->wayland});
278
+ }
@@ -0,0 +1,87 @@
1
+ #include "WidgetManager.h"
2
+ #import <AppKit/AppKit.h>
3
+ #import <WebKit/WebKit.h>
4
+
5
+ struct MacOSWidgetContext {
6
+ NSWindow* window;
7
+ WKWebView* webview;
8
+ };
9
+
10
+ void* WidgetManager::CreateWidget(const std::string& url, const WidgetOptions& options) {
11
+ NSRect frame = NSMakeRect(options.x, options.y, options.width, options.height);
12
+
13
+ NSWindow* window = [[NSWindow alloc] initWithContentRect:frame
14
+ styleMask:NSWindowStyleMaskBorderless
15
+ backing:NSBackingStoreBuffered
16
+ defer:NO];
17
+
18
+ [window setBackgroundColor:[NSColor clearColor]];
19
+ [window setOpaque:NO];
20
+ [window setHasShadow:NO];
21
+
22
+ if (options.sticky) {
23
+ [window setLevel:kCGDesktopWindowLevel - 1]; // Pin to desktop
24
+ [window setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces | NSWindowCollectionBehaviorStationary];
25
+ } else {
26
+ [window setLevel:NSFloatingWindowLevel];
27
+ }
28
+
29
+ if (options.blur) {
30
+ NSVisualEffectView* blurView = [[NSVisualEffectView alloc] initWithFrame:frame];
31
+ [blurView setBlendingMode:NSVisualEffectBlendingModeBehindWindow];
32
+ [blurView setMaterial:NSVisualEffectMaterialDark];
33
+ [blurView setState:NSVisualEffectStateActive];
34
+ [window setContentView:blurView];
35
+ }
36
+
37
+ WKWebViewConfiguration* config = [[WKWebViewConfiguration alloc] init];
38
+ // Security Shield: Sandbox settings
39
+ [[config preferences] setJavaScriptEnabled:YES];
40
+
41
+ // Inject CSS to hide scrollbars and handle overflow
42
+ std::string scroll_css = "var style = document.createElement('style');"
43
+ "style.innerHTML = '::-webkit-scrollbar { display: none !important; width: 0 !important; } ';";
44
+ if (!options.scroll) {
45
+ scroll_css += "style.innerHTML += 'body { overflow: hidden !important; }';";
46
+ }
47
+ scroll_css += "document.head.appendChild(style);";
48
+
49
+ WKUserScript* script = [[WKUserScript alloc] initWithSource:[NSString stringWithUTF8String:scroll_css.c_str()]
50
+ injectionTime:WKUserScriptInjectionTimeAtDocumentEnd
51
+ forMainFrameOnly:YES];
52
+ [[config userContentController] addUserScript:script];
53
+
54
+ WKWebView* webview = [[WKWebView alloc] initWithFrame:[[window contentView] bounds] configuration:config];
55
+ [webview setNavigationDelegate:nil];
56
+ [webview setValue:@(NO) forKey:@"drawsBackground"];
57
+
58
+ [[window contentView] addSubview:webview];
59
+
60
+ if (!options.html.empty()) {
61
+ [webview loadHTMLString:[NSString stringWithUTF8String:options.html.c_str()] baseURL:nil];
62
+ } else {
63
+ NSURL* nsUrl = [NSURL URLWithString:[NSString stringWithUTF8String:url.c_str()]];
64
+ [webview loadRequest:[NSURLRequest requestWithURL:nsUrl]];
65
+ }
66
+
67
+ [window makeKeyAndOrderFront:nil];
68
+
69
+ MacOSWidgetContext* ctx = new MacOSWidgetContext();
70
+ ctx->window = window;
71
+ ctx->webview = webview;
72
+
73
+ return ctx;
74
+ }
75
+
76
+ void WidgetManager::UpdateOpacity(void* handle, double opacity) {
77
+ MacOSWidgetContext* ctx = (MacOSWidgetContext*)handle;
78
+ [ctx->window setAlphaValue:opacity];
79
+ }
80
+
81
+ void WidgetManager::UpdatePosition(void* handle, int x, int y) {
82
+ MacOSWidgetContext* ctx = (MacOSWidgetContext*)handle;
83
+ NSRect frame = [ctx->window frame];
84
+ frame.origin.x = x;
85
+ frame.origin.y = y;
86
+ [ctx->window setFrame:frame display:YES];
87
+ }
@@ -0,0 +1,57 @@
1
+ #include <napi.h>
2
+ #include "WidgetManager.h"
3
+
4
+ Napi::Value CreateWidget(const Napi::CallbackInfo& info) {
5
+ Napi::Env env = info.Env();
6
+
7
+ if (info.Length() < 2 || !info[0].IsString() || !info[1].IsObject()) {
8
+ Napi::TypeError::New(env, "String and Object expected").ThrowAsJavaScriptException();
9
+ return env.Null();
10
+ }
11
+
12
+ std::string url = info[0].As<Napi::String>().Utf8Value();
13
+ Napi::Object opts = info[1].As<Napi::Object>();
14
+
15
+ WidgetOptions options;
16
+ options.width = opts.Get("width").ToNumber().Int32Value();
17
+ options.height = opts.Get("height").ToNumber().Int32Value();
18
+ options.x = opts.Get("x").ToNumber().Int32Value();
19
+ options.y = opts.Get("y").ToNumber().Int32Value();
20
+ options.opacity = opts.Has("opacity") ? opts.Get("opacity").ToNumber().DoubleValue() : 1.0;
21
+ options.blur = opts.Has("blur") ? opts.Get("blur").ToBoolean().Value() : false;
22
+ options.sticky = opts.Has("sticky") ? opts.Get("sticky").ToBoolean().Value() : true;
23
+ options.interactive = opts.Has("interactive") ? opts.Get("interactive").ToBoolean().Value() : true;
24
+ options.html = opts.Has("html") ? opts.Get("html").ToString().Utf8Value() : "";
25
+ options.scroll = opts.Has("scroll") ? opts.Get("scroll").ToBoolean().Value() : true;
26
+
27
+ void* handle = WidgetManager::CreateWidget(url, options);
28
+ return Napi::External<void>::New(env, handle);
29
+ }
30
+
31
+ Napi::Value UpdateOpacity(const Napi::CallbackInfo& info) {
32
+ Napi::Env env = info.Env();
33
+ void* handle = info[0].As<Napi::External<void>>().Data();
34
+ double opacity = info[1].As<Napi::Number>().DoubleValue();
35
+
36
+ WidgetManager::UpdateOpacity(handle, opacity);
37
+ return env.Undefined();
38
+ }
39
+
40
+ Napi::Value UpdatePosition(const Napi::CallbackInfo& info) {
41
+ Napi::Env env = info.Env();
42
+ void* handle = info[0].As<Napi::External<void>>().Data();
43
+ int x = info[1].As<Napi::Number>().Int32Value();
44
+ int y = info[2].As<Napi::Number>().Int32Value();
45
+
46
+ WidgetManager::UpdatePosition(handle, x, y);
47
+ return env.Undefined();
48
+ }
49
+
50
+ Napi::Object Init(Napi::Env env, Napi::Object exports) {
51
+ exports.Set("createWidget", Napi::Function::New(env, CreateWidget));
52
+ exports.Set("updateOpacity", Napi::Function::New(env, UpdateOpacity));
53
+ exports.Set("updatePosition", Napi::Function::New(env, UpdatePosition));
54
+ return exports;
55
+ }
56
+
57
+ NODE_API_MODULE(widget_shield_native, Init)