From 9323a2af0d8914daa364410d4d3376cb81dd250e Mon Sep 17 00:00:00 2001 From: leejinho Date: Mon, 23 Mar 2020 09:16:32 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9C=88=EB=8F=84=EC=9A=B0=20=EB=B0=B1?= =?UTF-8?q?=EA=B7=B8=EB=9D=BC=EC=9A=B4=EB=93=9C=EC=97=90=20=EC=9E=88?= =?UTF-8?q?=EC=9D=84=EB=95=8C=20=EC=95=8C=EB=A6=BC=20=EC=A3=BC=EB=8A=94=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=EC=9C=BC=EB=A1=9C=20=EA=B0=9C=EC=84=A0=20(?= =?UTF-8?q?=EB=AF=B8=EC=99=84=EB=A3=8C=201=EC=B0=A8=20=EC=BB=A4=EB=B0=8B)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/app/AppWindow.ts | 13 ++++-- .../src/app/services/notification.service.ts | 32 +++++++++----- .../lib/services/browser-native.service.ts | 13 +++++- .../lib/services/electron-native.service.ts | 42 +++++++++++++++---- .../src/lib/types/channel.type.ts | 3 +- .../src/lib/services/native.service.ts | 8 +++- 6 files changed, 86 insertions(+), 25 deletions(-) diff --git a/electron-projects/ucap-webmessenger-electron/src/app/AppWindow.ts b/electron-projects/ucap-webmessenger-electron/src/app/AppWindow.ts index 640ca1d6..e6aae927 100644 --- a/electron-projects/ucap-webmessenger-electron/src/app/AppWindow.ts +++ b/electron-projects/ucap-webmessenger-electron/src/app/AppWindow.ts @@ -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 diff --git a/projects/ucap-webmessenger-app/src/app/services/notification.service.ts b/projects/ucap-webmessenger-app/src/app/services/notification.service.ts index dbec144a..a802dfe1 100644 --- a/projects/ucap-webmessenger-app/src/app/services/notification.service.ts +++ b/projects/ucap-webmessenger-app/src/app/services/notification.service.ts @@ -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; } diff --git a/projects/ucap-webmessenger-native-browser/src/lib/services/browser-native.service.ts b/projects/ucap-webmessenger-native-browser/src/lib/services/browser-native.service.ts index 6fad45a1..dc284721 100644 --- a/projects/ucap-webmessenger-native-browser/src/lib/services/browser-native.service.ts +++ b/projects/ucap-webmessenger-native-browser/src/lib/services/browser-native.service.ts @@ -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 {} diff --git a/projects/ucap-webmessenger-native-electron/src/lib/services/electron-native.service.ts b/projects/ucap-webmessenger-native-electron/src/lib/services/electron-native.service.ts index abeea430..951fb55e 100644 --- a/projects/ucap-webmessenger-native-electron/src/lib/services/electron-native.service.ts +++ b/projects/ucap-webmessenger-native-electron/src/lib/services/electron-native.service.ts @@ -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 | null = null; private backgroundCheckForUpdates$: Observable | 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; + } + ); } } diff --git a/projects/ucap-webmessenger-native-electron/src/lib/types/channel.type.ts b/projects/ucap-webmessenger-native-electron/src/lib/types/channel.type.ts index 8201fec0..772b89d7 100644 --- a/projects/ucap-webmessenger-native-electron/src/lib/types/channel.type.ts +++ b/projects/ucap-webmessenger-native-electron/src/lib/types/channel.type.ts @@ -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 { diff --git a/projects/ucap-webmessenger-native/src/lib/services/native.service.ts b/projects/ucap-webmessenger-native/src/lib/services/native.service.ts index f31a7d25..e052a398 100644 --- a/projects/ucap-webmessenger-native/src/lib/services/native.service.ts +++ b/projects/ucap-webmessenger-native/src/lib/services/native.service.ts @@ -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; abstract appExit(): void; abstract appLogging(error: any): void;