@@ -27,6 +27,7 @@ import {ContainerSM, COLOR, H1, Logo, Text, TextLink} from '@wireapp/react-ui-ki
27
27
import './Webview.css' ;
28
28
29
29
import { EVENT_TYPE } from '../../../../src/lib/eventType' ;
30
+ import { getLogger } from '../../../../src/logging/getLogger' ;
30
31
import {
31
32
abortAccountCreation ,
32
33
resetIdentity ,
@@ -58,7 +59,7 @@ const getEnvironmentUrl = (account: Account) => {
58
59
url . searchParams . set ( 'id' , account . id ) ;
59
60
60
61
// set the current language
61
- url . searchParams . set ( 'hl' , wrapperLocale ) ;
62
+ url . searchParams . set ( 'hl' , wrapperLocale ( ) ) ;
62
63
63
64
if ( account . ssoCode && account . isAdding ) {
64
65
url . pathname = '/auth' ;
@@ -104,18 +105,17 @@ const Webview = ({
104
105
const [ canDelete , setCanDelete ] = useState ( false ) ;
105
106
const [ url , setUrl ] = useState ( getEnvironmentUrl ( account ) ) ;
106
107
const [ webviewError , setWebviewError ] = useState < DidFailLoadEvent | null > ( null ) ;
108
+ const logger = getLogger ( 'Webview' ) ;
107
109
108
110
useEffect ( ( ) => {
109
111
const newUrl = getEnvironmentUrl ( account ) ;
110
- console . info ( `Loading WebApp URL "${ newUrl } " ...` ) ;
112
+ logger . info ( `Loading WebApp URL "${ newUrl } " ...` ) ;
111
113
if ( url !== newUrl && webviewRef . current ) {
112
114
setUrl ( newUrl ) ;
113
115
try {
114
- webviewRef . current
115
- . loadURL ( newUrl )
116
- . catch ( ( error : any ) => console . error ( `Navigating to ${ newUrl } failed` , error ) ) ;
116
+ webviewRef . current . loadURL ( newUrl ) . catch ( ( error : any ) => logger . error ( `Navigating to ${ newUrl } failed` , error ) ) ;
117
117
} catch ( error ) {
118
- console . warn ( 'Can not #loadURL before attaching webview to DOM' , error ) ;
118
+ logger . warn ( 'Can not #loadURL before attaching webview to DOM' , error ) ;
119
119
}
120
120
}
121
121
// eslint-disable-next-line react-hooks/exhaustive-deps
@@ -164,19 +164,21 @@ const Webview = ({
164
164
useEffect ( ( ) => {
165
165
const listener = ( error : DidFailLoadEvent ) => {
166
166
const urlOrigin = new URL ( getEnvironmentUrl ( account ) ) . origin ;
167
- console . warn ( `Webview fired "did-fail-load" for URL "${ error . validatedURL } " and account ID "${ account . id } "` ) ;
167
+ logger . warn ( `Webview fired "did-fail-load" for URL "${ error . validatedURL } " and account ID "${ account . id } "` ) ;
168
168
if ( error . validatedURL . startsWith ( urlOrigin ) ) {
169
169
setWebviewError ( error ) ;
170
170
}
171
171
} ;
172
- webviewRef . current ?. addEventListener ( ON_WEBVIEW_ERROR , listener ) ;
172
+
173
+ const currentWebview = webviewRef . current ;
174
+ currentWebview ?. addEventListener ( ON_WEBVIEW_ERROR , listener ) ;
173
175
174
176
return ( ) => {
175
- if ( webviewRef . current ) {
176
- webviewRef . current . removeEventListener ( ON_WEBVIEW_ERROR , listener ) ;
177
+ if ( currentWebview ) {
178
+ currentWebview . removeEventListener ( ON_WEBVIEW_ERROR , listener ) ;
177
179
}
178
180
} ;
179
- } , [ webviewRef , account ] ) ;
181
+ } , [ account , logger ] ) ;
180
182
181
183
useEffect ( ( ) => {
182
184
const onIpcMessage = ( { channel, args} : { args : unknown [ ] ; channel : string } ) => {
@@ -211,7 +213,7 @@ const Webview = ({
211
213
case EVENT_TYPE . LIFECYCLE . SIGNED_IN : {
212
214
if ( conversationJoinData ) {
213
215
const { code, key, domain} = conversationJoinData ;
214
- window . sendConversationJoinToHost ( accountId , code , key , domain ) ;
216
+ window . wireDesktop ?. sendConversationJoinToHost ( accountId , code , key , domain ) ;
215
217
setConversationJoinData ( accountId , undefined ) ;
216
218
}
217
219
updateAccountLifecycle ( accountId , channel ) ;
@@ -241,7 +243,7 @@ const Webview = ({
241
243
242
244
if ( isConversationJoinData ( data ) ) {
243
245
if ( accountLifecycle === EVENT_TYPE . LIFECYCLE . SIGNED_IN ) {
244
- window . sendConversationJoinToHost ( accountId , data . code , data . key , data . domain ) ;
246
+ window . wireDesktop ?. sendConversationJoinToHost ( accountId , data . code , data . key , data . domain ) ;
245
247
setConversationJoinData ( accountId , undefined ) ;
246
248
} else {
247
249
setConversationJoinData ( accountId , data ) ;
@@ -272,18 +274,19 @@ const Webview = ({
272
274
}
273
275
} ;
274
276
275
- webviewRef . current ?. addEventListener ( ON_IPC_MESSAGE , onIpcMessage ) ;
277
+ const currentWebview = webviewRef . current ;
278
+ currentWebview ?. addEventListener ( ON_IPC_MESSAGE , onIpcMessage ) ;
276
279
277
280
return ( ) => {
278
- if ( webviewRef . current ) {
279
- webviewRef . current . removeEventListener ( ON_IPC_MESSAGE , onIpcMessage ) ;
281
+ if ( currentWebview ) {
282
+ currentWebview . removeEventListener ( ON_IPC_MESSAGE , onIpcMessage ) ;
280
283
}
281
284
} ;
282
285
// eslint-disable-next-line react-hooks/exhaustive-deps
283
286
} , [ account , accountLifecycle , conversationJoinData ] ) ;
284
287
285
288
const deleteWebview = ( account : Account ) => {
286
- window . sendDeleteAccount ( account . id , account . sessionID ) . then ( ( ) => {
289
+ window . wireDesktop ?. sendDeleteAccount ( account . id , account . sessionID ) ? .then ( ( ) => {
287
290
abortAccountCreation ( account . id ) ;
288
291
} ) ;
289
292
} ;
0 commit comments