Skip to content
This repository has been archived by the owner on Oct 27, 2022. It is now read-only.

chore: Use Node.js 12 #12

Merged
merged 10 commits into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ os: osx
language: node_js

node_js:
- '10'
- '12'

notifications:
email: false
Expand Down
18 changes: 2 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
{
"author": "Wire Swiss <wireapp@wire.com>",
"contributors": [
{
"email": "chris@wire.com",
"name": "Chris Owen",
"url": "http://wire.com"
},
{
"email": "digital.flowers@hotmail.com",
"name": "Fareed Al-Namrouti"
}
],
Copy link
Contributor Author

@ffflorian ffflorian May 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This list was incomplete and can now be found at https://github.com/wireapp/node-addressbook/graphs/contributors

"dependencies": {
"nan": "2.13.2"
},
Expand Down Expand Up @@ -48,9 +37,7 @@
"address",
"addressbook",
"contacts",
"wire",
"binding",
"c"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless IMO

"binding"
],
"license": "GPL-3.0",
"lint-staged": {
Expand Down Expand Up @@ -82,9 +69,8 @@
"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"
"test": "yarn lint && yarn dist"
},
"version": "3.0.2"
}
73 changes: 33 additions & 40 deletions src/cpp/AddressBook.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.


#include "Person.h"

#ifdef __APPLE__
Expand All @@ -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;
}

86 changes: 39 additions & 47 deletions src/cpp/Person.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,70 +19,62 @@
#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::numbers() const {
return m_numbers;
}

const stringvector& Person::emails() const
{
return m_emails;
const stringvector &Person::emails() const {
return m_emails;
}

12 changes: 8 additions & 4 deletions src/cpp/wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ void fillPersonObject(Isolate* isolate, Local<Object> 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() {}

Expand Down Expand Up @@ -114,7 +114,11 @@ NAN_METHOD(GetMe) {


NAN_METHOD(GetContact) {
int index = info[0]->Uint32Value();
#if defined(V8_MAJOR_VERSION) && V8_MAJOR_VERSION >= 7
int index = info[0]->Uint32Value(Nan::GetCurrentContext()).ToChecked();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#else
int index = info[0]->Uint32Value();
#endif

AddressBook ab;
Isolate* isolate = Isolate::GetCurrent();
Expand Down Expand Up @@ -144,4 +148,4 @@ NAN_MODULE_INIT(Init) {
GetFunction(New<FunctionTemplate>(GetContacts)).ToLocalChecked());
}

NODE_MODULE(addon, Init)
NODE_MODULE(addon, Init)