mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
fix sync status display
This commit is contained in:
parent
a07e6b59a3
commit
94a5cf7549
26 changed files with 415 additions and 276 deletions
245
dashboard-ui/cordova/registrationservices.js
vendored
245
dashboard-ui/cordova/registrationservices.js
vendored
|
@ -1,86 +1,56 @@
|
|||
(function () {
|
||||
|
||||
function isAndroid() {
|
||||
|
||||
return $.browser.android;
|
||||
}
|
||||
|
||||
function getPremiumUnlockFeatureId() {
|
||||
|
||||
if (isAndroid()) {
|
||||
return "com.mb.android.unlock";
|
||||
}
|
||||
|
||||
return 'appunlock';
|
||||
}
|
||||
|
||||
function validatePlayback(deferred) {
|
||||
|
||||
// Don't require validation on android
|
||||
if (isAndroid()) {
|
||||
deferred.resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
validateFeature(getPremiumUnlockFeatureId(), deferred);
|
||||
}
|
||||
|
||||
function validateLiveTV(deferred) {
|
||||
|
||||
validateFeature(getPremiumUnlockFeatureId(), deferred);
|
||||
}
|
||||
|
||||
function validateServerManagement(deferred) {
|
||||
deferred.resolve();
|
||||
}
|
||||
|
||||
function getRegistrationInfo(feature, enableSupporterUnlock) {
|
||||
function getRegistrationInfo(feature) {
|
||||
|
||||
if (!enableSupporterUnlock) {
|
||||
var deferred = $.Deferred();
|
||||
deferred.resolveWith(null, [{}]);
|
||||
return deferred.promise();
|
||||
}
|
||||
return ConnectionManager.getRegistrationInfo(feature, ApiClient);
|
||||
}
|
||||
|
||||
var validatedFeatures = [];
|
||||
|
||||
function validateFeature(id, deferred) {
|
||||
function validateFeature(feature, deferred) {
|
||||
|
||||
if (validatedFeatures.indexOf(id) != -1) {
|
||||
var id = IapManager.getStoreFeatureId(feature);
|
||||
|
||||
if (validatedFeatures.indexOf(feature) != -1) {
|
||||
deferred.resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
var info = IapManager.getProductInfo(id) || {};
|
||||
var info = IapManager.getProductInfo(feature) || {};
|
||||
|
||||
if (info.owned) {
|
||||
notifyServer(id);
|
||||
validatedFeatures.push(id);
|
||||
validatedFeatures.push(feature);
|
||||
deferred.resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
var productInfo = {
|
||||
enableSupporterUnlock: true,
|
||||
enableAppUnlock: IapManager.isPurchaseAvailable(id),
|
||||
enableAppUnlock: IapManager.isPurchaseAvailable(feature),
|
||||
id: id,
|
||||
price: info.price
|
||||
price: info.price,
|
||||
feature: feature
|
||||
};
|
||||
|
||||
var prefix = isAndroid() ? 'android' : 'ios';
|
||||
var prefix = $.browser.android ? 'android' : 'ios';
|
||||
|
||||
// Get supporter status
|
||||
getRegistrationInfo(prefix + 'appunlock', productInfo.enableSupporterUnlock).done(function (registrationInfo) {
|
||||
getRegistrationInfo(prefix + 'appunlock').done(function (registrationInfo) {
|
||||
|
||||
if (registrationInfo.IsRegistered) {
|
||||
validatedFeatures.push(id);
|
||||
validatedFeatures.push(feature);
|
||||
deferred.resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
showInAppPurchaseInfo(productInfo, registrationInfo, deferred);
|
||||
IapManager.getSubscriptionOptions().done(function (subscriptionOptions) {
|
||||
|
||||
showInAppPurchaseInfo(productInfo, subscriptionOptions, registrationInfo, deferred);
|
||||
});
|
||||
|
||||
}).fail(function () {
|
||||
deferred.reject();
|
||||
|
@ -114,42 +84,32 @@
|
|||
});
|
||||
}
|
||||
|
||||
function getInAppPurchaseElement(info) {
|
||||
function getInAppPurchaseElement(info, subscriptionOptions) {
|
||||
|
||||
cancelInAppPurchase();
|
||||
var dlg = PaperDialogHelper.createDialog();
|
||||
|
||||
var html = '';
|
||||
html += '<div class="inAppPurchaseOverlay" style="background-image:url(css/images/splash.jpg);top:0;left:0;right:0;bottom:0;position:fixed;background-position:center center;background-size:100% 100%;background-repeat:no-repeat;z-index:999999;">';
|
||||
html += '<div class="inAppPurchaseOverlayInner" style="background:rgba(10,10,10,.8);width:100%;height:100%;color:#eee;">';
|
||||
html += '<h2 class="dialogHeader">';
|
||||
html += '<paper-fab icon="arrow-back" class="mini btnCloseDialog"></paper-fab>';
|
||||
html += '<div style="display:inline-block;margin-left:.6em;vertical-align:middle;">' + Globalize.translate('HeaderUnlockApp') + '</div>';
|
||||
html += '</h2>';
|
||||
|
||||
html += '<div class="editorContent">';
|
||||
|
||||
html += '<div class="inAppPurchaseForm" style="margin: 0 auto;padding: 30px 1em 0;">';
|
||||
|
||||
html += '<h1 style="color:#fff;">' + Globalize.translate('HeaderUnlockApp') + '</h1>';
|
||||
|
||||
html += '<form style="max-width: 800px;margin:auto;">';
|
||||
html += '<p style="margin:2em 0;">';
|
||||
|
||||
var showSupporterInfo = info.enableSupporterUnlock && !$.browser.safari;
|
||||
|
||||
if (showSupporterInfo && info.enableAppUnlock) {
|
||||
if (info.enableAppUnlock) {
|
||||
html += Globalize.translate('MessageUnlockAppWithPurchaseOrSupporter');
|
||||
}
|
||||
else if (showSupporterInfo) {
|
||||
else {
|
||||
html += Globalize.translate('MessageUnlockAppWithSupporter');
|
||||
} else if (info.enableAppUnlock) {
|
||||
html += Globalize.translate('MessageUnlockAppWithPurchase');
|
||||
} else {
|
||||
html += '<span style="color:red;">';
|
||||
html += Globalize.translate('MessagePaymentServicesUnavailable');
|
||||
html += '</span>';
|
||||
}
|
||||
html += '</p>';
|
||||
|
||||
if (showSupporterInfo) {
|
||||
html += '<p style="margin:2em 0;">';
|
||||
html += Globalize.translate('MessageToValidateSupporter');
|
||||
html += '</p>';
|
||||
}
|
||||
html += '<p style="margin:2em 0;">';
|
||||
html += Globalize.translate('MessageToValidateSupporter');
|
||||
html += '</p>';
|
||||
|
||||
if (info.enableAppUnlock) {
|
||||
|
||||
|
@ -158,76 +118,118 @@
|
|||
unlockText = Globalize.translate('ButtonUnlockPrice', info.price);
|
||||
}
|
||||
html += '<p>';
|
||||
html += '<paper-button raised class="secondary block btnAppUnlock"><iron-icon icon="check"></iron-icon><span>' + unlockText + '</span></paper-button>';
|
||||
html += '<paper-button raised class="secondary block btnPurchase" data-feature="' + info.feature + '"><iron-icon icon="check"></iron-icon><span>' + unlockText + '</span></paper-button>';
|
||||
html += '</p>';
|
||||
|
||||
if (IapManager.restorePurchase) {
|
||||
html += '<p>';
|
||||
html += '<paper-button raised class="secondary block btnRestorePurchase" style="background-color: #673AB7;"><iron-icon icon="check"></iron-icon><span>' + Globalize.translate('ButtonRestorePreviousPurchase') + '</span></paper-button>';
|
||||
html += '</p>';
|
||||
}
|
||||
}
|
||||
|
||||
html += '<p>';
|
||||
html += '<paper-button raised class="cancelDark block btnCancel"><iron-icon icon="close"></iron-icon><span>' + Globalize.translate('ButtonCancel') + '</span></paper-button>';
|
||||
html += '</p>';
|
||||
for (var i = 0, length = subscriptionOptions.length; i < length; i++) {
|
||||
|
||||
html += '<p>';
|
||||
html += '<paper-button raised class="submit block btnPurchase" data-email="true" data-feature="' + subscriptionOptions[i].feature + '"><iron-icon icon="check"></iron-icon><span>';
|
||||
html += subscriptionOptions[i].buttonText;
|
||||
html += '</span></paper-button>';
|
||||
html += '</p>';
|
||||
}
|
||||
|
||||
if (IapManager.restorePurchase) {
|
||||
html += '<p>';
|
||||
html += '<paper-button raised class="secondary block btnRestorePurchase" style="background-color: #673AB7;"><iron-icon icon="check"></iron-icon><span>' + Globalize.translate('ButtonRestorePreviousPurchase') + '</span></paper-button>';
|
||||
html += '</p>';
|
||||
}
|
||||
|
||||
html += '</form>';
|
||||
html += '</div>';
|
||||
|
||||
html += '</div>';
|
||||
html += '</div>';
|
||||
dlg.innerHTML = html;
|
||||
document.body.appendChild(dlg);
|
||||
|
||||
$(document.body).append(html);
|
||||
// init dlg content here
|
||||
|
||||
return $('.inAppPurchaseOverlay');
|
||||
PaperDialogHelper.openWithHash(dlg, 'iap');
|
||||
|
||||
$('.btnCloseDialog', dlg).on('click', function () {
|
||||
|
||||
PaperDialogHelper.close(dlg);
|
||||
});
|
||||
|
||||
dlg.classList.add('inAppPurchaseOverlay');
|
||||
|
||||
return dlg;
|
||||
}
|
||||
|
||||
function cancelInAppPurchase() {
|
||||
|
||||
$('.inAppPurchaseOverlay').remove();
|
||||
var elem = document.querySelector('.inAppPurchaseOverlay');
|
||||
if (elem) {
|
||||
PaperDialogHelper.close(elem);
|
||||
}
|
||||
}
|
||||
|
||||
var currentDisplayingProductInfo = null;
|
||||
var currentDisplayingProductInfos = [];
|
||||
var currentDisplayingDeferred = null;
|
||||
var isCancelled = true;
|
||||
|
||||
function clearCurrentDisplayingInfo() {
|
||||
currentDisplayingProductInfo = null;
|
||||
currentDisplayingProductInfos = [];
|
||||
currentDisplayingDeferred = null;
|
||||
}
|
||||
|
||||
function showInAppPurchaseInfo(info, serverRegistrationInfo, deferred) {
|
||||
function showInAppPurchaseInfo(info, subscriptionOptions, serverRegistrationInfo, deferred) {
|
||||
|
||||
var elem = getInAppPurchaseElement(info);
|
||||
require(['components/paperdialoghelper'], function () {
|
||||
|
||||
currentDisplayingProductInfo = info;
|
||||
currentDisplayingDeferred = deferred;
|
||||
|
||||
$('.btnAppUnlock', elem).on('click', function () {
|
||||
|
||||
IapManager.beginPurchase(info.id);
|
||||
});
|
||||
|
||||
$('.btnRestorePurchase', elem).on('click', function () {
|
||||
|
||||
IapManager.restorePurchase(info.id);
|
||||
});
|
||||
|
||||
$('.btnCancel', elem).on('click', function () {
|
||||
|
||||
clearCurrentDisplayingInfo();
|
||||
cancelInAppPurchase();
|
||||
isCancelled = true;
|
||||
|
||||
deferred.reject();
|
||||
});
|
||||
$('.btnSignInSupporter', elem).on('click', function () {
|
||||
var elem = getInAppPurchaseElement(info, subscriptionOptions);
|
||||
|
||||
clearCurrentDisplayingInfo();
|
||||
// clone
|
||||
currentDisplayingProductInfos = subscriptionOptions.slice(0);
|
||||
currentDisplayingProductInfos.push(info);
|
||||
|
||||
Dashboard.alert({
|
||||
message: Globalize.translate('MessagePleaseSignInLocalNetwork'),
|
||||
callback: function () {
|
||||
currentDisplayingDeferred = deferred;
|
||||
|
||||
$('.btnPurchase', elem).on('click', function () {
|
||||
|
||||
isCancelled = false;
|
||||
|
||||
if (this.getAttribute('data-email') == 'true') {
|
||||
promptForEmail(this.getAttribute('data-feature'));
|
||||
} else {
|
||||
IapManager.beginPurchase(this.getAttribute('data-feature'));
|
||||
}
|
||||
});
|
||||
|
||||
$('.btnRestorePurchase', elem).on('click', function () {
|
||||
|
||||
isCancelled = false;
|
||||
IapManager.restorePurchase(info.feature);
|
||||
});
|
||||
|
||||
$(elem).on('iron-overlay-closed', function () {
|
||||
|
||||
if (isCancelled) {
|
||||
clearCurrentDisplayingInfo();
|
||||
cancelInAppPurchase();
|
||||
Dashboard.logout();
|
||||
|
||||
deferred.reject();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function promptForEmail(feature) {
|
||||
|
||||
require(['prompt'], function (prompt) {
|
||||
|
||||
prompt({
|
||||
text: Globalize.translate('TextPleaseEnterYourEmailAddressForSubscription'),
|
||||
title: Globalize.translate('HeaderEmailAddress'),
|
||||
callback: function(email) {
|
||||
|
||||
if (email) {
|
||||
IapManager.beginPurchase(this.getAttribute('data-feature'), email);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -235,12 +237,15 @@
|
|||
|
||||
function onProductUpdated(e, product) {
|
||||
|
||||
var currentInfo = currentDisplayingProductInfo;
|
||||
var deferred = currentDisplayingDeferred;
|
||||
|
||||
if (currentInfo && deferred) {
|
||||
if (product.owned && product.id == currentInfo.id) {
|
||||
if (deferred && product.owned) {
|
||||
|
||||
if (currentDisplayingProductInfos.filter(function (p) {
|
||||
|
||||
return product.id == p.id;
|
||||
|
||||
}).length) {
|
||||
clearCurrentDisplayingInfo();
|
||||
cancelInAppPurchase();
|
||||
deferred.resolve();
|
||||
|
@ -305,11 +310,9 @@
|
|||
var deferred = DeferredBuilder.Deferred();
|
||||
|
||||
if (name == 'playback') {
|
||||
validatePlayback(deferred);
|
||||
validateFeature(name, deferred);
|
||||
} else if (name == 'livetv') {
|
||||
validateLiveTV(deferred);
|
||||
} else if (name == 'manageserver') {
|
||||
validateServerManagement(deferred);
|
||||
validateFeature(name, deferred);
|
||||
} else if (name == 'sync') {
|
||||
validateSync(deferred);
|
||||
} else {
|
||||
|
@ -324,7 +327,7 @@
|
|||
Events.on(IapManager, 'productupdated', onProductUpdated);
|
||||
}
|
||||
|
||||
if (isAndroid()) {
|
||||
if ($.browser.android) {
|
||||
requirejs(['cordova/android/iap'], onIapManagerLoaded);
|
||||
} else {
|
||||
requirejs(['cordova/iap'], onIapManagerLoaded);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue