@@ -51,13 +51,13 @@ export default class WebView {
51
51
}
52
52
53
53
static async create ( props : WebViewProps ) : Promise < WebView > {
54
- const $element = generateNodeFromHtml (
54
+ const $webview = generateNodeFromHtml (
55
55
WebView . templateHtml ( props ) ,
56
56
) as HTMLElement ;
57
- props . $root . append ( $element ) ;
57
+ props . $root . append ( $webview ) ;
58
58
59
59
await new Promise < void > ( ( resolve ) => {
60
- $element . addEventListener (
60
+ $webview . addEventListener (
61
61
"did-attach" ,
62
62
( ) => {
63
63
resolve ( ) ;
@@ -87,37 +87,30 @@ export default class WebView {
87
87
throw new TypeError ( "Failed to get WebContents ID" ) ;
88
88
}
89
89
90
- return new WebView ( props , $element , webContentsId ) ;
90
+ return new WebView ( props , $webview , webContentsId ) ;
91
91
}
92
92
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 ;
100
98
101
99
private constructor (
102
100
readonly props : WebViewProps ,
103
- $element : HTMLElement ,
104
- webContentsId : number ,
101
+ private readonly $webview : HTMLElement ,
102
+ readonly webContentsId : number ,
105
103
) {
106
- this . zoomFactor = 1 ;
107
- this . loading = true ;
108
- this . badgeCount = 0 ;
109
104
this . customCss = ConfigUtil . getConfigItem ( "customCSS" , null ) ;
110
105
this . $webviewsContainer = document . querySelector (
111
106
"#webviews-container" ,
112
107
) ! . classList ;
113
- this . $el = $element ;
114
- this . webContentsId = webContentsId ;
115
108
116
109
this . registerListeners ( ) ;
117
110
}
118
111
119
112
destroy ( ) : void {
120
- this . $el . remove ( ) ;
113
+ this . $webview . remove ( ) ;
121
114
}
122
115
123
116
getWebContents ( ) : WebContents {
@@ -136,11 +129,11 @@ export default class WebView {
136
129
this . props . onTitleChange ( ) ;
137
130
} ) ;
138
131
139
- this . $el . addEventListener ( "did-navigate-in-page" , ( ) => {
132
+ this . $webview . addEventListener ( "did-navigate-in-page" , ( ) => {
140
133
this . canGoBackButton ( ) ;
141
134
} ) ;
142
135
143
- this . $el . addEventListener ( "did-navigate" , ( ) => {
136
+ this . $webview . addEventListener ( "did-navigate" , ( ) => {
144
137
this . canGoBackButton ( ) ;
145
138
} ) ;
146
139
@@ -164,7 +157,7 @@ export default class WebView {
164
157
contextMenu ( webContents , event , menuParameters ) ;
165
158
} ) ;
166
159
167
- this . $el . addEventListener ( "dom-ready" , ( ) => {
160
+ this . $webview . addEventListener ( "dom-ready" , ( ) => {
168
161
this . loading = false ;
169
162
this . props . switchLoading ( false , this . props . url ) ;
170
163
this . show ( ) ;
@@ -181,11 +174,11 @@ export default class WebView {
181
174
}
182
175
} ) ;
183
176
184
- this . $el . addEventListener ( "did-start-loading" , ( ) => {
177
+ this . $webview . addEventListener ( "did-start-loading" , ( ) => {
185
178
this . props . switchLoading ( true , this . props . url ) ;
186
179
} ) ;
187
180
188
- this . $el . addEventListener ( "did-stop-loading" , ( ) => {
181
+ this . $webview . addEventListener ( "did-stop-loading" , ( ) => {
189
182
this . props . switchLoading ( false , this . props . url ) ;
190
183
} ) ;
191
184
}
@@ -208,7 +201,7 @@ export default class WebView {
208
201
// To show or hide the loading indicator in the active tab
209
202
this . $webviewsContainer . toggle ( "loaded" , ! this . loading ) ;
210
203
211
- this . $el . classList . add ( "active" ) ;
204
+ this . $webview . classList . add ( "active" ) ;
212
205
this . focus ( ) ;
213
206
this . props . onTitleChange ( ) ;
214
207
// Injecting preload css in webview to override some css rules
@@ -233,13 +226,13 @@ export default class WebView {
233
226
}
234
227
235
228
focus ( ) : void {
236
- this . $el . focus ( ) ;
229
+ this . $webview . focus ( ) ;
237
230
// Work around https://github.com/electron/electron/issues/31918
238
- this . $el . shadowRoot ?. querySelector ( "iframe" ) ?. focus ( ) ;
231
+ this . $webview . shadowRoot ?. querySelector ( "iframe" ) ?. focus ( ) ;
239
232
}
240
233
241
234
hide ( ) : void {
242
- this . $el . classList . remove ( "active" ) ;
235
+ this . $webview . classList . remove ( "active" ) ;
243
236
}
244
237
245
238
load ( ) : void {
0 commit comments