1
1
2
+ var queryString = getQueryString ( ) ;
3
+
2
4
Promise . all ( [
3
5
getVoices ( ) ,
4
6
getSettings ( ) ,
@@ -12,7 +14,6 @@ function initialize(allVoices, settings, acceptLangs) {
12
14
updateDependents ( settings ) ;
13
15
14
16
//close button
15
- var queryString = getQueryString ( ) ;
16
17
if ( queryString . referer ) {
17
18
$ ( "button.close" ) . show ( )
18
19
. click ( function ( ) {
@@ -25,7 +26,7 @@ function initialize(allVoices, settings, acceptLangs) {
25
26
. click ( function ( ) {
26
27
getAuthToken ( { interactive : true } )
27
28
. then ( function ( token ) {
28
- brapi . tabs . create ( { url : config . webAppUrl + "/premium-voices.html?t=" + token } ) ;
29
+ createTabAndClosePopup ( config . webAppUrl + "/premium-voices.html?t=" + token )
29
30
} )
30
31
. catch ( handleError )
31
32
return false ;
@@ -67,14 +68,13 @@ function initialize(allVoices, settings, acceptLangs) {
67
68
. val ( settings . voiceName || "" )
68
69
. change ( function ( ) {
69
70
var voiceName = $ ( this ) . val ( ) ;
70
- if ( voiceName == "@custom" ) brapi . tabs . create ( { url : "custom-voices.html" } ) ;
71
- else if ( voiceName == "@languages" ) brapi . tabs . create ( { url : "languages.html" } ) ;
72
- else if ( voiceName == "@premium" ) brapi . tabs . create ( { url : "premium-voices.html" } ) ;
71
+ if ( voiceName == "@custom" ) createTabAndClosePopup ( "custom-voices.html" )
72
+ else if ( voiceName == "@languages" ) createTabAndClosePopup ( "languages.html" )
73
73
else if ( voiceName == "@piper" ) bgPageInvoke ( "managePiperVoices" )
74
74
else saveSettings ( { voiceName : voiceName } ) ;
75
75
} ) ;
76
76
$ ( "#languages-edit-button" ) . click ( function ( ) {
77
- brapi . tabs . create ( { url : "languages.html" } ) ;
77
+ createTabAndClosePopup ( "languages.html" )
78
78
} )
79
79
80
80
@@ -161,7 +161,7 @@ function initialize(allVoices, settings, acceptLangs) {
161
161
162
162
//hot key
163
163
$ ( "#hotkeys-link" ) . click ( function ( ) {
164
- brapi . tabs . create ( { url : getHotkeySettingsUrl ( ) } ) ;
164
+ createTabAndClosePopup ( getHotkeySettingsUrl ( ) )
165
165
} ) ;
166
166
}
167
167
@@ -348,8 +348,7 @@ function handleError(err) {
348
348
} )
349
349
break ;
350
350
case "#auth-wavenet" :
351
- createTab ( brapi . runtime . getURL ( "firefox-perm.html" ) + "?perms=" + encodeURIComponent ( JSON . stringify ( config . wavenetPerms ) ) + "&then=auth-wavenet" )
352
- . then ( ( ) => window . close ( ) )
351
+ createTabAndClosePopup ( "firefox-perm.html?perms=" + encodeURIComponent ( JSON . stringify ( config . wavenetPerms ) ) + "&then=auth-wavenet" )
353
352
break ;
354
353
case "#user-gesture" :
355
354
getBackgroundPage ( )
@@ -379,6 +378,14 @@ function showAccountInfo(account) {
379
378
}
380
379
}
381
380
381
+ function createTabAndClosePopup ( url ) {
382
+ brapi . tabs . create ( { url} )
383
+ . then ( ( ) => {
384
+ if ( queryString . isPopup ) window . close ( )
385
+ } )
386
+ . catch ( handleError )
387
+ }
388
+
382
389
383
390
384
391
function createSlider ( elem , defaultValue , onChange , onSlideChange ) {
0 commit comments