refactor: ginify InAppPurchase (#24674)
This commit is contained in:
parent
5cfe956fe1
commit
071c5930b9
3 changed files with 24 additions and 22 deletions
|
@ -3,11 +3,7 @@ import { EventEmitter } from 'events';
|
||||||
let _inAppPurchase;
|
let _inAppPurchase;
|
||||||
|
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
const { inAppPurchase, InAppPurchase } = process._linkedBinding('electron_browser_in_app_purchase');
|
const { inAppPurchase } = process._linkedBinding('electron_browser_in_app_purchase');
|
||||||
|
|
||||||
// inAppPurchase is an EventEmitter.
|
|
||||||
Object.setPrototypeOf(InAppPurchase.prototype, EventEmitter.prototype);
|
|
||||||
EventEmitter.call(inAppPurchase);
|
|
||||||
|
|
||||||
_inAppPurchase = inAppPurchase;
|
_inAppPurchase = inAppPurchase;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include "shell/common/gin_helper/dictionary.h"
|
#include "shell/common/gin_helper/dictionary.h"
|
||||||
#include "shell/common/gin_helper/object_template_builder.h"
|
#include "shell/common/gin_helper/object_template_builder.h"
|
||||||
|
#include "shell/common/gin_helper/promise.h"
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
|
|
||||||
namespace gin {
|
namespace gin {
|
||||||
|
@ -73,17 +74,18 @@ namespace electron {
|
||||||
|
|
||||||
namespace api {
|
namespace api {
|
||||||
|
|
||||||
|
gin::WrapperInfo InAppPurchase::kWrapperInfo = {gin::kEmbedderNativeGin};
|
||||||
|
|
||||||
#if defined(OS_MACOSX)
|
#if defined(OS_MACOSX)
|
||||||
// static
|
// static
|
||||||
gin::Handle<InAppPurchase> InAppPurchase::Create(v8::Isolate* isolate) {
|
gin::Handle<InAppPurchase> InAppPurchase::Create(v8::Isolate* isolate) {
|
||||||
return gin::CreateHandle(isolate, new InAppPurchase(isolate));
|
return gin::CreateHandle(isolate, new InAppPurchase());
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
gin::ObjectTemplateBuilder InAppPurchase::GetObjectTemplateBuilder(
|
||||||
void InAppPurchase::BuildPrototype(v8::Isolate* isolate,
|
v8::Isolate* isolate) {
|
||||||
v8::Local<v8::FunctionTemplate> prototype) {
|
return gin_helper::EventEmitterMixin<InAppPurchase>::GetObjectTemplateBuilder(
|
||||||
prototype->SetClassName(gin::StringToV8(isolate, "InAppPurchase"));
|
isolate)
|
||||||
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
|
||||||
.SetMethod("canMakePayments", &in_app_purchase::CanMakePayments)
|
.SetMethod("canMakePayments", &in_app_purchase::CanMakePayments)
|
||||||
.SetMethod("restoreCompletedTransactions",
|
.SetMethod("restoreCompletedTransactions",
|
||||||
&in_app_purchase::RestoreCompletedTransactions)
|
&in_app_purchase::RestoreCompletedTransactions)
|
||||||
|
@ -96,10 +98,12 @@ void InAppPurchase::BuildPrototype(v8::Isolate* isolate,
|
||||||
.SetMethod("getProducts", &InAppPurchase::GetProducts);
|
.SetMethod("getProducts", &InAppPurchase::GetProducts);
|
||||||
}
|
}
|
||||||
|
|
||||||
InAppPurchase::InAppPurchase(v8::Isolate* isolate) {
|
const char* InAppPurchase::GetTypeName() {
|
||||||
Init(isolate);
|
return "InAppPurchase";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InAppPurchase::InAppPurchase() {}
|
||||||
|
|
||||||
InAppPurchase::~InAppPurchase() {}
|
InAppPurchase::~InAppPurchase() {}
|
||||||
|
|
||||||
v8::Local<v8::Promise> InAppPurchase::PurchaseProduct(
|
v8::Local<v8::Promise> InAppPurchase::PurchaseProduct(
|
||||||
|
@ -158,9 +162,6 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||||
v8::Isolate* isolate = context->GetIsolate();
|
v8::Isolate* isolate = context->GetIsolate();
|
||||||
gin_helper::Dictionary dict(isolate, exports);
|
gin_helper::Dictionary dict(isolate, exports);
|
||||||
dict.Set("inAppPurchase", InAppPurchase::Create(isolate));
|
dict.Set("inAppPurchase", InAppPurchase::Create(isolate));
|
||||||
dict.Set("InAppPurchase", InAppPurchase::GetConstructor(isolate)
|
|
||||||
->GetFunction(context)
|
|
||||||
.ToLocalChecked());
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,26 +9,31 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "gin/handle.h"
|
#include "gin/handle.h"
|
||||||
|
#include "gin/wrappable.h"
|
||||||
|
#include "shell/browser/event_emitter_mixin.h"
|
||||||
#include "shell/browser/mac/in_app_purchase.h"
|
#include "shell/browser/mac/in_app_purchase.h"
|
||||||
#include "shell/browser/mac/in_app_purchase_observer.h"
|
#include "shell/browser/mac/in_app_purchase_observer.h"
|
||||||
#include "shell/browser/mac/in_app_purchase_product.h"
|
#include "shell/browser/mac/in_app_purchase_product.h"
|
||||||
#include "shell/common/gin_helper/event_emitter.h"
|
#include "v8/include/v8.h"
|
||||||
#include "shell/common/gin_helper/promise.h"
|
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
|
|
||||||
namespace api {
|
namespace api {
|
||||||
|
|
||||||
class InAppPurchase : public gin_helper::EventEmitter<InAppPurchase>,
|
class InAppPurchase : public gin::Wrappable<InAppPurchase>,
|
||||||
|
public gin_helper::EventEmitterMixin<InAppPurchase>,
|
||||||
public in_app_purchase::TransactionObserver {
|
public in_app_purchase::TransactionObserver {
|
||||||
public:
|
public:
|
||||||
static gin::Handle<InAppPurchase> Create(v8::Isolate* isolate);
|
static gin::Handle<InAppPurchase> Create(v8::Isolate* isolate);
|
||||||
|
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
// gin::Wrappable
|
||||||
v8::Local<v8::FunctionTemplate> prototype);
|
static gin::WrapperInfo kWrapperInfo;
|
||||||
|
gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
||||||
|
v8::Isolate* isolate) override;
|
||||||
|
const char* GetTypeName() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit InAppPurchase(v8::Isolate* isolate);
|
InAppPurchase();
|
||||||
~InAppPurchase() override;
|
~InAppPurchase() override;
|
||||||
|
|
||||||
v8::Local<v8::Promise> PurchaseProduct(const std::string& product_id,
|
v8::Local<v8::Promise> PurchaseProduct(const std::string& product_id,
|
||||||
|
|
Loading…
Reference in a new issue