-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdemo-transparent.ts
40 lines (29 loc) · 1.14 KB
/
demo-transparent.ts
1
2
3
4
5
6
7
8
9
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
import path from "path";
import { WidgetAttribute, WidgetEventTypes, QColor } from "@nodegui/nodegui";
import { QWebEngineView, QWebChannel } from ".";
const index = "file://" + path.resolve(__dirname, "..", "public/index.html");
const webview = new QWebEngineView();
webview.setAttribute(WidgetAttribute.WA_TranslucentBackground, true);
webview.setAttribute(WidgetAttribute.WA_OpaquePaintEvent, true);
webview.setAttribute(WidgetAttribute.WA_AlwaysStackOnTop, true);
webview.load(index);
webview.addEventListener("urlChanged", (url) => {
console.log("changed to", url);
});
webview.addEventListener("selectionChanged", () => {
console.log("selection", webview.property("selectedText").toString());
});
webview.addEventListener("loadFinished", () => {
const js = `alert('nodeui');`;
const page = webview.page();
page.runJavaScript(js);
});
const color = new QColor("transparent");
webview.addEventListener(WidgetEventTypes.Paint, () => {
webview.page().setBackgroundColor(color);
});
const channel = new QWebChannel();
webview.page().setWebChannel(channel);
webview.page().setBackgroundColor(color);
webview.show();
(global as any).wv = webview;