Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async onSWUpdate() {
const registration = await navigator.serviceWorker.getRegistration();
if (!registration || !registration.waiting) {
// If there is no registration, this is the first service
// worker to be installed. registration.waiting is the one
// waiting to be activiated.
return;
}
const toast = await toastCtrl.create({
message: "New version available",
showCloseButton: true,
closeButtonText: "Reload"
});
await toast.present();
await toast.onWillDismiss();
registration.waiting.postMessage("skipWaiting");
window.location.reload();
}
async openColorVision() {
const modal = await modalCtrl.create({
component: 'color-modal'
});
await modal.present();
const colorData = await modal.onDidDismiss();
console.log(colorData.data);
if (colorData.data && colorData.data.length > 0) {
this.selectColor(`#${colorData.data}`);
const toast = await toastCtrl.create({
message: `Found this color: #${colorData.data}`,
duration: 1200,
position: "top",
});
await toast.present();
}
}
async erase() {
ga('send', 'event', ['Button'], ['Erase'], ['Erasing']);
if (!this.erasing) {
this.eraserMode.emit();
this.erasing = true;
const eraseToast = await toastCtrl.create({
message: 'erase mode',
duration: 1300,
position: 'top'
});
await eraseToast.present();
}
else {
this.erasing = false;
this.penMode.emit();
const penToast = await toastCtrl.create({
message: 'pen mode',
duration: 1300,
position: 'top'
});
await penToast.present();
console.log(appCanvas);
await appCanvas.saveCanvas(data.fileName);
console.log(data);
this.currentFileName = data.fileName;
}
}
]
});
await alert.present();
}
else if (this.currentFileName) {
await appCanvas.saveCanvas(this.currentFileName);
const toast = await toastController.create({
message: `${this.currentFileName} saved`,
duration: 1800
});
await toast.present();
}
}
/*let remoteImages = [];
this.images.forEach((image) => {
if (image.id) {
remoteImages.push({ id: image.id, name: image.name });
}
});
saveImages(remoteImages);*/
await saveImagesS(this.images);
await loading.dismiss();
const toast = await toastCtrl.create({
message: "Board uploaded to OneDrive",
duration: 1800
});
await toast.present();
}
catch (err) {
console.error(err);
const toast = await toastCtrl.create({
message: "Upload failed, try again later",
duration: 1800
});
await toast.present();
}
}
}
private async toastError(error: string) {
const popover: HTMLIonToastElement = await toastController.create({
message: error,
showCloseButton: true,
position: 'top',
color: 'danger',
duration: 6000
});
await popover.present();
}
let imageToDelete = null;
this.images.forEach((image) => {
if (image.name === imagePicked.name) {
imageToDelete = image;
}
});
if (imageToDelete !== null) {
const indexOfImage = this.images.indexOf(imageToDelete);
if (indexOfImage > -1) {
this.images.splice(indexOfImage, 1);
const toast = await toastCtrl.create({
message: "deleting image",
duration: 1300
});
await toast.present();
this.images = [...this.images];
await set('images', this.images);
await saveImagesS(this.images);
}
}
event.preventDefault();
}