Skip to content

Commit 9a8680d

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

File tree

1 file changed

+84
-84
lines changed

1 file changed

+84
-84
lines changed

app/renderer/js/components/webview.ts

Lines changed: 84 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,88 @@ export default class WebView {
117117
return remote.webContents.fromId(this.webContentsId);
118118
}
119119

120-
registerListeners(): void {
120+
showNotificationSettings(): void {
121+
this.send("show-notification-settings");
122+
}
123+
124+
focus(): void {
125+
this.$webview.focus();
126+
// Work around https://github.com/electron/electron/issues/31918
127+
this.$webview.shadowRoot?.querySelector("iframe")?.focus();
128+
}
129+
130+
hide(): void {
131+
this.$webview.classList.remove("active");
132+
}
133+
134+
load(): void {
135+
this.show();
136+
}
137+
138+
zoomIn(): void {
139+
this.zoomFactor += 0.1;
140+
this.getWebContents().setZoomFactor(this.zoomFactor);
141+
}
142+
143+
zoomOut(): void {
144+
this.zoomFactor -= 0.1;
145+
this.getWebContents().setZoomFactor(this.zoomFactor);
146+
}
147+
148+
zoomActualSize(): void {
149+
this.zoomFactor = 1;
150+
this.getWebContents().setZoomFactor(this.zoomFactor);
151+
}
152+
153+
logOut(): void {
154+
this.send("logout");
155+
}
156+
157+
showKeyboardShortcuts(): void {
158+
this.send("show-keyboard-shortcuts");
159+
}
160+
161+
openDevTools(): void {
162+
this.getWebContents().openDevTools();
163+
}
164+
165+
back(): void {
166+
if (this.getWebContents().canGoBack()) {
167+
this.getWebContents().goBack();
168+
this.focus();
169+
}
170+
}
171+
172+
canGoBackButton(): void {
173+
const $backButton = document.querySelector(
174+
"#actions-container #back-action",
175+
)!;
176+
$backButton.classList.toggle("disable", !this.getWebContents().canGoBack());
177+
}
178+
179+
forward(): void {
180+
if (this.getWebContents().canGoForward()) {
181+
this.getWebContents().goForward();
182+
}
183+
}
184+
185+
reload(): void {
186+
this.hide();
187+
// Shows the loading indicator till the webview is reloaded
188+
this.$webviewsContainer.remove("loaded");
189+
this.loading = true;
190+
this.props.switchLoading(true, this.props.url);
191+
this.getWebContents().reload();
192+
}
193+
194+
send<Channel extends keyof RendererMessage>(
195+
channel: Channel,
196+
...args: Parameters<RendererMessage[Channel]>
197+
): void {
198+
ipcRenderer.sendTo(this.webContentsId, channel, ...args);
199+
}
200+
201+
private registerListeners(): void {
121202
const webContents = this.getWebContents();
122203

123204
if (shouldSilentWebview) {
@@ -183,16 +264,12 @@ export default class WebView {
183264
});
184265
}
185266

186-
getBadgeCount(title: string): number {
267+
private getBadgeCount(title: string): number {
187268
const messageCountInTitle = /^\((\d+)\)/.exec(title);
188269
return messageCountInTitle ? Number(messageCountInTitle[1]) : 0;
189270
}
190271

191-
showNotificationSettings(): void {
192-
this.send("show-notification-settings");
193-
}
194-
195-
show(): void {
272+
private show(): void {
196273
// Do not show WebView if another tab was selected and this tab should be in background.
197274
if (!this.props.isActive()) {
198275
return;
@@ -224,81 +301,4 @@ export default class WebView {
224301
this.getWebContents().insertCSS(fs.readFileSync(customCss, "utf8")))();
225302
}
226303
}
227-
228-
focus(): void {
229-
this.$webview.focus();
230-
// Work around https://github.com/electron/electron/issues/31918
231-
this.$webview.shadowRoot?.querySelector("iframe")?.focus();
232-
}
233-
234-
hide(): void {
235-
this.$webview.classList.remove("active");
236-
}
237-
238-
load(): void {
239-
this.show();
240-
}
241-
242-
zoomIn(): void {
243-
this.zoomFactor += 0.1;
244-
this.getWebContents().setZoomFactor(this.zoomFactor);
245-
}
246-
247-
zoomOut(): void {
248-
this.zoomFactor -= 0.1;
249-
this.getWebContents().setZoomFactor(this.zoomFactor);
250-
}
251-
252-
zoomActualSize(): void {
253-
this.zoomFactor = 1;
254-
this.getWebContents().setZoomFactor(this.zoomFactor);
255-
}
256-
257-
logOut(): void {
258-
this.send("logout");
259-
}
260-
261-
showKeyboardShortcuts(): void {
262-
this.send("show-keyboard-shortcuts");
263-
}
264-
265-
openDevTools(): void {
266-
this.getWebContents().openDevTools();
267-
}
268-
269-
back(): void {
270-
if (this.getWebContents().canGoBack()) {
271-
this.getWebContents().goBack();
272-
this.focus();
273-
}
274-
}
275-
276-
canGoBackButton(): void {
277-
const $backButton = document.querySelector(
278-
"#actions-container #back-action",
279-
)!;
280-
$backButton.classList.toggle("disable", !this.getWebContents().canGoBack());
281-
}
282-
283-
forward(): void {
284-
if (this.getWebContents().canGoForward()) {
285-
this.getWebContents().goForward();
286-
}
287-
}
288-
289-
reload(): void {
290-
this.hide();
291-
// Shows the loading indicator till the webview is reloaded
292-
this.$webviewsContainer.remove("loaded");
293-
this.loading = true;
294-
this.props.switchLoading(true, this.props.url);
295-
this.getWebContents().reload();
296-
}
297-
298-
send<Channel extends keyof RendererMessage>(
299-
channel: Channel,
300-
...args: Parameters<RendererMessage[Channel]>
301-
): void {
302-
ipcRenderer.sendTo(this.webContentsId, channel, ...args);
303-
}
304304
}

0 commit comments

Comments
 (0)