browser notification is implemented
This commit is contained in:
parent
bed06e0f71
commit
d529a3b4a0
|
@ -27,7 +27,7 @@ export function initializeApp(appService: AppService) {
|
|||
{
|
||||
provide: APP_INITIALIZER,
|
||||
useFactory: initializeApp,
|
||||
deps: [AppService],
|
||||
deps: [AppService, UCAP_NATIVE_SERVICE],
|
||||
multi: true
|
||||
}
|
||||
]
|
||||
|
|
|
@ -6,16 +6,13 @@ import { UCAP_NATIVE_SERVICE, NativeService } from '@ucap-webmessenger/native';
|
|||
|
||||
export async function createTranslateLoader(nativeService: NativeService) {
|
||||
// tslint:disable-next-line: variable-name
|
||||
let _TranslateLoader;
|
||||
_TranslateLoader = await import('@ucap-webmessenger/native-browser').then(
|
||||
m => m.TranslateBrowserLoader
|
||||
);
|
||||
_TranslateLoader = await import('@ucap-webmessenger/native-electron').then(
|
||||
m => m.TranslateElectronLoader
|
||||
const translateLoader = nativeService.getTranslateLoader(
|
||||
'./assets/i18n/',
|
||||
'.json'
|
||||
);
|
||||
|
||||
// return new TranslateBrowserLoader(nativeService, './assets/i18n/', '.json');
|
||||
return new _TranslateLoader(nativeService, './assets/i18n/', '.json');
|
||||
return translateLoader;
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { Injectable, Inject } from '@angular/core';
|
||||
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
|
||||
import { EnviromentUtilService } from '@ucap-webmessenger/util';
|
||||
import { DeviceType } from '@ucap-webmessenger/core';
|
||||
import { EnvironmentsInfo, KEY_ENVIRONMENTS_INFO } from '@app/types';
|
||||
import { AppNotificationService } from './notification.service';
|
||||
import { NativeService, UCAP_NATIVE_SERVICE } from '@ucap-webmessenger/native';
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
constructor(
|
||||
private enviromentUtilService: EnviromentUtilService,
|
||||
private sessionStorageService: SessionStorageService,
|
||||
private appNotificationService: AppNotificationService
|
||||
private appNotificationService: AppNotificationService,
|
||||
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService
|
||||
) {}
|
||||
|
||||
public postInit(): Promise<any> {
|
||||
|
@ -35,6 +37,7 @@ export class AppService {
|
|||
);
|
||||
|
||||
this.appNotificationService.subscribe();
|
||||
this.nativeService.postAppInit();
|
||||
resolve();
|
||||
} catch (error) {
|
||||
reject();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Type } from '@angular/core';
|
||||
import { Type, ModuleWithProviders } from '@angular/core';
|
||||
import { NativeService } from '@ucap-webmessenger/native';
|
||||
|
||||
export abstract class UrlConfig {
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
import { NotificationRequest } from '@ucap-webmessenger/native';
|
||||
|
||||
export class NotificationService {
|
||||
notificationPermission: NotificationPermission;
|
||||
|
||||
constructor() {
|
||||
this.notificationPermission = this.isSupported() ? 'default' : 'denied';
|
||||
}
|
||||
|
||||
public isSupported(): boolean {
|
||||
return 'Notification' in window;
|
||||
}
|
||||
|
||||
requestPermission(): void {
|
||||
const self = this;
|
||||
if ('Notification' in window) {
|
||||
Notification.requestPermission().then(result => {
|
||||
self.notificationPermission = result;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
notify(noti: NotificationRequest) {
|
||||
const notification = new Notification(noti.title, { body: noti.contents });
|
||||
notification.onclick = e => {
|
||||
console.log('notification.onclick');
|
||||
};
|
||||
notification.onclose = e => {
|
||||
console.log('notification.onclose');
|
||||
};
|
||||
notification.onerror = e => {
|
||||
console.log('notification.onerror');
|
||||
};
|
||||
}
|
||||
}
|
|
@ -9,12 +9,24 @@ import {
|
|||
import { HttpClient } from '@angular/common/http';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { TranslateLoader } from '@ngx-translate/core';
|
||||
import { TranslateLoaderService } from '../translate/browser-loader';
|
||||
import { NotificationService } from '../notification/notification.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class BrowserNativeService implements NativeService {
|
||||
notify(noti: NotificationRequest): void {}
|
||||
private notificationService: NotificationService;
|
||||
|
||||
postAppInit(): void {
|
||||
this.notificationService.requestPermission();
|
||||
}
|
||||
|
||||
notify(noti: NotificationRequest): void {
|
||||
console.log('ddd');
|
||||
this.notificationService.notify(noti);
|
||||
}
|
||||
closeAllNotify(): void {}
|
||||
|
||||
checkForUpdates(): Observable<boolean> {
|
||||
|
@ -77,5 +89,11 @@ export class BrowserNativeService implements NativeService {
|
|||
});
|
||||
}
|
||||
|
||||
constructor(private httpClient: HttpClient) {}
|
||||
getTranslateLoader(prefix?: string, suffix?: string): TranslateLoader {
|
||||
return new TranslateLoaderService(this, prefix, suffix);
|
||||
}
|
||||
|
||||
constructor(private httpClient: HttpClient) {
|
||||
this.notificationService = new NotificationService();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,11 @@
|
|||
import { TranslateLoader } from '@ngx-translate/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { NativeService, UCAP_NATIVE_SERVICE } from '@ucap-webmessenger/native';
|
||||
import { NativeService } from '@ucap-webmessenger/native';
|
||||
import { take, map } from 'rxjs/operators';
|
||||
import { FileUtil } from '@ucap-webmessenger/core';
|
||||
import { Injectable, Inject } from '@angular/core';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class TranslateBrowserLoader implements TranslateLoader {
|
||||
export class TranslateLoaderService implements TranslateLoader {
|
||||
constructor(
|
||||
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService,
|
||||
private nativeService: NativeService,
|
||||
private prefix: string = '/assets/i18n/',
|
||||
private suffix: string = '.json'
|
||||
) {}
|
||||
|
|
|
@ -17,6 +17,8 @@ import {
|
|||
IdleStateChannel
|
||||
} from '../types/channel.type';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { TranslateLoaderService } from '../translate/electron-loader';
|
||||
import { TranslateLoader } from '@ngx-translate/core';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
@ -28,6 +30,8 @@ export class ElectronNativeService implements NativeService {
|
|||
private idleStateChangedSubject: Subject<WindowIdle> | null = null;
|
||||
private idleStateChanged$: Observable<WindowIdle> | null = null;
|
||||
|
||||
postAppInit(): void {}
|
||||
|
||||
notify(noti: NotificationRequest): void {
|
||||
ipcRenderer.send(NotificationChannel.Notify, noti);
|
||||
}
|
||||
|
@ -149,5 +153,9 @@ export class ElectronNativeService implements NativeService {
|
|||
return this.idleStateChanged$;
|
||||
}
|
||||
|
||||
getTranslateLoader(prefix?: string, suffix?: string): TranslateLoader {
|
||||
return new TranslateLoaderService(this, prefix, suffix);
|
||||
}
|
||||
|
||||
constructor() {}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
import { TranslateLoader } from '@ngx-translate/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { NativeService, UCAP_NATIVE_SERVICE } from '@ucap-webmessenger/native';
|
||||
import { NativeService } from '@ucap-webmessenger/native';
|
||||
import { take, map } from 'rxjs/operators';
|
||||
import { Inject } from '@angular/core';
|
||||
|
||||
export class TranslateElectronLoader implements TranslateLoader {
|
||||
export class TranslateLoaderService implements TranslateLoader {
|
||||
constructor(
|
||||
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService,
|
||||
private nativeService: NativeService,
|
||||
private prefix: string = '/assets/i18n/',
|
||||
private suffix: string = '.json'
|
||||
) {}
|
||||
|
|
|
@ -3,8 +3,11 @@ import { Observable } from 'rxjs';
|
|||
import { WindowState } from '../types/window-state.type';
|
||||
import { WindowIdle } from '../types/window-idle.type';
|
||||
import { NotificationRequest } from '../models/notification';
|
||||
import { TranslateLoader } from '@ngx-translate/core';
|
||||
|
||||
export interface NativeService {
|
||||
postAppInit(): void;
|
||||
|
||||
notify(noti: NotificationRequest): void;
|
||||
closeAllNotify(): void;
|
||||
|
||||
|
@ -21,4 +24,6 @@ export interface NativeService {
|
|||
windowMaximize(): void;
|
||||
|
||||
idleStateChanged(): Observable<WindowIdle>;
|
||||
|
||||
getTranslateLoader(prefix?: string, suffix?: string): TranslateLoader;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user