mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
update cordova scripts
This commit is contained in:
parent
48a576778f
commit
6235ee51eb
3 changed files with 183 additions and 123 deletions
50
dashboard-ui/thirdparty/cordova/android/iap.js
vendored
Normal file
50
dashboard-ui/thirdparty/cordova/android/iap.js
vendored
Normal file
|
@ -0,0 +1,50 @@
|
|||
(function () {
|
||||
|
||||
var unlockId = "premiumunlock";
|
||||
var updatedProducts = [];
|
||||
|
||||
function updateProductInfo(id, owned) {
|
||||
|
||||
updatedProducts = updatedProducts.filter(function (r) {
|
||||
return r.id != id;
|
||||
});
|
||||
|
||||
updatedProducts.push({
|
||||
id: id,
|
||||
owned: owned
|
||||
});
|
||||
}
|
||||
|
||||
function hasPurchased(id) {
|
||||
var product = getProduct(id);
|
||||
|
||||
return product != null && product.owned;
|
||||
}
|
||||
|
||||
function getProduct(id) {
|
||||
var products = updatedProducts.filter(function (r) {
|
||||
return r.id == id;
|
||||
});
|
||||
|
||||
return products.length ? products[0] : null;
|
||||
}
|
||||
|
||||
function isPurchaseAvailable(id) {
|
||||
|
||||
return NativeIapManager.isStoreAvailable();
|
||||
}
|
||||
|
||||
function beginPurchase(id) {
|
||||
return NativeIapManager.beginPurchase(id);
|
||||
}
|
||||
|
||||
window.IapManager = {
|
||||
isPurchaseAvailable: isPurchaseAvailable,
|
||||
hasPurchased: hasPurchased,
|
||||
updateProduct: updateProductInfo,
|
||||
beginPurchase: beginPurchase
|
||||
};
|
||||
|
||||
NativeIapManager.isPurchased(unlockId, "window.IapManager.updateProduct");
|
||||
|
||||
})();
|
123
dashboard-ui/thirdparty/cordova/iap.js
vendored
Normal file
123
dashboard-ui/thirdparty/cordova/iap.js
vendored
Normal file
|
@ -0,0 +1,123 @@
|
|||
(function () {
|
||||
|
||||
var unlockAlias = "premium features";
|
||||
var updatedProducts = [];
|
||||
|
||||
function updateProductInfo(p) {
|
||||
|
||||
updatedProducts = updatedProducts.filter(function (r) {
|
||||
return r.id != p.id;
|
||||
});
|
||||
|
||||
updatedProducts.push(p);
|
||||
}
|
||||
|
||||
function normalizeId(id) {
|
||||
|
||||
// This is what i named it in itunes
|
||||
id = id.replace('premiumunlock', 'appunlock');
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
function getProduct(id) {
|
||||
|
||||
id = normalizeId(id);
|
||||
|
||||
var products = updatedProducts.filter(function (r) {
|
||||
return r.id == id;
|
||||
});
|
||||
|
||||
return products.length ? products[0] : null;
|
||||
}
|
||||
|
||||
function hasPurchased(id) {
|
||||
var product = getProduct(id);
|
||||
|
||||
return product != null && product.owned;
|
||||
}
|
||||
|
||||
function isPurchaseAvailable(id) {
|
||||
var product = getProduct(id);
|
||||
|
||||
return product != null && product.canPurchase;
|
||||
}
|
||||
|
||||
function beginPurchase(id) {
|
||||
|
||||
}
|
||||
|
||||
function validateProduct(product, callback) {
|
||||
|
||||
// product attributes:
|
||||
// https://github.com/j3k0/cordova-plugin-purchase/blob/master/doc/api.md#validation-error-codes
|
||||
|
||||
callback(true, {
|
||||
|
||||
});
|
||||
|
||||
//callback(true, { ... transaction details ... }); // success!
|
||||
|
||||
//// OR
|
||||
//callback(false, {
|
||||
// error: {
|
||||
// code: store.PURCHASE_EXPIRED,
|
||||
// message: "XYZ"
|
||||
// }
|
||||
//});
|
||||
|
||||
//// OR
|
||||
//callback(false, "Impossible to proceed with validation");
|
||||
}
|
||||
|
||||
function initializeStore() {
|
||||
|
||||
// Let's set a pretty high verbosity level, so that we see a lot of stuff
|
||||
// in the console (reassuring us that something is happening).
|
||||
store.verbosity = store.INFO;
|
||||
|
||||
store.validator = validateProduct;
|
||||
|
||||
// iOS
|
||||
store.register({
|
||||
id: "appunlock",
|
||||
alias: unlockAlias,
|
||||
type: store.NON_CONSUMABLE
|
||||
});
|
||||
|
||||
// When purchase of the full version is approved,
|
||||
// show some logs and finish the transaction.
|
||||
store.when(unlockAlias).approved(function (order) {
|
||||
log('You just unlocked the FULL VERSION!');
|
||||
order.finish();
|
||||
});
|
||||
|
||||
// The play button can only be accessed when the user
|
||||
// owns the full version.
|
||||
store.when(unlockAlias).updated(function (product) {
|
||||
|
||||
updateProductInfo(product);
|
||||
});
|
||||
|
||||
// When every goes as expected, it's time to celebrate!
|
||||
// The "ready" event should be welcomed with music and fireworks,
|
||||
// go ask your boss about it! (just in case)
|
||||
store.ready(function () {
|
||||
|
||||
console.log("Store ready");
|
||||
});
|
||||
|
||||
// After we've done our setup, we tell the store to do
|
||||
// it's first refresh. Nothing will happen if we do not call store.refresh()
|
||||
store.refresh();
|
||||
}
|
||||
|
||||
window.IapManager = {
|
||||
isPurchaseAvailable: isPurchaseAvailable,
|
||||
hasPurchased: hasPurchased,
|
||||
beginPurchase: beginPurchase
|
||||
};
|
||||
|
||||
initializeStore();
|
||||
|
||||
})();
|
|
@ -1,38 +1,5 @@
|
|||
(function () {
|
||||
|
||||
var updatedProducts = [];
|
||||
|
||||
var unlockAlias = "premium features";
|
||||
|
||||
function updateProductInfo(p) {
|
||||
|
||||
updatedProducts = updatedProducts.filter(function (r) {
|
||||
return r.alias != p.alias;
|
||||
});
|
||||
|
||||
updatedProducts.push(p);
|
||||
}
|
||||
|
||||
function getProduct(alias) {
|
||||
var products = updatedProducts.filter(function (r) {
|
||||
return r.alias == alias;
|
||||
});
|
||||
|
||||
return products.length ? products[0] : null;
|
||||
}
|
||||
|
||||
function hasPurchased(alias) {
|
||||
var product = getProduct(alias);
|
||||
|
||||
return product != null && product.owned;
|
||||
}
|
||||
|
||||
function isPurchaseAvailable(alias) {
|
||||
var product = getProduct(alias);
|
||||
|
||||
return product != null && product.canPurchase;
|
||||
}
|
||||
|
||||
function isAndroid() {
|
||||
|
||||
var platform = (device.platform || '').toLowerCase();
|
||||
|
@ -50,8 +17,7 @@
|
|||
|
||||
validateFeature({
|
||||
|
||||
id: 'appunlock',
|
||||
alias: unlockAlias
|
||||
id: 'premiumunlock'
|
||||
|
||||
}, deferred);
|
||||
}
|
||||
|
@ -66,8 +32,7 @@
|
|||
|
||||
validateFeature({
|
||||
|
||||
id: 'premiumunlock',
|
||||
alias: unlockAlias
|
||||
id: 'premiumunlock'
|
||||
|
||||
}, deferred);
|
||||
}
|
||||
|
@ -82,8 +47,7 @@
|
|||
|
||||
validateFeature({
|
||||
|
||||
id: 'premiumunlock',
|
||||
alias: unlockAlias
|
||||
id: 'premiumunlock'
|
||||
|
||||
}, deferred);
|
||||
}
|
||||
|
@ -100,14 +64,15 @@
|
|||
|
||||
function validateFeature(info, deferred) {
|
||||
|
||||
if (hasPurchased(info.alias)) {
|
||||
if (IapManager.hasPurchased(info.id)) {
|
||||
deferred.resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
var productInfo = {
|
||||
enableSupporterUnlock: isAndroid(),
|
||||
enableAppUnlock: isPurchaseAvailable(info.alias)
|
||||
enableAppUnlock: IapManager.isPurchaseAvailable(info.id),
|
||||
id: info.id
|
||||
};
|
||||
|
||||
var prefix = isAndroid() ? 'android' : 'ios';
|
||||
|
@ -163,13 +128,7 @@
|
|||
}
|
||||
|
||||
if (info.enableAppUnlock) {
|
||||
html += '<p style="margin:2em 0;">';
|
||||
html += Globalize.translate('MessageToValidateSupporter');
|
||||
html += '</p>';
|
||||
}
|
||||
|
||||
if (info.enableAppUnlock) {
|
||||
html += '<button class="btn btnActionAccent btnAppUnlock" data-role="none" type="button"><span>' + Globalize.translate('ButtonUnlockWithPurchase') + '</span><i class="fa fa-check"></i></button>';
|
||||
html += '<button class="btn btnActionAccent btnAppUnlock" data-role="none" type="submit"><span>' + Globalize.translate('ButtonUnlockWithPurchase') + '</span><i class="fa fa-check"></i></button>';
|
||||
}
|
||||
|
||||
if (info.enableSupporterUnlock) {
|
||||
|
@ -199,6 +158,7 @@
|
|||
|
||||
$('.inAppPurchaseForm', elem).on('submit', function () {
|
||||
|
||||
IapManager.beginPurchase(info.id);
|
||||
return false;
|
||||
});
|
||||
|
||||
|
@ -222,11 +182,6 @@
|
|||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('.btnAppUnlock', elem).on('click', function () {
|
||||
|
||||
alert('coming soon');
|
||||
});
|
||||
}
|
||||
|
||||
window.RegistrationServices = {
|
||||
|
@ -260,76 +215,8 @@
|
|||
}
|
||||
};
|
||||
|
||||
function validateProduct(product, callback) {
|
||||
var depends = isAndroid() ? 'thirdparty/cordova/android/iap' : 'thirdparty/cordova/iap';
|
||||
|
||||
// product attributes:
|
||||
// https://github.com/j3k0/cordova-plugin-purchase/blob/master/doc/api.md#validation-error-codes
|
||||
|
||||
callback(true, {
|
||||
|
||||
});
|
||||
|
||||
//callback(true, { ... transaction details ... }); // success!
|
||||
|
||||
//// OR
|
||||
//callback(false, {
|
||||
// error: {
|
||||
// code: store.PURCHASE_EXPIRED,
|
||||
// message: "XYZ"
|
||||
// }
|
||||
//});
|
||||
|
||||
//// OR
|
||||
//callback(false, "Impossible to proceed with validation");
|
||||
}
|
||||
|
||||
function initializeStore() {
|
||||
|
||||
if (isAndroid()) {
|
||||
return;
|
||||
}
|
||||
// Let's set a pretty high verbosity level, so that we see a lot of stuff
|
||||
// in the console (reassuring us that something is happening).
|
||||
store.verbosity = store.INFO;
|
||||
|
||||
store.validator = validateProduct;
|
||||
|
||||
// iOS
|
||||
store.register({
|
||||
id: "appunlock",
|
||||
alias: unlockAlias,
|
||||
type: store.NON_CONSUMABLE
|
||||
});
|
||||
|
||||
// When purchase of the full version is approved,
|
||||
// show some logs and finish the transaction.
|
||||
store.when(unlockAlias).approved(function (order) {
|
||||
log('You just unlocked the FULL VERSION!');
|
||||
order.finish();
|
||||
});
|
||||
|
||||
// The play button can only be accessed when the user
|
||||
// owns the full version.
|
||||
store.when(unlockAlias).updated(function (product) {
|
||||
|
||||
updateProductInfo(product);
|
||||
});
|
||||
|
||||
// When every goes as expected, it's time to celebrate!
|
||||
// The "ready" event should be welcomed with music and fireworks,
|
||||
// go ask your boss about it! (just in case)
|
||||
store.ready(function () {
|
||||
|
||||
console.log("Store ready");
|
||||
});
|
||||
|
||||
// After we've done our setup, we tell the store to do
|
||||
// it's first refresh. Nothing will happen if we do not call store.refresh()
|
||||
store.refresh();
|
||||
}
|
||||
|
||||
// We must wait for the "deviceready" event to fire
|
||||
// before we can use the store object.
|
||||
initializeStore();
|
||||
requirejs([depends]);
|
||||
|
||||
})();
|
Loading…
Add table
Add a link
Reference in a new issue