100 lines
2.4 KiB
TypeScript

import { Observable } from 'rxjs';
import {
NativeService,
WindowState,
NotificationRequest,
WindowIdle
} from '@ucap-webmessenger/native';
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 {
private notificationService: NotificationService;
postAppInit(): void {
this.notificationService.requestPermission();
}
notify(noti: NotificationRequest): void {
console.log('ddd');
this.notificationService.notify(noti);
}
closeAllNotify(): void {}
checkForUpdates(): Observable<boolean> {
return new Observable<boolean>(subscriber => {
try {
subscriber.next(false);
} catch (error) {
subscriber.error(error);
} finally {
subscriber.complete();
}
});
}
showImageViewer(): void {}
readFile(path: string): Observable<Buffer> {
return this.httpClient.get(path, { responseType: 'arraybuffer' }).pipe(
map(arrayBuffer => {
return Buffer.from(arrayBuffer);
})
);
}
saveFile(
buffer: Buffer,
fileName: string,
path?: string
): Observable<string> {
return this.httpClient.post<string>(path, buffer, {});
}
windowStateChanged(): Observable<WindowState> {
return new Observable<WindowState>(subscriber => {
try {
subscriber.next(WindowState.Normal);
} catch (error) {
subscriber.error(error);
} finally {
subscriber.complete();
}
});
}
windowClose(): void {}
windowMinimize(): void {}
windowMaximize(): void {}
idleStateChanged(): Observable<WindowIdle> {
return new Observable<WindowIdle>(subscriber => {
try {
subscriber.next(WindowIdle.Active);
} catch (error) {
subscriber.error(error);
} finally {
subscriber.complete();
}
});
}
getTranslateLoader(prefix?: string, suffix?: string): TranslateLoader {
return new TranslateLoaderService(this, prefix, suffix);
}
constructor(private httpClient: HttpClient) {
this.notificationService = new NotificationService();
}
}