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 --> <!-- Permissions -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_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-permission android:name="android.permission.CAMERA" />
<uses-sdk tools:overrideLibrary="com.google.zxing.client.android" /> <uses-sdk tools:overrideLibrary="com.google.zxing.client.android" />
<uses-feature
android:name="android.hardware.camera"
android:required="true" />
</manifest> </manifest>

View file

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

View file

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

49
package-lock.json generated
View file

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

View file

@ -34,9 +34,9 @@
"@awesome-cordova-plugins/sms": "^6.3.0", "@awesome-cordova-plugins/sms": "^6.3.0",
"@awesome-cordova-plugins/social-sharing": "^6.3.0", "@awesome-cordova-plugins/social-sharing": "^6.3.0",
"@awesome-cordova-plugins/theme-detection": "^6.3.0", "@awesome-cordova-plugins/theme-detection": "^6.3.0",
"@capacitor-community/barcode-scanner": "^3.0.3", "@capacitor-community/barcode-scanner": "^4.0.1",
"@capacitor-community/contacts": "^2.0.0", "@capacitor-community/contacts": "^5.0.3",
"@capacitor-community/screen-brightness": "^4.0.0", "@capacitor-community/screen-brightness": "^5.0.0",
"@capacitor/android": "^5.0.0", "@capacitor/android": "^5.0.0",
"@capacitor/app": "^5.0.0", "@capacitor/app": "^5.0.0",
"@capacitor/camera": "^5.0.0", "@capacitor/camera": "^5.0.0",
@ -102,4 +102,4 @@
"ts-node": "~8.3.0", "ts-node": "~8.3.0",
"typescript": "~4.8.3" "typescript": "~4.8.3"
} }
} }

View file

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