1 line
17 KiB
JavaScript
1 line
17 KiB
JavaScript
define(["exports","./../emby-apiclient/events.js","./../emby-apiclient/connectionmanager.js","./../common/appsettings.js","./../focusmanager.js","./../dialoghelper/dialoghelper.js","./../loading/loading.js","./../common/servicelocator.js","./../layoutmanager.js","./../common/globalize.js","./../listview/listview.js","./../emby-elements/emby-button/emby-button.js"],function(_exports,_events,_connectionmanager,_appsettings,_focusmanager,_dialoghelper,_loading,_servicelocator,_layoutmanager,_globalize,_listview,_embyButton){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,require(["formDialogStyle"]);var currentDisplayingProductInfos=[],currentDisplayingResolve=null,currentValidatingFeature=null,isCurrentDialogRejected=null;function showAlert(options){return Emby.importModule("./modules/common/dialogs/alert.js").then(function(alert){return alert(options)})}function showInAppPurchaseInfo(subscriptionOptions,unlockableProductInfo,dialogOptions){return new Promise(function(resolve,reject){!function(subscriptionOptions,unlockableProductInfo,dialogOptions,resolve,reject){cancelInAppPurchase(),currentDisplayingProductInfos=subscriptionOptions.slice(0),unlockableProductInfo&¤tDisplayingProductInfos.push(unlockableProductInfo);var i,length,dlg=_dialoghelper.default.createDialog({size:_layoutmanager.default.tv?"fullscreen":"fullscreen-border",removeOnClose:!0,scrollY:!1}),html=(dlg.classList.add("formDialog"),"");html=(html=(html=(html=(html=(html+='<div class="formDialogHeader">')+'<button is="paper-icon-button-light" class="btnCloseDialog hide-mouse-idle-tv" tabindex="-1"><i class="md-icon autortl"></i></button><h3 class="formDialogHeaderTitle">')+(dialogOptions.title||""))+"</h3></div>")+'<div is="emby-scroller" data-forcescrollbar="true" data-horizontal="false" data-focusscroll="true" class="formDialogContent"><div class="scrollSlider">')+'<form class="dialogContentInner dialog-content-centered padded-left padded-right"><p style="margin-top:0;">',html+=unlockableProductInfo?_globalize.default.translate("MessageUnlockAppWithPurchaseOrSupporter"):_globalize.default.translate("MessageUnlockAppWithSupporter");for(html=(html+='</p><p style="margin:1.5em 0 2em;">')+_globalize.default.translate("MessageToValidateSupporter")+"</p>",i=0,length=subscriptionOptions.length;i<length;i++)html=(html=(html=(html+="<p>")+'<button is="emby-button" type="button" class="raised button-submit block btnPurchase" data-email="'+(!1!==subscriptionOptions[i].requiresEmail)+'" data-featureid="'+subscriptionOptions[i].id+'"><span>')+subscriptionOptions[i].title)+"</span></button></p>";unlockableProductInfo&&(unlockText=_globalize.default.translate("ButtonUnlockWithPurchase"),unlockableProductInfo.price&&(unlockText=_globalize.default.translate("ButtonUnlockPrice",unlockableProductInfo.price)),html=(html+="<p>")+'<button is="emby-button" type="button" class="raised block btnPurchase" data-featureid="'+unlockableProductInfo.id+'"><span>'+unlockText+"</span></button></p>");html=(html+="<p>")+'<button is="emby-button" type="button" class="raised button-cancel block btnRestorePurchase"><span>'+_servicelocator.iapManager.getRestoreButtonText()+"</span></button></p>",subscriptionOptions.length&&(html=(html=html+('<h1 style="margin-top:1.5em;">'+_globalize.default.translate("HeaderBenefitsEmbyPremiere"))+'</h1><div style="margin-bottom:1em;">')+getSubscriptionBenefits().map(getSubscriptionBenefitHtml).join("")+"</div>");"playback"===dialogOptions.feature&&(html=(html+="<p>")+'<button is="emby-button" type="button" class="raised button-cancel block btnPlayMinute"><span>'+_globalize.default.translate("ButtonPlayOneMinute")+"</span></button></p>");html=(html=html+function(){var html="",termsOfPurchase=_servicelocator.iapManager.getTermsOfPurchase?_servicelocator.iapManager.getTermsOfPurchase():[];return termsOfPurchase.length&&(html+="<h1>"+_globalize.default.translate("HeaderTermsOfPurchase")+"</h1>",termsOfPurchase.push('<a is="emby-linkbutton" class="button-link" href="https://emby.media/privacy" target="_blank">'+_globalize.default.translate("PrivacyPolicy")+"</a>"),termsOfPurchase.push('<a is="emby-linkbutton" class="button-link" href="https://emby.media/terms" target="_blank">'+_globalize.default.translate("TermsOfUse")+"</a>"),html=(html+="<ul>")+termsOfPurchase.map(getPurchaseTermHtml).join("")+"</ul>"),html}()+"</form>")+"</div></div>",dlg.innerHTML=html,document.body.appendChild(dlg);var btnPurchases=dlg.querySelectorAll(".btnPurchase");for(i=0,length=btnPurchases.length;i<length;i++)btnPurchases[i].addEventListener("click",onPurchaseButtonClick);for(btnPurchases=dlg.querySelectorAll(".buttonPremiereInfo"),i=0,length=btnPurchases.length;i<length;i++)btnPurchases[i].addEventListener("click",showExternalPremiereInfo);isCurrentDialogRejected=!0;var resolveWithTimeLimit=!1,unlockText=dlg.querySelector(".btnPlayMinute");unlockText&&unlockText.addEventListener("click",function(){isCurrentDialogRejected=!(resolveWithTimeLimit=!0),_dialoghelper.default.close(dlg)});function onCloseButtonClick(){_dialoghelper.default.close(dlg)}dlg.querySelector(".btnRestorePurchase").addEventListener("click",function(){!function(unlockableProductInfo){var dlg=_dialoghelper.default.createDialog({size:_layoutmanager.default.tv?"fullscreen":"fullscreen-border",removeOnClose:!0,scrollY:!1}),html=(dlg.classList.add("formDialog"),"");html=(html=(html=(html=(html=(html=(html=(html=(html+='<div class="formDialogHeader">')+'<button is="paper-icon-button-light" class="btnCloseDialog hide-mouse-idle-tv" tabindex="-1"><i class="md-icon autortl"></i></button><h3 class="formDialogHeaderTitle">')+_servicelocator.iapManager.getRestoreButtonText())+"</h3></div>")+'<div is="emby-scroller" data-horizontal="false" data-forcescrollbar="true" data-focusscroll="true" class="formDialogContent"><div class="scrollSlider">')+'<div class="dialogContentInner dialog-content-centered padded-left padded-right"><p style="margin:0 0 2em;">')+_globalize.default.translate("HowDidYouPay"))+"</p><p>")+'<button is="emby-button" type="button" class="raised button-cancel block btnRestoreSub"><span>'+_globalize.default.translate("IHaveEmbyPremiere")+"</span></button></p>",unlockableProductInfo&&(html=(html+="<p>")+'<button is="emby-button" type="button" class="raised button-cancel block btnRestoreUnlock"><span>'+_globalize.default.translate("IPurchasedThisApp")+"</span></button></p>");html=(html+="</div>")+"</div></div>",dlg.innerHTML=html,document.body.appendChild(dlg),_loading.default.hide(),dlg.querySelector(".btnCloseDialog").addEventListener("click",function(){_dialoghelper.default.close(dlg)}),dlg.querySelector(".btnRestoreSub").addEventListener("click",function(){_dialoghelper.default.close(dlg),showAlert({text:_globalize.default.translate("MessageToValidateSupporter"),title:"Emby Premiere"})});unlockableProductInfo=dlg.querySelector(".btnRestoreUnlock");unlockableProductInfo&&unlockableProductInfo.addEventListener("click",function(){_dialoghelper.default.close(dlg),_servicelocator.iapManager.restorePurchase()});_dialoghelper.default.open(dlg)}(unlockableProductInfo)}),_loading.default.hide();var btnCloseDialogs=dlg.querySelectorAll(".btnCloseDialog");for(i=0,length=btnCloseDialogs.length;i<length;i++)btnCloseDialogs[i].addEventListener("click",onCloseButtonClick);dlg.classList.add("inAppPurchaseOverlay"),_dialoghelper.default.open(dlg).then(function(){var rejected=isCurrentDialogRejected;currentDisplayingProductInfos=[],isCurrentDialogRejected=currentValidatingFeature=currentDisplayingResolve=null,rejected?reject():resolveWithTimeLimit&&resolve({enableTimeLimit:!0})})}(subscriptionOptions,unlockableProductInfo,dialogOptions,resolve,reject),currentDisplayingResolve=resolve})}function showPeriodicMessageIfNeeded(feature){var intervalMs,settingsKey,lastMessage;return"playback"!==feature||(intervalMs=_servicelocator.iapManager.getPeriodicMessageIntervalMs(feature))<=0?Promise.resolve():(settingsKey="periodicmessage11-"+feature,(lastMessage=parseInt(_appsettings.default.get(settingsKey)||"0"))?!(Date.now()-lastMessage>intervalMs)||"554ae9ea56b94c1c82cc628f6de52d85"===(lastMessage=_connectionmanager.default.currentApiClient()).serverId()?Promise.resolve():_connectionmanager.default.getRegistrationInfo(_servicelocator.iapManager.getAdminFeatureName(feature),lastMessage,{viewOnly:!0}).catch(function(errorResult){return"overlimit"===errorResult?(_appsettings.default.set(settingsKey,Date.now()),Promise.resolve()):function(settingsKey){return new Promise(function(resolve,reject){for(var dlg=_dialoghelper.default.createDialog({size:_layoutmanager.default.tv?"fullscreen":"fullscreen-border",removeOnClose:!0,scrollY:!1}),html=(dlg.classList.add("formDialog"),""),seconds=(html=(html=(html=(html=(html=(html=(html=(html=(html=(html=(html=html+'<div class="formDialogHeader">'+'<button is="paper-icon-button-light" class="btnCancelSupporterInfo hide-mouse-idle-tv" tabindex="-1"><i class="md-icon autortl"></i></button>')+'<h3 class="formDialogHeaderTitle">Emby Premiere'+"</h3>")+"</div>"+'<div is="emby-scroller" data-horizontal="false" data-forcescrollbar="true" data-focusscroll="true" class="formDialogContent">')+'<div class="scrollSlider">'+'<div class="dialogContentInner dialog-content-centered padded-left padded-right">')+('<h1 style="margin-top: 0;">'+_globalize.default.translate("HeaderDiscoverEmbyPremiere")+"</h1>"))+("<p>"+_globalize.default.translate("MessageDidYouKnowCinemaMode")+"</p>"))+("<p>"+_globalize.default.translate("CinemaModeFeatureDescription")+"</p>"))+("<h2>"+_globalize.default.translate("HeaderBenefitsEmbyPremiere")+"</h2>")+"<div>")+getSubscriptionBenefits().map(getSubscriptionBenefitHtml).join("")+"</div>")+"<br/>"+'<div class="formDialogFooter">')+('<button is="emby-button" type="button" class="raised button-submit block btnGetPremiere block formDialogFooterItem autofocus"><span>'+_globalize.default.translate("HeaderBecomeProjectSupporter")+"</span></button>"),11),isRejected=(html=(html+='<div class="continueTimeText formDialogFooterItem" style="margin: 1.5em 0 .5em;">'+_globalize.default.translate("ContinueInSecondsValue",seconds)+"</div>")+('<button is="emby-button" type="button" class="raised button-cancel block btnContinue block formDialogFooterItem hide"><span>'+_globalize.default.translate("Continue")+"</span></button>"),dlg.innerHTML=html=(html=html+"</div>"+"</div>")+"</div>"+"</div>",!0),timeTextInterval=setInterval(function(){var btnContinue;--seconds<=0?(clearInterval(timeTextInterval),dlg.querySelector(".continueTimeText").classList.add("hide"),(btnContinue=dlg.querySelector(".btnContinue")).classList.remove("hide"),_focusmanager.default.focus(btnContinue)):dlg.querySelector(".continueTimeText").innerHTML=_globalize.default.translate("ContinueInSecondsValue",seconds)},1e3),btnPurchases=dlg.querySelectorAll(".buttonPremiereInfo"),i=0,length=btnPurchases.length;i<length;i++)btnPurchases[i].addEventListener("click",showExternalPremiereInfo);dlg.addEventListener("close",function(e){clearInterval(timeTextInterval),(isRejected?reject:(_appsettings.default.set(settingsKey,Date.now()),resolve))()}),dlg.querySelector(".btnContinue").addEventListener("click",function(){isRejected=!1,_dialoghelper.default.close(dlg)}),dlg.querySelector(".btnGetPremiere").addEventListener("click",showPremiereInfo),_dialoghelper.default.open(dlg);function onCancelClick(){_dialoghelper.default.close(dlg)}var elems=dlg.querySelectorAll(".btnCancelSupporterInfo");for(i=0,length=elems.length;i<length;i++)elems[i].addEventListener("click",onCancelClick)})}(settingsKey)}):(_appsettings.default.set(settingsKey,Date.now()),Promise.resolve()))}function cancelInAppPurchase(){var elem=document.querySelector(".inAppPurchaseOverlay");elem&&_dialoghelper.default.close(elem)}function showExternalPremiereInfo(){_servicelocator.shell.openUrl(_servicelocator.iapManager.getPremiumInfoUrl())}function getPurchaseTermHtml(term){return"<li>"+term+"</li>"}function getSubscriptionBenefits(){var list=[];return list.push({name:_globalize.default.translate("HeaderFreeApps"),icon:"",autortl:!1,text:_globalize.default.translate("FreeAppsFeatureDescription")}),_servicelocator.appHost.supports("sync")&&list.push({name:_globalize.default.translate("HeaderOfflineDownloads"),icon:"",text:_globalize.default.translate("HeaderOfflineDownloadsDescription")}),list.push({name:_globalize.default.translate("LiveTV"),icon:"",text:_globalize.default.translate("LiveTvFeatureDescription")}),list.push({name:"Emby DVR",icon:"",text:_globalize.default.translate("DvrFeatureDescription")}),list.push({name:_globalize.default.translate("HeaderCinemaMode"),icon:"",text:_globalize.default.translate("CinemaModeFeatureDescription")}),list.push({name:_globalize.default.translate("HeaderCloudSync"),icon:"",text:_globalize.default.translate("CloudSyncFeatureDescription")}),list}function getSubscriptionBenefitHtml(item){var enableLink=_servicelocator.appHost.supports("externalpremium"),html="",cssClass="listItem listItem-border";return _layoutmanager.default.tv&&(cssClass+=" listItem-focusscale"),html+=enableLink?'<button type="button" class="'+(cssClass+=" listItem-button")+' buttonPremiereInfo">':'<div class="'+cssClass+'">',!1===item.autortl?html+='<i class="listItemIcon md-icon">'+item.icon+"</i>":html+='<i class="listItemIcon md-icon autortl">'+item.icon+"</i>",html=(html=(html=(html=(html+='<div class="listItemBody">')+'<h3 class="listItemBodyText">'+item.name)+"</h3>"+'<div class="listItemBodyText listItemBodyText-secondary secondaryText">')+item.text+"</div>")+"</div>"+(enableLink?"</button>":"</div>")}function onPurchaseButtonClick(){var featureId=this.getAttribute("data-featureid");"true"===this.getAttribute("data-email")?function(){if(_connectionmanager.default.isLoggedIntoConnect()){var connectUser=_connectionmanager.default.connectUser();if(connectUser&&connectUser.Email)return Promise.resolve(connectUser.Email)}return function(options){return Emby.importModule("./modules/prompt/prompt.js").then(function(prompt){return prompt(options)})}({label:_globalize.default.translate("LabelEmailAddress")})}().then(function(email){_servicelocator.iapManager.beginPurchase(featureId,email)}):_servicelocator.iapManager.beginPurchase(featureId)}function showPremiereInfo(){return _servicelocator.appHost.supports("externalpremium")?(showExternalPremiereInfo(),Promise.resolve()):_servicelocator.iapManager.getSubscriptionOptions().then(function(subscriptionOptions){return showInAppPurchaseInfo(subscriptionOptions,null,{title:"Emby Premiere",feature:"sync"})})}_events.default.on(_servicelocator.iapManager,"productupdated",function(e,product){var feature,resolve=currentDisplayingResolve;product.owned&&resolve&¤tDisplayingProductInfos.filter(function(p){return product.id===p.id}).length?(isCurrentDialogRejected=!1,cancelInAppPurchase(),resolve()):(feature=currentValidatingFeature)&&_servicelocator.iapManager.isUnlockedByDefault(feature).then(function(){isCurrentDialogRejected=!1,cancelInAppPurchase(),resolve&&resolve()})}),_exports.default={validateFeature:function(feature,options){return options=options||{},console.log("validateFeature: "+feature),_servicelocator.iapManager.isUnlockedByDefault(feature,options).then(function(){return showPeriodicMessageIfNeeded(feature)},function(){var unlockableFeatureCacheKey="featurepurchased-"+feature;if("1"===_appsettings.default.get(unlockableFeatureCacheKey))return showPeriodicMessageIfNeeded(feature);var unlockableProduct=_servicelocator.iapManager.getProductInfo(feature);if(unlockableProduct){var unlockableCacheKey="productpurchased-"+unlockableProduct.id;if(unlockableProduct.owned)return _appsettings.default.set(unlockableFeatureCacheKey,"1"),_appsettings.default.set(unlockableCacheKey,"1"),showPeriodicMessageIfNeeded(feature);if("1"===_appsettings.default.get(unlockableCacheKey))return showPeriodicMessageIfNeeded(feature)}var unlockableProductInfo=unlockableProduct?{enableAppUnlock:!0,id:unlockableProduct.id,price:unlockableProduct.price,feature:feature}:null;return _servicelocator.iapManager.getSubscriptionOptions().then(function(subscriptionOptions){var registrationOptions,apiClient;return 0<subscriptionOptions.filter(function(p){return p.owned}).length?Promise.resolve():(registrationOptions={viewOnly:options.viewOnly,useCachedFailure:!1===options.showDialog},apiClient=options.serverId?_connectionmanager.default.getApiClient(options.serverId):_connectionmanager.default.currentApiClient(),_connectionmanager.default.getRegistrationInfo(_servicelocator.iapManager.getAdminFeatureName(feature),apiClient,registrationOptions).catch(function(errorResult){var alertPromise;return!1===options.showDialog?Promise.reject():(alertPromise=(alertPromise="overlimit"===errorResult?showAlert("Your Emby Premiere device limit has been exceeded. Please check with the owner of your Emby Server and have them contact Emby support at billingsupport@emby.media if necessary.").catch(function(){return Promise.resolve()}):alertPromise)||Promise.resolve()).then(function(){var dialogOptions={title:_globalize.default.translate("HeaderUnlockFeature"),feature:feature};return currentValidatingFeature=feature,showInAppPurchaseInfo(subscriptionOptions,unlockableProductInfo,dialogOptions)})}))})})},showPremiereInfo:showPremiereInfo}}); |