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 ( 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 ( "custom-voices.html" )
72+ else if ( voiceName == "@languages" ) createTabAndClosePopup ( "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 ( "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 ( getHotkeySettingsUrl ( ) )
165165 } ) ;
166166}
167167
@@ -348,8 +348,7 @@ 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 ( "firefox-perm.html?perms=" + encodeURIComponent ( JSON . stringify ( config . wavenetPerms ) ) + "&then=auth-wavenet" )
353352 break ;
354353 case "#user-gesture" :
355354 getBackgroundPage ( )
@@ -379,6 +378,14 @@ function showAccountInfo(account) {
379378 }
380379}
381380
381+ function createTabAndClosePopup ( url ) {
382+ brapi . tabs . create ( { url} )
383+ . then ( ( ) => {
384+ if ( queryString . isPopup ) window . close ( )
385+ } )
386+ . catch ( handleError )
387+ }
388+
382389
383390
384391function createSlider ( elem , defaultValue , onChange , onSlideChange ) {
0 commit comments