native notifications are added

This commit is contained in:
병준 박 2019-11-19 16:44:50 +09:00
parent 67e27594ea
commit 44e576fc72
8 changed files with 166 additions and 42 deletions

View File

@ -21,7 +21,8 @@ import {
FileChannel,
IdleStateChannel,
NotificationChannel,
ChatChannel
ChatChannel,
MessengerChannel
} from '@ucap-webmessenger/native-electron';
import { ElectronNotificationService } from '@ucap-webmessenger/electron-notification';
@ -156,18 +157,7 @@ function createWindow() {
appWindow = window;
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on(ElectronAppChannel.Ready, () => {
if (isDuplicateInstance) {
return;
}
readyTime = now() - launchTime;
createWindow();
function createTray() {
appTray = new Tray(appIconPath);
const contextMenu = Menu.buildFromTemplate([
@ -176,22 +166,15 @@ app.on(ElectronAppChannel.Ready, () => {
// accelerator: 'Q',
// selector: 'terminate:',
click: () => {
// 로그아웃 후 로그인화면.
const options = {
type: 'question',
buttons: ['취소', '로그아웃'],
defaultId: 2,
title: 'Question',
message: '로그아웃',
detail: '로그아웃 하시겠습니까?'
// checkboxLabel: 'Remember my answer',
// checkboxChecked: true,
};
const choice = dialog.showMessageBoxSync(null, options);
if (1 === choice) {
// logout
appWindow.browserWindow.webContents.send(ChatChannel.OpenRoom);
}
appWindow.browserWindow.webContents.send(MessengerChannel.Logout);
}
},
{
label: '설정',
// accelerator: 'Q',
// selector: 'terminate:',
click: () => {
appWindow.browserWindow.webContents.send(MessengerChannel.ShowSetting);
}
},
{ label: '버전', submenu: [{ label: 'Ver. ' + app.getVersion() }] },
@ -212,6 +195,21 @@ app.on(ElectronAppChannel.Ready, () => {
appTray.on('click', () => {
appWindow.isVisible() ? appWindow.hide() : appWindow.show();
});
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on(ElectronAppChannel.Ready, () => {
if (isDuplicateInstance) {
return;
}
readyTime = now() - launchTime;
createWindow();
createTray();
notificationService = new ElectronNotificationService({
width: 340,

View File

@ -5,6 +5,7 @@ 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';
import { AppNativeService } from './native.service';
@Injectable()
export class AppService {
@ -12,6 +13,7 @@ export class AppService {
private enviromentUtilService: EnviromentUtilService,
private sessionStorageService: SessionStorageService,
private appNotificationService: AppNotificationService,
private appNativeService: AppNativeService,
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService
) {}
@ -32,10 +34,11 @@ export class AppService {
this.sessionStorageService.set<EnvironmentsInfo>(
KEY_ENVIRONMENTS_INFO,
{
deviceType,
deviceType
}
);
this.appNativeService.subscribe();
this.appNotificationService.subscribe();
this.nativeService.postAppInit();
resolve();

View File

@ -2,10 +2,12 @@ import { AppService } from './app.service';
import { AppAuthenticationService } from './authentication.service';
import { AppLoaderService } from './loader.service';
import { AppNotificationService } from './notification.service';
import { AppNativeService } from './native.service';
export const SERVICES = [
AppService,
AppAuthenticationService,
AppLoaderService,
AppNotificationService
AppNotificationService,
AppNativeService
];

View File

@ -0,0 +1,25 @@
import { Injectable, Inject } from '@angular/core';
import { UCAP_NATIVE_SERVICE, NativeService } from '@ucap-webmessenger/native';
import { Store } from '@ngrx/store';
import { NGXLogger } from 'ngx-logger';
import * as AuthenticationStore from '@app/store/account/authentication';
@Injectable({
providedIn: 'root'
})
export class AppNativeService {
constructor(
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService,
private store: Store<any>,
private logger: NGXLogger
) {}
subscribe(): void {
this.nativeService.logout().subscribe(() => {
this.store.dispatch(AuthenticationStore.logout());
});
this.nativeService.changeStatus().subscribe(statusCode => {});
this.nativeService.showSetting().subscribe(() => {});
}
}

View File

@ -4,7 +4,7 @@ import {
NativeService,
WindowState,
NotificationRequest,
WindowIdle,
WindowIdle
} from '@ucap-webmessenger/native';
import { HttpClient } from '@angular/common/http';
import { map, share } from 'rxjs/operators';
@ -12,10 +12,10 @@ import { TranslateLoader } from '@ngx-translate/core';
import { TranslateLoaderService } from '../translate/browser-loader';
import { NotificationService } from '../notification/notification.service';
import { Injectable } from '@angular/core';
import { FileUtil } from '@ucap-webmessenger/core';
import { FileUtil, StatusCode } from '@ucap-webmessenger/core';
@Injectable({
providedIn: 'root',
providedIn: 'root'
})
export class BrowserNativeService extends NativeService {
private notificationService: NotificationService;
@ -27,6 +27,39 @@ export class BrowserNativeService extends NativeService {
this.notificationService.requestPermission();
}
logout(): Observable<void> {
return new Observable<void>(subscriber => {
try {
} catch (error) {
subscriber.error(error);
} finally {
subscriber.complete();
}
});
}
changeStatus(): Observable<StatusCode> {
return new Observable<StatusCode>(subscriber => {
try {
} catch (error) {
subscriber.error(error);
} finally {
subscriber.complete();
}
});
}
showSetting(): Observable<void> {
return new Observable<void>(subscriber => {
try {
} catch (error) {
subscriber.error(error);
} finally {
subscriber.complete();
}
});
}
notify(noti: NotificationRequest): void {
this.notificationService.notify(noti, () => {
window.focus();

View File

@ -6,7 +6,7 @@ import {
NativeService,
WindowState,
NotificationRequest,
WindowIdle,
WindowIdle
} from '@ucap-webmessenger/native';
import { share } from 'rxjs/operators';
import {
@ -16,18 +16,29 @@ import {
WindowStateChannel,
IdleStateChannel,
ChatChannel,
MessengerChannel
} from '../types/channel.type';
import { Injectable } from '@angular/core';
import { TranslateLoaderService } from '../translate/electron-loader';
import { TranslateLoader } from '@ngx-translate/core';
import { StatusCode } from '@ucap-webmessenger/core';
@Injectable({
providedIn: 'root',
providedIn: 'root'
})
export class ElectronNativeService implements NativeService {
private ipcRenderer: typeof ipcRenderer;
private remote: typeof remote;
private logoutSubject: Subject<void> | null = null;
private logout$: Observable<void> | null = null;
private changeStatusSubject: Subject<StatusCode> | null = null;
private changeStatus$: Observable<StatusCode> | null = null;
private showSettingSubject: Subject<void> | null = null;
private showSetting$: Observable<void> | null = null;
private windowStateChangedSubject: Subject<WindowState> | null = null;
private windowStateChanged$: Observable<WindowState> | null = null;
@ -39,6 +50,47 @@ export class ElectronNativeService implements NativeService {
postAppInit(): void {}
logout(): Observable<void> {
if (!this.logoutSubject) {
this.logoutSubject = new Subject<void>();
this.logout$ = this.logoutSubject.asObservable().pipe(share());
}
this.ipcRenderer.on(MessengerChannel.Logout, (event: any) => {
this.logoutSubject.next();
});
return this.logout$;
}
changeStatus(): Observable<StatusCode> {
if (!this.changeStatusSubject) {
this.changeStatusSubject = new Subject<StatusCode>();
this.changeStatus$ = this.changeStatusSubject
.asObservable()
.pipe(share());
}
this.ipcRenderer.on(
MessengerChannel.ChangeStatus,
(event: any, statusCode: StatusCode) => {
this.changeStatusSubject.next(statusCode);
}
);
return this.changeStatus$;
}
showSetting(): Observable<void> {
if (!this.showSettingSubject) {
this.showSettingSubject = new Subject<void>();
this.showSetting$ = this.showSettingSubject.asObservable().pipe(share());
}
this.ipcRenderer.on(MessengerChannel.ShowSetting, (event: any) => {
this.showSettingSubject.next();
});
return this.showSetting$;
}
notify(noti: NotificationRequest): void {
this.ipcRenderer.send(NotificationChannel.Notify, noti);
}

View File

@ -1,27 +1,33 @@
export enum MessengerChannel {
Logout = 'UCAP::messenger::logout',
ChangeStatus = 'UCAP::messenger::changeStatus',
ShowSetting = 'UCAP::messenger::showSetting'
}
export enum ChatChannel {
OpenRoom = 'UCAP::chat::openRoom',
OpenRoom = 'UCAP::chat::openRoom'
}
export enum NotificationChannel {
Notify = 'UCAP::notification::notify',
CloseAllNotify = 'UCAP::notification::closeAllNotify',
CloseAllNotify = 'UCAP::notification::closeAllNotify'
}
export enum UpdaterChannel {
Check = 'UCAP::updater::check',
Check = 'UCAP::updater::check'
}
export enum FileChannel {
ShowImageViewer = 'UCAP::file::showImageViewer',
SaveFile = 'UCAP::file::saveFile',
ReadFile = 'UCAP::file::readFile',
ReadFile = 'UCAP::file::readFile'
}
export enum WindowStateChannel {
Changed = 'UCAP::windowState::windowStateChanged',
Changed = 'UCAP::windowState::windowStateChanged'
}
export enum IdleStateChannel {
Changed = 'UCAP::idleState::changed',
StartCheck = 'UCAP::idleState::startCheck',
StartCheck = 'UCAP::idleState::startCheck'
}

View File

@ -4,10 +4,15 @@ 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';
import { StatusCode } from '@ucap-webmessenger/core';
export abstract class NativeService {
abstract postAppInit(): void;
abstract logout(): Observable<void>;
abstract changeStatus(): Observable<StatusCode>;
abstract showSetting(): Observable<void>;
abstract notify(noti: NotificationRequest): void;
abstract closeAllNotify(): void;