Files
doneit-web/src/app/app.component.ts
T

139 lines
4.1 KiB
TypeScript
Raw Normal View History

2023-01-02 15:42:15 +01:00
import { Component } from '@angular/core';
2020-08-05 15:39:16 +01:00
import { Platform } from '@ionic/angular';
import { StatusBar } from '@ionic-native/status-bar/ngx';
2021-06-24 11:08:17 +01:00
import { NgxMatDateFormats } from '@angular-material-components/datetime-picker';
import { NGX_MAT_DATE_FORMATS } from '@angular-material-components/datetime-picker';
2022-07-05 14:37:06 +01:00
import { ThemeService } from 'src/app/services/theme.service';
2022-12-19 15:49:04 +01:00
import { environment } from 'src/environments/environment';
2022-12-22 15:24:48 +01:00
import { Storage } from '@ionic/storage';
2023-11-29 12:17:52 +01:00
import { register } from 'swiper/element/bundle';
2024-02-09 10:57:41 +01:00
import { DomSanitizer } from '@angular/platform-browser';
2024-07-31 17:23:44 +01:00
import { ScreenOrientation } from "@ionic-native/screen-orientation/ngx";
2024-11-06 10:47:07 +01:00
import { SessionStore } from './store/session.service';
2021-06-24 11:08:17 +01:00
const CUSTOM_DATE_FORMATS: NgxMatDateFormats = {
parse: {
dateInput: "YYYY-MMMM-DD HH:mm"
},
display: {
dateInput: "DD MMM YYYY H:mm",
monthYearLabel: "MMM YYYY",
dateA11yLabel: "LL",
monthYearA11yLabel: "MMMM YYYY"
}
}
2023-11-29 12:17:52 +01:00
register();
2021-02-25 11:50:32 +01:00
2020-08-05 15:39:16 +01:00
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
2021-06-24 11:08:17 +01:00
styleUrls: ['app.component.scss'],
providers: [
{ provide: NGX_MAT_DATE_FORMATS, useValue: CUSTOM_DATE_FORMATS },
]
2020-08-05 15:39:16 +01:00
})
export class AppComponent {
2024-11-06 10:47:07 +01:00
tabIsActive = true
2020-08-05 15:39:16 +01:00
constructor(
private platform: Platform,
2021-10-28 09:30:28 +01:00
private statusBar: StatusBar,
2022-07-05 14:37:06 +01:00
public ThemeService: ThemeService,
2023-06-22 12:53:35 +01:00
private storage: Storage,
2024-03-11 11:18:32 +01:00
private sanitizer: DomSanitizer,
2024-07-11 10:28:21 +01:00
private screenOrientation: ScreenOrientation,
2020-08-05 15:39:16 +01:00
) {
2023-07-11 17:54:08 +01:00
2024-02-09 10:57:41 +01:00
window["sanitizer"] = this.sanitizer
2020-08-05 15:39:16 +01:00
this.initializeApp();
2022-12-22 15:24:48 +01:00
this.storage.set('version', environment.version).then(() => {})
2024-02-22 11:40:06 +01:00
2024-10-23 15:30:15 +01:00
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/firebase-messaging-sw.js')
.then(registration => {
console.log('Service Worker registrado com sucesso:', registration);
// Send data to the service worker
if (registration.active) {
registration.active.postMessage({ type: 'INIT_WEBSOCKET', url: 'wss://example.com/socket' });
} else {
navigator.serviceWorker.ready.then(registration => {
registration.active.postMessage({ type: 'INIT_WEBSOCKET', url: 'wss://example.com/socket' });
});
}
})
.catch(error => {
console.error('Erro ao registrar o Service Worker:', error);
});
}
}
2024-11-06 10:47:07 +01:00
window.addEventListener('focus', (event) => {
if (!this.tabIsActive) {
this.tabIsActive = true
const data = SessionStore.getDataFromLocalStorage();
if (!data?.user?.Authorization && SessionStore?.user?.Authorization) {
window.location.reload();
}
if (window['all-process-gabinete']) {
window['all-process-gabinete']()
}
}
});
window.addEventListener('blur', (event) => {
this.tabIsActive = false
});
2020-08-05 15:39:16 +01:00
}
2023-06-26 11:12:57 +01:00
/* requestPermission() {
this.afMessaging.requestToken.subscribe(
(token) => {
// Save the token to your server for sending notifications
console.log('Permission granted! Token:', token);
},
(error) => {
console.error('Permission denied:', error);
}
);
}
receiveMessages() {
this.afMessaging.messages.subscribe((message) => {
console.log('Received message:', message);
// Handle the received message, e.g., show a notification
});
} */
2020-08-05 15:39:16 +01:00
initializeApp() {
this.platform.ready().then(() => {
2021-02-25 11:50:32 +01:00
this.statusBar.styleDefault();
2024-02-22 11:40:06 +01:00
2021-10-28 09:30:28 +01:00
if (this.platform.is("tablet")) {
window.screen.orientation.unlock();
2021-10-28 09:30:28 +01:00
} else if( this.platform.is("mobile")) {
2024-03-11 11:18:32 +01:00
if(this.platform.is('ios')){
this.screenOrientation.lock('portrait')
} else {
2024-08-09 12:36:51 +01:00
(window.screen.orientation as any).lock('portrait');
2024-03-11 11:18:32 +01:00
}
2021-10-28 09:30:28 +01:00
}
2020-08-05 15:39:16 +01:00
});
}
}
2024-08-05 11:12:51 +01:00
window.onerror = function(message, source, lineno, colno, error) {
if (error) message = error.stack;
console.log('send', 'event', 'window.onerror', message, navigator.userAgent);
}
// ============================================================================