chore: upgrade @capacitor-community plugins

This commit is contained in:
Tom Fong 2023-06-27 11:57:42 +08:00
parent 94bd973730
commit f8bfdcf52e
6 changed files with 129 additions and 113 deletions

View file

@ -41,6 +41,11 @@
<!-- Permissions -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-sdk tools:overrideLibrary="com.google.zxing.client.android" />
<uses-feature
android:name="android.hardware.camera"
android:required="true" />
</manifest>

View file

@ -5,7 +5,7 @@
},
{
"pkg": "@capacitor-community/contacts",
"classpath": "ch.byrds.capacitor.contacts.Contacts"
"classpath": "getcapacitor.community.contacts.ContactsPlugin"
},
{
"pkg": "@capacitor-community/screen-brightness",

View file

@ -7,11 +7,11 @@ PODS:
- Capacitor
- CapacitorClipboard (5.0.4):
- Capacitor
- CapacitorCommunityBarcodeScanner (3.0.3):
- CapacitorCommunityBarcodeScanner (4.0.1):
- Capacitor
- CapacitorCommunityContacts (2.0.0):
- CapacitorCommunityContacts (5.0.3):
- Capacitor
- CapacitorCommunityScreenBrightness (4.0.0):
- CapacitorCommunityScreenBrightness (5.0.0):
- Capacitor
- CapacitorCordova (5.0.5)
- CapacitorDevice (5.0.4):
@ -93,9 +93,9 @@ SPEC CHECKSUMS:
CapacitorApp: 7a5dec8b33573707164b293475d5c89ba684364a
CapacitorCamera: 9b5c8e809c1042f263994f97ba846aa37e974f12
CapacitorClipboard: 46f3959735fa0d96b9989dafcc4aed52e624d163
CapacitorCommunityBarcodeScanner: c61469507bb16f41ef2d3f6d92069974aeb7890d
CapacitorCommunityContacts: 07dc6241e29629e4eec0b0ec9726c6a498dd7b94
CapacitorCommunityScreenBrightness: 6a93c0c7c2792cc1b8db704f7a7774830bed50c1
CapacitorCommunityBarcodeScanner: 7feb206489c8555a8ca0c74c57ddf49ead774eb8
CapacitorCommunityContacts: fda3a2e951a1300869ccb6ca0763adf9b2b5b4ff
CapacitorCommunityScreenBrightness: b2d9c6fffee6b684994cd69f727f2090e2f05c6d
CapacitorCordova: f8c06b897c74ee8f7701fe10e6443b40822bc83a
CapacitorDevice: eb4b5e3b42ac35d2527f20aad296b59e0785dc8d
CapacitorFilesystem: e1bdfab09b95b181c844c16abcfda45ec8e8ed6b

49
package-lock.json generated
View file

@ -26,9 +26,9 @@
"@awesome-cordova-plugins/sms": "^6.3.0",
"@awesome-cordova-plugins/social-sharing": "^6.3.0",
"@awesome-cordova-plugins/theme-detection": "^6.3.0",
"@capacitor-community/barcode-scanner": "^3.0.3",
"@capacitor-community/contacts": "^2.0.0",
"@capacitor-community/screen-brightness": "^4.0.0",
"@capacitor-community/barcode-scanner": "^4.0.1",
"@capacitor-community/contacts": "^5.0.3",
"@capacitor-community/screen-brightness": "^5.0.0",
"@capacitor/android": "^5.0.0",
"@capacitor/app": "^5.0.0",
"@capacitor/camera": "^5.0.0",
@ -2773,45 +2773,31 @@
}
},
"node_modules/@capacitor-community/barcode-scanner": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/@capacitor-community/barcode-scanner/-/barcode-scanner-3.0.3.tgz",
"integrity": "sha512-XXxiumONhaIgCwzzoZazmNIybsBq0KFvgQZxtv4TWH2zakmr6dOAvj7DYp6KZOapHS/zg3s6czF8MCpFTjbQWQ==",
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/@capacitor-community/barcode-scanner/-/barcode-scanner-4.0.1.tgz",
"integrity": "sha512-acuhDU2mqskSeCIQMc5TGNnDszXXs4IqEES+3C2JDiq+MkJMTr+B2Dhq4k55hlkRFMOumMhlnbr2R9G6qyFPhw==",
"dependencies": {
"@zxing/browser": "^0.1.1",
"@zxing/library": "^0.19.2"
"@zxing/browser": "^0.1.3",
"@zxing/library": "^0.20.0"
},
"peerDependencies": {
"@capacitor/core": "^4.5.0"
}
},
"node_modules/@capacitor-community/barcode-scanner/node_modules/@zxing/library": {
"version": "0.19.3",
"resolved": "https://registry.npmjs.org/@zxing/library/-/library-0.19.3.tgz",
"integrity": "sha512-RUv5svewpDoD0ymXleOP8yVTO5BLkR0zn5coGC/Vs1671u0OBJ4xdtR8WVWf08OcvrieEMHdSfQY3ZKtqII/hg==",
"dependencies": {
"ts-custom-error": "^3.2.1"
},
"engines": {
"node": ">= 10.4.0"
},
"optionalDependencies": {
"@zxing/text-encoding": "~0.9.0"
"@capacitor/core": "^5.0.0"
}
},
"node_modules/@capacitor-community/contacts": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@capacitor-community/contacts/-/contacts-2.0.0.tgz",
"integrity": "sha512-9fdbkD1r0BclJU9q8P5qsoJSd3Zks89FkciiRAnxjPGyarb4ZJcUrIi3WAl1XivMp+Plf8ZJjy76wgSPt+9+zg==",
"version": "5.0.3",
"resolved": "https://registry.npmjs.org/@capacitor-community/contacts/-/contacts-5.0.3.tgz",
"integrity": "sha512-G9BUCww02fuBGCq0W01jZg86ntAFz/31ZZ6f6t8Or0EP8KF0hNyqO3e92IM9y95QvkPpvXLbNVyEYeibgq3sAA==",
"peerDependencies": {
"@capacitor/core": "^4.0.0"
"@capacitor/core": "^5.0.0"
}
},
"node_modules/@capacitor-community/screen-brightness": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/@capacitor-community/screen-brightness/-/screen-brightness-4.0.0.tgz",
"integrity": "sha512-P0wWVZiyIfVZbFAmYmRK16nsbTAx8Q9wCJN3p0l5F4tAyDG04J//P235HomD0nA/horzfKsGz4axdDhiUb0uRw==",
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/@capacitor-community/screen-brightness/-/screen-brightness-5.0.0.tgz",
"integrity": "sha512-EaAV7mk+Noxi0Natcx8C7C7ecW9IFAsMotYHjR/Ve8R4kA0ksvvjuWoAc0YtWT0DvpXP8qViWN2xU3Q8Uz6v4w==",
"peerDependencies": {
"@capacitor/core": "^4.0.0"
"@capacitor/core": "^5.0.0"
}
},
"node_modules/@capacitor/android": {
@ -5745,7 +5731,6 @@
"version": "0.20.0",
"resolved": "https://registry.npmjs.org/@zxing/library/-/library-0.20.0.tgz",
"integrity": "sha512-6Ev6rcqVjMakZFIDvbUf0dtpPGeZMTfyxYg4HkVWioWeN7cRcnUWT3bU6sdohc82O1nPXcjq6WiGfXX2Pnit6A==",
"peer": true,
"dependencies": {
"ts-custom-error": "^3.2.1"
},

View file

@ -34,9 +34,9 @@
"@awesome-cordova-plugins/sms": "^6.3.0",
"@awesome-cordova-plugins/social-sharing": "^6.3.0",
"@awesome-cordova-plugins/theme-detection": "^6.3.0",
"@capacitor-community/barcode-scanner": "^3.0.3",
"@capacitor-community/contacts": "^2.0.0",
"@capacitor-community/screen-brightness": "^4.0.0",
"@capacitor-community/barcode-scanner": "^4.0.1",
"@capacitor-community/contacts": "^5.0.3",
"@capacitor-community/screen-brightness": "^5.0.0",
"@capacitor/android": "^5.0.0",
"@capacitor/app": "^5.0.0",
"@capacitor/camera": "^5.0.0",

View file

@ -1,6 +1,6 @@
import { Component, QueryList, ViewChildren } from '@angular/core';
import { Clipboard } from '@capacitor/clipboard';
import { Contacts, ContactType, EmailAddress, NewContact, PhoneNumber } from '@capacitor-community/contacts'
import { ContactInput, Contacts, EmailInput, EmailType, PhoneInput, PhoneType } from '@capacitor-community/contacts';
import { SMS } from '@awesome-cordova-plugins/sms/ngx';
import { Haptics, ImpactStyle } from '@capacitor/haptics';
import { AlertController, LoadingController, ModalController, Platform } from '@ionic/angular';
@ -224,104 +224,130 @@ export class ResultPage {
}
async addContact(): Promise<void> {
let newContact = null;
let contactInput: ContactInput = {};
if (this.contentType === "contact") {
const phoneNumbers = [];
const phoneNumbers: PhoneInput[] = [];
if (this.vCardContact?.defaultPhoneNumber != null) {
const phoneNumber = { number: this.vCardContact?.defaultPhoneNumber } as PhoneNumber;
const phoneNumber: PhoneInput = {
type: PhoneType.Mobile,
label: 'mobile',
number: this.vCardContact?.defaultPhoneNumber,
isPrimary: true,
};
phoneNumbers.push(phoneNumber);
}
if (this.vCardContact?.homePhoneNumber != null) {
const phoneNumber = { number: this.vCardContact?.homePhoneNumber } as PhoneNumber;
const phoneNumber: PhoneInput = {
type: PhoneType.Home,
label: 'home',
number: this.vCardContact?.homePhoneNumber,
};
phoneNumbers.push(phoneNumber);
}
if (this.vCardContact?.workPhoneNumber != null) {
const phoneNumber = { number: this.vCardContact?.homePhoneNumber } as PhoneNumber;
const phoneNumber: PhoneInput = {
type: PhoneType.Work,
label: 'work',
number: this.vCardContact?.workPhoneNumber,
};
phoneNumbers.push(phoneNumber);
}
if (this.vCardContact?.mobilePhoneNumber != null) {
const phoneNumber = { number: this.vCardContact?.mobilePhoneNumber } as PhoneNumber;
const phoneNumber: PhoneInput = {
type: PhoneType.Mobile,
label: 'mobile',
number: this.vCardContact?.mobilePhoneNumber,
};
phoneNumbers.push(phoneNumber);
}
const emails = [];
const emails: EmailInput[] = [];
if (this.vCardContact?.defaultEmail != null) {
const address = { address: this.vCardContact?.defaultEmail } as EmailAddress;
emails.push(address);
const emailInput: EmailInput = {
type: EmailType.Home,
label: 'home',
isPrimary: true,
address: this.vCardContact?.defaultEmail,
};
emails.push(emailInput);
}
if (this.vCardContact?.homeEmail != null) {
const address = { address: this.vCardContact?.homeEmail } as EmailAddress;
emails.push(address);
const emailInput: EmailInput = {
type: EmailType.Home,
label: 'home',
address: this.vCardContact?.homeEmail,
};
emails.push(emailInput);
}
if (this.vCardContact?.workEmail != null) {
const address = { address: this.vCardContact?.workEmail } as EmailAddress;
emails.push(address);
const emailInput: EmailInput = {
type: EmailType.Work,
label: 'work',
address: this.vCardContact?.workEmail,
};
emails.push(emailInput);
}
newContact = {
contactType: ContactType.Person,
givenName: this.vCardContact?.givenName ?? this.vCardContact?.fullName ?? '',
familyName: this.vCardContact?.familyName,
phoneNumbers: phoneNumbers,
emailAddresses: emails
} as NewContact;
contactInput.phones = phoneNumbers;
contactInput.emails = emails;
contactInput.name = {
given: this.vCardContact?.givenName ?? this.vCardContact?.fullName ?? '',
family: this.vCardContact?.familyName,
};
} else if (this.contentType === "sms" || this.contentType === "phone") {
const phoneNumbers = [];
const phoneNumber = { number: this.phoneNumber } as PhoneNumber;
phoneNumbers.push(phoneNumber);
newContact = {
contactType: ContactType.Person,
phoneNumbers: phoneNumbers
} as NewContact;
const phones: PhoneInput[] = [
{
type: PhoneType.Mobile,
label: 'mobile',
number: this.phoneNumber,
isPrimary: true,
}
];
contactInput.phones = phones;
}
if (newContact != null) {
if (this.platform.is('ios')) {
await Contacts.getPermissions().then(
async permission => {
if (permission.granted) {
await this.saveContact(newContact);
} else {
const alert = await this.alertController.create({
header: this.translate.instant("PERMISSION_REQUIRED"),
message: this.translate.instant("MSG.CONTACT_PERMISSION"),
buttons: [
{
text: this.translate.instant("SETTING"),
handler: () => {
BarcodeScanner.openAppSettings();
return true;
}
},
{
text: this.translate.instant("CLOSE"),
handler: () => {
return true;
}
}
],
cssClass: ['alert-bg']
});
await alert.present();
}
}
);
// TODO: iOS contact handling
// await Contacts.checkPermissions().then(
// async permission => {
// if (permission.contacts == 'granted') {
// await this.saveContact(newContact);
// } else {
// const alert = await this.alertController.create({
// header: this.translate.instant("PERMISSION_REQUIRED"),
// message: this.translate.instant("MSG.CONTACT_PERMISSION"),
// buttons: [
// {
// text: this.translate.instant("SETTING"),
// handler: () => {
// BarcodeScanner.openAppSettings();
// return true;
// }
// },
// {
// text: this.translate.instant("CLOSE"),
// handler: () => {
// return true;
// }
// }
// ],
// cssClass: ['alert-bg']
// });
// await alert.present();
// }
// }
// );
} else { // Android doesn't need to get permission
await this.saveContact(newContact);
}
await this.saveContact(contactInput);
}
}
private async saveContact(newContact: any) {
await Contacts.saveContact(newContact).then(
private async saveContact(contactInput: ContactInput) {
await Contacts.createContact({ contact: contactInput }).then(
_ => {
if (this.isIOS) {
this.presentToast(this.translate.instant('MSG.SAVED_CONTACT'), "short", "bottom");
} else {
this.presentToast(this.translate.instant('MSG.SAVING_CONTACT'), "short", "bottom");
}
}
).catch(
err => {
if (this.env.isDebugging) {
this.presentToast("Error when call Contacts.saveContact: " + JSON.stringify(err), "long", "top");
this.presentToast("Error when call Contacts.createContact: " + JSON.stringify(err), "long", "top");
} else {
this.presentToast(this.translate.instant('MSG.FAILED_SAVING_CONTACT'), "short", "bottom");
}