11
2+ var queryString = getQueryString ( ) ;
3+
24Promise . all ( [
35 getVoices ( ) ,
46 getSettings ( ) ,
@@ -12,7 +14,6 @@ function initialize(allVoices, settings, acceptLangs) {
1214 updateDependents ( settings ) ;
1315
1416 //close button
15- var queryString = getQueryString ( ) ;
1617 if ( queryString . referer ) {
1718 $ ( "button.close" ) . show ( )
1819 . click ( function ( ) {
@@ -25,7 +26,7 @@ function initialize(allVoices, settings, acceptLangs) {
2526 . click ( function ( ) {
2627 getAuthToken ( { interactive : true } )
2728 . then ( function ( token ) {
28- brapi . tabs . create ( { url : config . webAppUrl + "/premium-voices.html?t=" + token } ) ;
29+ createTabAndClosePopup ( { url : config . webAppUrl + "/premium-voices.html?t=" + token } ) ;
2930 } )
3031 . catch ( handleError )
3132 return false ;
@@ -67,14 +68,13 @@ function initialize(allVoices, settings, acceptLangs) {
6768 . val ( settings . voiceName || "" )
6869 . change ( function ( ) {
6970 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 ( { url : "custom-voices.html" } ) ;
72+ else if ( voiceName == "@languages" ) createTabAndClosePopup ( { url : "languages.html" } ) ;
7373 else if ( voiceName == "@piper" ) bgPageInvoke ( "managePiperVoices" )
7474 else saveSettings ( { voiceName : voiceName } ) ;
7575 } ) ;
7676 $ ( "#languages-edit-button" ) . click ( function ( ) {
77- brapi . tabs . create ( { url : "languages.html" } ) ;
77+ createTabAndClosePopup ( { url : "languages.html" } ) ;
7878 } )
7979
8080
@@ -161,7 +161,7 @@ function initialize(allVoices, settings, acceptLangs) {
161161
162162 //hot key
163163 $ ( "#hotkeys-link" ) . click ( function ( ) {
164- brapi . tabs . create ( { url : getHotkeySettingsUrl ( ) } ) ;
164+ createTabAndClosePopup ( { url : getHotkeySettingsUrl ( ) } ) ;
165165 } ) ;
166166}
167167
@@ -348,8 +348,9 @@ function handleError(err) {
348348 } )
349349 break ;
350350 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 ( {
352+ url : "firefox-perm.html?perms=" + encodeURIComponent ( JSON . stringify ( config . wavenetPerms ) ) + "&then=auth-wavenet"
353+ } )
353354 break ;
354355 case "#user-gesture" :
355356 getBackgroundPage ( )
@@ -379,6 +380,14 @@ function showAccountInfo(account) {
379380 }
380381}
381382
383+ function createTabAndClosePopup ( opts ) {
384+ brapi . tabs . create ( opts )
385+ . then ( ( ) => {
386+ if ( queryString . popup ) window . close ( )
387+ } )
388+ . catch ( handleError )
389+ }
390+
382391
383392
384393function createSlider ( elem , defaultValue , onChange , onSlideChange ) {
0 commit comments