From d0a2b32c29f5657aa8ab974ae37e0bd1f6079c92 Mon Sep 17 00:00:00 2001 From: Florian Keller Date: Tue, 7 May 2019 11:30:23 +0200 Subject: [PATCH 01/10] chore: Use Node.js 12 --- .travis.yml | 2 +- package.json | 15 +-------------- src/cpp/wrapper.cc | 4 ++-- 3 files changed, 4 insertions(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5b3791d..c1e2002 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ os: osx language: node_js node_js: - - '10' + - '12' notifications: email: false diff --git a/package.json b/package.json index 172fc1e..bbf5b93 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,5 @@ { "author": "Wire Swiss ", - "contributors": [ - { - "email": "chris@wire.com", - "name": "Chris Owen", - "url": "http://wire.com" - }, - { - "email": "digital.flowers@hotmail.com", - "name": "Fareed Al-Namrouti" - } - ], "dependencies": { "nan": "2.13.2" }, @@ -48,9 +37,7 @@ "address", "addressbook", "contacts", - "wire", - "binding", - "c" + "binding" ], "license": "GPL-3.0", "lint-staged": { diff --git a/src/cpp/wrapper.cc b/src/cpp/wrapper.cc index a5e6a0c..c39caba 100644 --- a/src/cpp/wrapper.cc +++ b/src/cpp/wrapper.cc @@ -114,7 +114,7 @@ NAN_METHOD(GetMe) { NAN_METHOD(GetContact) { - int index = info[0]->Uint32Value(); + int index = info[0]->Uint32Value(Nan::GetCurrentContext()).ToChecked(); AddressBook ab; Isolate* isolate = Isolate::GetCurrent(); @@ -144,4 +144,4 @@ NAN_MODULE_INIT(Init) { GetFunction(New(GetContacts)).ToLocalChecked()); } -NODE_MODULE(addon, Init) \ No newline at end of file +NODE_MODULE(addon, Init) From 6d445688cbfa05319b4efa787a1fb1f1e080cf3d Mon Sep 17 00:00:00 2001 From: Florian Keller Date: Tue, 7 May 2019 11:36:44 +0200 Subject: [PATCH 02/10] add if case --- src/cpp/wrapper.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cpp/wrapper.cc b/src/cpp/wrapper.cc index c39caba..3913688 100644 --- a/src/cpp/wrapper.cc +++ b/src/cpp/wrapper.cc @@ -114,7 +114,11 @@ NAN_METHOD(GetMe) { NAN_METHOD(GetContact) { - int index = info[0]->Uint32Value(Nan::GetCurrentContext()).ToChecked(); + #if V8_MAJOR_VERSION >= 7 + int index = info[0]->Uint32Value(Nan::GetCurrentContext()).ToChecked(); + #else + int index = info[0]->Uint32Value(); + #endif AddressBook ab; Isolate* isolate = Isolate::GetCurrent(); From b2cbbc90a27cef90702c35733d9f5ee0e8a26406 Mon Sep 17 00:00:00 2001 From: Florian Keller Date: Tue, 7 May 2019 13:22:46 +0200 Subject: [PATCH 03/10] add space --- src/cpp/wrapper.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cpp/wrapper.cc b/src/cpp/wrapper.cc index 3913688..50511e2 100644 --- a/src/cpp/wrapper.cc +++ b/src/cpp/wrapper.cc @@ -48,8 +48,8 @@ void fillPersonObject(Isolate* isolate, Local obj, Person *person) class AddressBookWorker : public AsyncProgressWorker { public: - AddressBookWorker(Callback *callback,Callback *progress) - : AsyncProgressWorker(callback), progress(progress) , contacts() {} + AddressBookWorker(Callback *callback, Callback *progress) + : AsyncProgressWorker(callback), progress(progress), contacts() {} ~AddressBookWorker() {} From 730cd98c30fe6c1fde13af4d27e867bea6df22ea Mon Sep 17 00:00:00 2001 From: Florian Keller Date: Tue, 7 May 2019 13:25:27 +0200 Subject: [PATCH 04/10] better if check --- src/cpp/wrapper.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp/wrapper.cc b/src/cpp/wrapper.cc index 50511e2..a5cc8fb 100644 --- a/src/cpp/wrapper.cc +++ b/src/cpp/wrapper.cc @@ -114,7 +114,7 @@ NAN_METHOD(GetMe) { NAN_METHOD(GetContact) { - #if V8_MAJOR_VERSION >= 7 + #if defined(V8_MAJOR_VERSION) && V8_MAJOR_VERSION >= 7 int index = info[0]->Uint32Value(Nan::GetCurrentContext()).ToChecked(); #else int index = info[0]->Uint32Value(); From 3be337306709bf3c269e81033adb9bab30523714 Mon Sep 17 00:00:00 2001 From: Florian Keller Date: Tue, 7 May 2019 13:28:08 +0200 Subject: [PATCH 05/10] formatting --- src/cpp/AddressBook.cc | 73 +++++++++++++++------------------ src/cpp/Person.cc | 91 +++++++++++++++++++----------------------- 2 files changed, 75 insertions(+), 89 deletions(-) diff --git a/src/cpp/AddressBook.cc b/src/cpp/AddressBook.cc index 8b24247..7fcc44c 100644 --- a/src/cpp/AddressBook.cc +++ b/src/cpp/AddressBook.cc @@ -15,7 +15,6 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . - #include "Person.h" #ifdef __APPLE__ @@ -24,57 +23,51 @@ #include "AddressBook.h" -AddressBook::AddressBook() -{ -} +AddressBook::AddressBook() {} -Person* AddressBook::getMe() const -{ +Person *AddressBook::getMe() const { #ifdef __APPLE__ - ABAddressBookRef ab = ABGetSharedAddressBook(); - ABPersonRef me = ABGetMe(ab); - Person *p = new Person(me); + ABAddressBookRef ab = ABGetSharedAddressBook(); + ABPersonRef me = ABGetMe(ab); + Person *p = new Person(me); #else - Person *p = new Person(); + Person *p = new Person(); #endif - return p; + return p; } -unsigned long AddressBook::contactCount() const -{ +unsigned long AddressBook::contactCount() const { #ifdef __APPLE__ - CFIndex count = 0; - ABAddressBookRef ab = ABGetSharedAddressBook(); - CFArrayRef peeps = ABCopyArrayOfAllPeople(ab); - if (peeps) { - count = CFArrayGetCount(peeps); - CFRelease(peeps); - } - return count; + CFIndex count = 0; + ABAddressBookRef ab = ABGetSharedAddressBook(); + CFArrayRef peeps = ABCopyArrayOfAllPeople(ab); + if (peeps) { + count = CFArrayGetCount(peeps); + CFRelease(peeps); + } + return count; #else - return 0; + return 0; #endif } -Person* AddressBook::getContact(unsigned long pos) const -{ +Person *AddressBook::getContact(unsigned long pos) const { #ifdef __APPLE__ - Person *p = NULL; - ABAddressBookRef ab = ABGetSharedAddressBook(); - CFArrayRef peeps = ABCopyArrayOfAllPeople(ab); - if (peeps) { - CFIndex count = CFArrayGetCount(peeps); - if ((CFIndex)pos < count) { - ABPersonRef pe = (ABPersonRef)CFArrayGetValueAtIndex(peeps, pos); - if (pe) { - p = new Person(pe); - } - } - CFRelease(peeps); - } + Person *p = NULL; + ABAddressBookRef ab = ABGetSharedAddressBook(); + CFArrayRef peeps = ABCopyArrayOfAllPeople(ab); + if (peeps) { + CFIndex count = CFArrayGetCount(peeps); + if ((CFIndex)pos < count) { + ABPersonRef pe = (ABPersonRef)CFArrayGetValueAtIndex(peeps, pos); + if (pe) { + p = new Person(pe); + } + } + CFRelease(peeps); + } #else - Person *p = new Person(); + Person *p = new Person(); #endif - return p; + return p; } - diff --git a/src/cpp/Person.cc b/src/cpp/Person.cc index abf8efb..1f58593 100644 --- a/src/cpp/Person.cc +++ b/src/cpp/Person.cc @@ -19,70 +19,63 @@ #include "AddressBook.h" #ifdef __APPLE__ -std::string Person::CFString2String(CFStringRef str) -{ - std::string rv; - CFIndex length = CFStringGetLength(str); - CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8) + 1; - char *buffer = (char *)malloc(maxSize); - if (CFStringGetCString(str, buffer, maxSize, kCFStringEncodingUTF8)) { - rv = buffer; - free(buffer); - } +std::string Person::CFString2String(CFStringRef str) { + std::string rv; + CFIndex length = CFStringGetLength(str); + CFIndex maxSize = + CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8) + 1; + char *buffer = (char *)malloc(maxSize); + if (CFStringGetCString(str, buffer, maxSize, kCFStringEncodingUTF8)) { + rv = buffer; + free(buffer); + } - return rv; + return rv; } -std::string Person::getStringProperty(ABPersonRef person, CFStringRef propertyName) -{ - CFStringRef propertyVal = (CFStringRef)ABRecordCopyValue(person, propertyName); - std::string rv; +std::string Person::getStringProperty(ABPersonRef person, + CFStringRef propertyName) { + CFStringRef propertyVal = + (CFStringRef)ABRecordCopyValue(person, propertyName); + std::string rv; - if (propertyVal && CFGetTypeID(propertyVal) == CFStringGetTypeID()) { - rv = CFString2String(propertyVal); - CFRelease(propertyVal); - } + if (propertyVal && CFGetTypeID(propertyVal) == CFStringGetTypeID()) { + rv = CFString2String(propertyVal); + CFRelease(propertyVal); + } - return rv; + return rv; } -void Person::fillPropertyVector(ABPersonRef person, CFStringRef propertyName, stringvector& vec) -{ - ABMultiValueRef propertyArray = (ABMultiValueRef)ABRecordCopyValue(person, propertyName); +void Person::fillPropertyVector(ABPersonRef person, CFStringRef propertyName, + stringvector &vec) { + ABMultiValueRef propertyArray = + (ABMultiValueRef)ABRecordCopyValue(person, propertyName); - if (propertyArray) { - CFIndex count = ABMultiValueCount(propertyArray); - for(CFIndex p = 0; p < count; p++) { - CFStringRef propertyVal = (CFStringRef)ABMultiValueCopyValueAtIndex(propertyArray, p); - vec.push_back(CFString2String(propertyVal)); - CFRelease(propertyVal); - } - } + if (propertyArray) { + CFIndex count = ABMultiValueCount(propertyArray); + for (CFIndex p = 0; p < count; p++) { + CFStringRef propertyVal = + (CFStringRef)ABMultiValueCopyValueAtIndex(propertyArray, p); + vec.push_back(CFString2String(propertyVal)); + CFRelease(propertyVal); + } + } } #endif -Person::Person() -{ -} +Person::Person() {} #ifdef __APPLE__ -Person::Person(ABPersonRef p) -{ - m_firstName = getStringProperty(p, kABFirstNameProperty); - m_lastName = getStringProperty(p, kABLastNameProperty); +Person::Person(ABPersonRef p) { + m_firstName = getStringProperty(p, kABFirstNameProperty); + m_lastName = getStringProperty(p, kABLastNameProperty); - fillPropertyVector(p, kABEmailProperty, m_emails); - fillPropertyVector(p, kABPhoneProperty, m_numbers); + fillPropertyVector(p, kABEmailProperty, m_emails); + fillPropertyVector(p, kABPhoneProperty, m_numbers); } #endif -const stringvector& Person::numbers() const -{ - return m_numbers; -} - -const stringvector& Person::emails() const -{ - return m_emails; -} +const stringvector &Person::numbers() const { return m_numbers; } +const stringvector &Person::emails() const { return m_emails; } From b5cdc9e574e70f613053f771c4ba4c4334705333 Mon Sep 17 00:00:00 2001 From: Florian Keller Date: Tue, 7 May 2019 13:46:33 +0200 Subject: [PATCH 06/10] [ci skip] formatting --- src/cpp/Person.cc | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/cpp/Person.cc b/src/cpp/Person.cc index 1f58593..a718f0b 100644 --- a/src/cpp/Person.cc +++ b/src/cpp/Person.cc @@ -22,8 +22,7 @@ std::string Person::CFString2String(CFStringRef str) { std::string rv; CFIndex length = CFStringGetLength(str); - CFIndex maxSize = - CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8) + 1; + CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8) + 1; char *buffer = (char *)malloc(maxSize); if (CFStringGetCString(str, buffer, maxSize, kCFStringEncodingUTF8)) { rv = buffer; @@ -33,10 +32,8 @@ std::string Person::CFString2String(CFStringRef str) { return rv; } -std::string Person::getStringProperty(ABPersonRef person, - CFStringRef propertyName) { - CFStringRef propertyVal = - (CFStringRef)ABRecordCopyValue(person, propertyName); +std::string Person::getStringProperty(ABPersonRef person, CFStringRef propertyName) { + CFStringRef propertyVal = (CFStringRef)ABRecordCopyValue(person, propertyName); std::string rv; if (propertyVal && CFGetTypeID(propertyVal) == CFStringGetTypeID()) { @@ -47,10 +44,8 @@ std::string Person::getStringProperty(ABPersonRef person, return rv; } -void Person::fillPropertyVector(ABPersonRef person, CFStringRef propertyName, - stringvector &vec) { - ABMultiValueRef propertyArray = - (ABMultiValueRef)ABRecordCopyValue(person, propertyName); +void Person::fillPropertyVector(ABPersonRef person, CFStringRef propertyName, stringvector &vec) { + ABMultiValueRef propertyArray = (ABMultiValueRef)ABRecordCopyValue(person, propertyName); if (propertyArray) { CFIndex count = ABMultiValueCount(propertyArray); From 077be6a104e4ffb1b132f91d758aafef1ddc58df Mon Sep 17 00:00:00 2001 From: Florian Keller Date: Tue, 7 May 2019 13:47:37 +0200 Subject: [PATCH 07/10] [ci skip] formatting --- src/cpp/Person.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cpp/Person.cc b/src/cpp/Person.cc index a718f0b..eeb5341 100644 --- a/src/cpp/Person.cc +++ b/src/cpp/Person.cc @@ -71,6 +71,10 @@ Person::Person(ABPersonRef p) { } #endif -const stringvector &Person::numbers() const { return m_numbers; } +const stringvector &Person::numbers() const { + return m_numbers; +} -const stringvector &Person::emails() const { return m_emails; } +const stringvector &Person::emails() const { + return m_emails; +} From 5faebe87b854b506977f187cc23820db0aa1841c Mon Sep 17 00:00:00 2001 From: Florian Keller Date: Tue, 7 May 2019 13:48:17 +0200 Subject: [PATCH 08/10] build and run when testing --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bbf5b93..6a5ed21 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,7 @@ "lint:ts": "tslint --project tsconfig.json", "postinstall": "node-gyp rebuild", "prettier": "prettier \"**/*.{json,md,yml}\"", - "test": "yarn lint" + "test": "yarn lint && yarn dist && node dist/example.js" }, "version": "3.0.2" } From 10dc71575b1f04f0a8394aa4184cce0709a6cc3d Mon Sep 17 00:00:00 2001 From: Florian Keller Date: Tue, 7 May 2019 13:53:21 +0200 Subject: [PATCH 09/10] don't rebuild twice --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 6a5ed21..ea719a4 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,6 @@ "lint": "yarn lint:other && yarn lint:ts", "lint:other": "yarn prettier --list-different", "lint:ts": "tslint --project tsconfig.json", - "postinstall": "node-gyp rebuild", "prettier": "prettier \"**/*.{json,md,yml}\"", "test": "yarn lint && yarn dist && node dist/example.js" }, From 644d81e9e77ddd70eddc6e4901cb47f78fc3b059 Mon Sep 17 00:00:00 2001 From: Florian Keller Date: Tue, 7 May 2019 13:58:30 +0200 Subject: [PATCH 10/10] don't run example --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ea719a4..0fd8f10 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "lint:other": "yarn prettier --list-different", "lint:ts": "tslint --project tsconfig.json", "prettier": "prettier \"**/*.{json,md,yml}\"", - "test": "yarn lint && yarn dist && node dist/example.js" + "test": "yarn lint && yarn dist" }, "version": "3.0.2" }