Skip to content

Commit 1569890

Browse files
committed
webview: Use private members.
Signed-off-by: Anders Kaseorg <[email protected]>
1 parent 2ed400c commit 1569890

File tree

1 file changed

+21
-28
lines changed

1 file changed

+21
-28
lines changed

app/renderer/js/components/webview.ts

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ export default class WebView {
5151
}
5252

5353
static async create(props: WebViewProps): Promise<WebView> {
54-
const $element = generateNodeFromHtml(
54+
const $webview = generateNodeFromHtml(
5555
WebView.templateHtml(props),
5656
) as HTMLElement;
57-
props.$root.append($element);
57+
props.$root.append($webview);
5858

5959
await new Promise<void>((resolve) => {
60-
$element.addEventListener(
60+
$webview.addEventListener(
6161
"did-attach",
6262
() => {
6363
resolve();
@@ -87,37 +87,30 @@ export default class WebView {
8787
throw new TypeError("Failed to get WebContents ID");
8888
}
8989

90-
return new WebView(props, $element, webContentsId);
90+
return new WebView(props, $webview, webContentsId);
9191
}
9292

93-
zoomFactor: number;
94-
badgeCount: number;
95-
loading: boolean;
96-
customCss: string | false | null;
97-
$webviewsContainer: DOMTokenList;
98-
$el: HTMLElement;
99-
webContentsId: number;
93+
badgeCount = 0;
94+
loading = true;
95+
private zoomFactor = 1;
96+
private customCss: string | false | null;
97+
private readonly $webviewsContainer: DOMTokenList;
10098

10199
private constructor(
102100
readonly props: WebViewProps,
103-
$element: HTMLElement,
104-
webContentsId: number,
101+
private readonly $webview: HTMLElement,
102+
readonly webContentsId: number,
105103
) {
106-
this.zoomFactor = 1;
107-
this.loading = true;
108-
this.badgeCount = 0;
109104
this.customCss = ConfigUtil.getConfigItem("customCSS", null);
110105
this.$webviewsContainer = document.querySelector(
111106
"#webviews-container",
112107
)!.classList;
113-
this.$el = $element;
114-
this.webContentsId = webContentsId;
115108

116109
this.registerListeners();
117110
}
118111

119112
destroy(): void {
120-
this.$el.remove();
113+
this.$webview.remove();
121114
}
122115

123116
getWebContents(): WebContents {
@@ -136,11 +129,11 @@ export default class WebView {
136129
this.props.onTitleChange();
137130
});
138131

139-
this.$el.addEventListener("did-navigate-in-page", () => {
132+
this.$webview.addEventListener("did-navigate-in-page", () => {
140133
this.canGoBackButton();
141134
});
142135

143-
this.$el.addEventListener("did-navigate", () => {
136+
this.$webview.addEventListener("did-navigate", () => {
144137
this.canGoBackButton();
145138
});
146139

@@ -164,7 +157,7 @@ export default class WebView {
164157
contextMenu(webContents, event, menuParameters);
165158
});
166159

167-
this.$el.addEventListener("dom-ready", () => {
160+
this.$webview.addEventListener("dom-ready", () => {
168161
this.loading = false;
169162
this.props.switchLoading(false, this.props.url);
170163
this.show();
@@ -181,11 +174,11 @@ export default class WebView {
181174
}
182175
});
183176

184-
this.$el.addEventListener("did-start-loading", () => {
177+
this.$webview.addEventListener("did-start-loading", () => {
185178
this.props.switchLoading(true, this.props.url);
186179
});
187180

188-
this.$el.addEventListener("did-stop-loading", () => {
181+
this.$webview.addEventListener("did-stop-loading", () => {
189182
this.props.switchLoading(false, this.props.url);
190183
});
191184
}
@@ -208,7 +201,7 @@ export default class WebView {
208201
// To show or hide the loading indicator in the active tab
209202
this.$webviewsContainer.toggle("loaded", !this.loading);
210203

211-
this.$el.classList.add("active");
204+
this.$webview.classList.add("active");
212205
this.focus();
213206
this.props.onTitleChange();
214207
// Injecting preload css in webview to override some css rules
@@ -233,13 +226,13 @@ export default class WebView {
233226
}
234227

235228
focus(): void {
236-
this.$el.focus();
229+
this.$webview.focus();
237230
// Work around https://github.com/electron/electron/issues/31918
238-
this.$el.shadowRoot?.querySelector("iframe")?.focus();
231+
this.$webview.shadowRoot?.querySelector("iframe")?.focus();
239232
}
240233

241234
hide(): void {
242-
this.$el.classList.remove("active");
235+
this.$webview.classList.remove("active");
243236
}
244237

245238
load(): void {

0 commit comments

Comments
 (0)