100 lines
2.4 KiB
TypeScript
Raw Normal View History

import { Observable } from 'rxjs';
2019-11-01 11:25:54 +09:00
import {
NativeService,
WindowState,
2019-11-09 17:29:02 +09:00
NotificationRequest,
WindowIdle
2019-11-01 11:25:54 +09:00
} from '@ucap-webmessenger/native';
import { HttpClient } from '@angular/common/http';
import { map } from 'rxjs/operators';
2019-11-11 15:53:39 +09:00
import { Injectable } from '@angular/core';
2019-11-11 18:09:47 +09:00
import { TranslateLoader } from '@ngx-translate/core';
import { TranslateLoaderService } from '../translate/browser-loader';
import { NotificationService } from '../notification/notification.service';
2019-11-11 15:53:39 +09:00
@Injectable({
providedIn: 'root'
})
export class BrowserNativeService implements NativeService {
2019-11-11 18:09:47 +09:00
private notificationService: NotificationService;
postAppInit(): void {
this.notificationService.requestPermission();
}
notify(noti: NotificationRequest): void {
console.log('ddd');
this.notificationService.notify(noti);
}
2019-11-09 17:29:02 +09:00
closeAllNotify(): void {}
checkForUpdates(): Observable<boolean> {
return new Observable<boolean>(subscriber => {
try {
subscriber.next(false);
} catch (error) {
subscriber.error(error);
} finally {
subscriber.complete();
}
});
}
showImageViewer(): void {}
2019-11-07 11:37:33 +09:00
readFile(path: string): Observable<Buffer> {
return this.httpClient.get(path, { responseType: 'arraybuffer' }).pipe(
map(arrayBuffer => {
return Buffer.from(arrayBuffer);
})
);
}
2019-11-07 11:37:33 +09:00
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();
}
});
}
2019-11-11 18:09:47 +09:00
getTranslateLoader(prefix?: string, suffix?: string): TranslateLoader {
return new TranslateLoaderService(this, prefix, suffix);
}
constructor(private httpClient: HttpClient) {
this.notificationService = new NotificationService();
}
}