윈도우 백그라운드에 있을때 알림 주는 로직으로 개선 (미완료 1차 커밋)

This commit is contained in:
leejinho 2020-03-23 09:16:32 +09:00
parent 5ba16d1ac0
commit 9323a2af0d
6 changed files with 86 additions and 25 deletions

View File

@ -16,6 +16,7 @@ import {
import { now } from '../util/now';
import { Storage } from '../lib/storage';
import { WindowStateChannel } from '@ucap-webmessenger/native-electron';
export class AppWindow {
private window: BrowserWindow | null = null;
@ -84,12 +85,18 @@ export class AppWindow {
event.returnValue = true;
});
// windows Focus or Blur state detacted.
this.window.on(ElectronBrowserWindowChannel.Focus, () => {
console.log('window got focus');
this.window.webContents.send(
WindowStateChannel.FocuseChanged,
ElectronBrowserWindowChannel.Focus
);
});
this.window.on(ElectronBrowserWindowChannel.Blur, () => {
console.log('window blur');
this.window.webContents.send(
WindowStateChannel.FocuseChanged,
ElectronBrowserWindowChannel.Blur
);
});
// on macOS, when the user closes the window we really just hide it. This

View File

@ -130,6 +130,7 @@ import {
ChatSetting
} from '@ucap-webmessenger/ui-settings';
import clone from 'clone';
import { ElectronBrowserWindowChannel } from '@ucap-webmessenger/electron-core';
@Injectable()
export class AppNotificationService {
@ -232,14 +233,6 @@ export class AppNotificationService {
if (notiOrRes.SSVC_TYPE === SSVC_TYPE_EVENT_SEND_NOTI) {
let doNoti = true;
// 방별 알림이 꺼져 있으면 노티 안함.
if (
!!roomList[noti.roomSeq] &&
!roomList[noti.roomSeq].receiveAlarm
) {
doNoti = false;
}
const windowState = this.nativeService.getWindowState();
// 현재 열려 있는 방일경우 노티 안함.
@ -248,8 +241,27 @@ export class AppNotificationService {
!!curRoomInfo.roomSeq &&
curRoomInfo.roomSeq === noti.roomSeq &&
!!windowState &&
windowState !== WindowState.Minimized &&
windowState !== WindowState.Hidden
windowState.windowState !== WindowState.Minimized &&
windowState.windowState !== WindowState.Hidden
) {
doNoti = false;
}
// // 포커스 아웃일때 무조건 노티.
// // Case 1 : 단순 포커스 아웃.
// // Case 2 : hidden 시 포커스 인 상태이지만 위에서 필터링 됨.
// console.log(windowState);
// if (
// windowState.windowFocusState !==
// ElectronBrowserWindowChannel.Focus
// ) {
// doNoti = true;
// }
// 방별 알림이 꺼져 있으면 노티 안함. > 우선순위 최상위.
if (
!!roomList[noti.roomSeq] &&
!roomList[noti.roomSeq].receiveAlarm
) {
doNoti = false;
}

View File

@ -18,6 +18,7 @@ import { TranslateLoaderService } from '../translate/browser-loader';
import { NotificationService } from '../notification/notification.service';
import { Injectable } from '@angular/core';
import { FileUtil, StatusCode } from '@ucap-webmessenger/core';
import { ElectronBrowserWindowChannel } from '@ucap-webmessenger/electron-core';
@Injectable({
providedIn: 'root'
@ -229,8 +230,16 @@ export class BrowserNativeService extends NativeService {
windowMinimize(): void {}
windowMaximize(): void {}
getWindowState(): WindowState {
return WindowState.Normal;
getWindowState(): {
windowState: WindowState;
windowFocusState:
| ElectronBrowserWindowChannel.Focus
| ElectronBrowserWindowChannel.Blur;
} {
return {
windowState: WindowState.Normal,
windowFocusState: ElectronBrowserWindowChannel.Focus
};
}
appExit(): void {}

View File

@ -31,6 +31,7 @@ import { Injectable } from '@angular/core';
import { TranslateLoaderService } from '../translate/electron-loader';
import { TranslateLoader } from '@ngx-translate/core';
import { StatusCode } from '@ucap-webmessenger/core';
import { ElectronBrowserWindowChannel } from '@ucap-webmessenger/electron-core';
@Injectable({
providedIn: 'root'
@ -65,6 +66,10 @@ export class ElectronNativeService implements NativeService {
private backgroundCheckForUpdatesSubject: Subject<UpdateInfo> | null = null;
private backgroundCheckForUpdates$: Observable<UpdateInfo> | null = null;
private windowFocusState:
| ElectronBrowserWindowChannel.Focus
| ElectronBrowserWindowChannel.Blur;
type(): NativeType {
return NativeType.Electron;
}
@ -395,20 +400,29 @@ export class ElectronNativeService implements NativeService {
}
}
getWindowState(): WindowState {
getWindowState(): {
windowState: WindowState;
windowFocusState:
| ElectronBrowserWindowChannel.Focus
| ElectronBrowserWindowChannel.Blur;
} {
let windowState = WindowState.Normal;
if (!remote.getCurrentWindow().isVisible()) {
return WindowState.Hidden;
windowState = WindowState.Hidden;
} else if (remote.getCurrentWindow().isMinimized()) {
return WindowState.Minimized;
windowState = WindowState.Minimized;
} else if (remote.getCurrentWindow().isNormal()) {
return WindowState.Normal;
windowState = WindowState.Normal;
} else if (remote.getCurrentWindow().isMaximized()) {
return WindowState.Maximized;
windowState = WindowState.Maximized;
} else if (remote.getCurrentWindow().isFullScreen()) {
return WindowState.FullScreen;
} else {
return WindowState.Normal;
windowState = WindowState.FullScreen;
}
return {
windowState,
windowFocusState: this.windowFocusState
};
}
appExit(): void {
@ -532,5 +546,17 @@ export class ElectronNativeService implements NativeService {
this.shell = (window as any).require('electron').shell;
this.webFrame = (window as any).require('electron').webFrame;
}
this.ipcRenderer.on(
WindowStateChannel.FocuseChanged,
(
event: any,
status:
| ElectronBrowserWindowChannel.Focus
| ElectronBrowserWindowChannel.Blur
) => {
this.windowFocusState = status;
}
);
}
}

View File

@ -46,7 +46,8 @@ export enum ProcessChannel {
}
export enum WindowStateChannel {
Changed = 'UCAP::windowState::windowStateChanged'
Changed = 'UCAP::windowState::windowStateChanged',
FocuseChanged = 'UCAP::windowState::windowFocusStateChanged'
}
export enum IdleStateChannel {

View File

@ -7,6 +7,7 @@ import { TranslateLoader } from '@ngx-translate/core';
import { StatusCode } from '@ucap-webmessenger/core';
import { UpdateInfo, UpdateCheckConfig } from '../models/update-info';
import { NativeType } from '../types/native.type';
import { ElectronBrowserWindowChannel } from '@ucap-webmessenger/electron-core';
export type NativePathName =
| 'home'
@ -73,7 +74,12 @@ export abstract class NativeService {
abstract windowClose(): void;
abstract windowMinimize(): void;
abstract windowMaximize(): void;
abstract getWindowState(): WindowState;
abstract getWindowState(): {
windowState: WindowState;
windowFocusState:
| ElectronBrowserWindowChannel.Focus
| ElectronBrowserWindowChannel.Blur;
};
abstract zoomTo(factor: number): Promise<number>;
abstract appExit(): void;
abstract appLogging(error: any): void;