diff --git a/electron-projects/ucap-webmessenger-electron/src/index.ts b/electron-projects/ucap-webmessenger-electron/src/index.ts index b81617e2..334a3c3d 100644 --- a/electron-projects/ucap-webmessenger-electron/src/index.ts +++ b/electron-projects/ucap-webmessenger-electron/src/index.ts @@ -3,6 +3,8 @@ import path from 'path'; import fse from 'fs-extra'; import semver from 'semver'; +import AutoLaunch from 'auto-launch'; + import { AppWindow } from './app/AppWindow'; import { now } from './util/now'; import { showUncaughtException } from './crash/show-uncaught-exception'; @@ -93,6 +95,10 @@ let autoUpdaterCancellationToken: CancellationToken; autoUpdater.autoDownload = false; autoUpdater.logger = log; +const ucapMessengerLauncher = new AutoLaunch({ + name: app.getName() +}); + app.on(ElectronAppChannel.SecondInstance, (event, args, workingDirectory) => { // Someone tried to run a second instance, we should focus our window. if (appWindow) { @@ -339,6 +345,35 @@ ipcMain.on(UpdaterChannel.Check, (event: IpcMainEvent, ...args: any[]) => { } }); +ipcMain.on( + MessengerChannel.ChangeAutoLaunch, + (event: IpcMainEvent, ...args: any[]) => { + const isAutoLaunch = args[0] as boolean; + + if (isAutoLaunch) { + ucapMessengerLauncher + .enable() + .then(() => { + event.returnValue = true; + console.log('AutoLaunch is enabled'); + }) + .catch(reason => { + event.returnValue = false; + }); + } else { + ucapMessengerLauncher + .disable() + .then(() => { + event.returnValue = true; + console.log('AutoLaunch is disabled'); + }) + .catch(reason => { + event.returnValue = false; + }); + } + } +); + ipcMain.on( UpdaterChannel.StartCheckInstant, (event: IpcMainEvent, ...args: any[]) => { diff --git a/package-lock.json b/package-lock.json index 76c804c8..3b643f54 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2270,6 +2270,12 @@ "integrity": "sha512-/+CRPXpBDpo2RK9C68N3b2cOvO0Cf5B9aPijHsoDQTHivnGSObdOF2BRQOYjojWTDy6nQvMjmqRXIxH55VjxxA==", "dev": true }, + "@types/auto-launch": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/@types/auto-launch/-/auto-launch-5.0.1.tgz", + "integrity": "sha512-+KQ+/koZ7sJXnf5cnCANofY6yXAdYJNEoVZEuWcwJfuWbUp9u6l09I7KhwD+ivU+cdz7JId4V5ukxscWtHdSuw==", + "dev": true + }, "@types/axios": { "version": "0.14.0", "resolved": "https://registry.npmjs.org/@types/axios/-/axios-0.14.0.tgz", @@ -2974,6 +2980,11 @@ "default-require-extensions": "^2.0.0" } }, + "applescript": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/applescript/-/applescript-1.0.0.tgz", + "integrity": "sha1-u4evVoytA0pOSMS9r2Bno6JwExc=" + }, "aproba": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz", @@ -3156,6 +3167,18 @@ "integrity": "sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==", "dev": true }, + "auto-launch": { + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/auto-launch/-/auto-launch-5.0.5.tgz", + "integrity": "sha512-ppdF4mihhYzMYLuCcx9H/c5TUOCev8uM7en53zWVQhyYAJrurd2bFZx3qQVeJKF2jrc7rsPRNN5cD+i23l6PdA==", + "requires": { + "applescript": "^1.0.0", + "mkdirp": "^0.5.1", + "path-is-absolute": "^1.0.0", + "untildify": "^3.0.2", + "winreg": "1.2.4" + } + }, "autolinker": { "version": "3.11.1", "resolved": "https://registry.npmjs.org/autolinker/-/autolinker-3.11.1.tgz", @@ -11215,8 +11238,7 @@ "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", - "dev": true + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" }, "path-is-inside": { "version": "1.0.2", @@ -14408,6 +14430,11 @@ } } }, + "untildify": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/untildify/-/untildify-3.0.3.tgz", + "integrity": "sha512-iSk/J8efr8uPT/Z4eSUywnqyrQU7DSdMfdqK4iWEaUVVmcP5JcnpRqmVMwcwcnmI1ATFNgC5V90u09tBynNFKA==" + }, "upath": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/upath/-/upath-1.2.0.tgz", @@ -16425,6 +16452,11 @@ "string-width": "^2.1.1" } }, + "winreg": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/winreg/-/winreg-1.2.4.tgz", + "integrity": "sha1-ugZWKbepJRMOFXeRCM9UCZDpjRs=" + }, "wordwrap": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz", diff --git a/package.json b/package.json index 24c40d49..dcdfb80d 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "private": true, "dependencies": { "@angular/core": "~8.2.12", + "auto-launch": "^5.0.5", "electron-log": "^3.0.9", "electron-updater": "^4.2.0", "electron-window-state": "^5.0.3", @@ -67,6 +68,7 @@ "@ngrx/store": "^8.4.0", "@ngrx/store-devtools": "^8.4.0", "@ngx-translate/core": "^11.0.1", + "@types/auto-launch": "^5.0.1", "@types/axios": "^0.14.0", "@types/copy-webpack-plugin": "^5.0.0", "@types/crypto-js": "^3.1.43", diff --git a/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/settings/messenger-settings.dialog.component.ts b/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/settings/messenger-settings.dialog.component.ts index 9ba29dd6..21168bc8 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/settings/messenger-settings.dialog.component.ts +++ b/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/settings/messenger-settings.dialog.component.ts @@ -23,6 +23,7 @@ import { Settings, NotificationSetting } from '@ucap-webmessenger/ui-settings'; +import { NativeService, UCAP_NATIVE_SERVICE } from '@ucap-webmessenger/native'; export interface MessengerSettingsDialogData {} @@ -48,6 +49,7 @@ export class MessengerSettingsDialogComponent implements OnInit { private sessionStorageService: SessionStorageService, private localStorageService: LocalStorageService, private ucapTranslateService: UCapTranslateService, + @Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService, private store: Store, @Inject(DOCUMENT) private document: Document, private renderer2: Renderer2 @@ -82,6 +84,10 @@ export class MessengerSettingsDialogComponent implements OnInit { ) { this.ucapTranslateService.use(setting.hrInfoLocale); } + if (this.appUserInfo.settings.general.autoLaunch !== setting.autoLaunch) { + this.nativeService.changeAutoLaunch(setting.autoLaunch); + } + this.applySettings({ ...this.appUserInfo.settings, general: setting }); } diff --git a/projects/ucap-webmessenger-app/src/environments/environment.daesang.dev.ts b/projects/ucap-webmessenger-app/src/environments/environment.daesang.dev.ts index 34fe09f6..e26a38dd 100644 --- a/projects/ucap-webmessenger-app/src/environments/environment.daesang.dev.ts +++ b/projects/ucap-webmessenger-app/src/environments/environment.daesang.dev.ts @@ -40,7 +40,7 @@ export const environment: Environment = { general: { appTheme: 'theme-default', autoLogin: false, - autoStart: true, + autoLaunch: true, continueRunWhenClose: true, locale: 'ko', hrInfoLocale: 'ko', diff --git a/projects/ucap-webmessenger-app/src/environments/environment.daesang.prod.ts b/projects/ucap-webmessenger-app/src/environments/environment.daesang.prod.ts index 7e936e74..a9f86eb7 100644 --- a/projects/ucap-webmessenger-app/src/environments/environment.daesang.prod.ts +++ b/projects/ucap-webmessenger-app/src/environments/environment.daesang.prod.ts @@ -40,7 +40,7 @@ export const environment: Environment = { general: { appTheme: 'theme-default', autoLogin: false, - autoStart: true, + autoLaunch: true, continueRunWhenClose: true, locale: 'ko', hrInfoLocale: 'ko', diff --git a/projects/ucap-webmessenger-app/src/environments/environment.dev.ts b/projects/ucap-webmessenger-app/src/environments/environment.dev.ts index 01aab1f6..2ba18fb5 100644 --- a/projects/ucap-webmessenger-app/src/environments/environment.dev.ts +++ b/projects/ucap-webmessenger-app/src/environments/environment.dev.ts @@ -40,7 +40,7 @@ export const environment: Environment = { general: { appTheme: 'theme-default', autoLogin: false, - autoStart: true, + autoLaunch: true, continueRunWhenClose: true, locale: 'ko', hrInfoLocale: 'ko', diff --git a/projects/ucap-webmessenger-app/src/environments/environment.prod.ts b/projects/ucap-webmessenger-app/src/environments/environment.prod.ts index da298dcb..eb6f9934 100644 --- a/projects/ucap-webmessenger-app/src/environments/environment.prod.ts +++ b/projects/ucap-webmessenger-app/src/environments/environment.prod.ts @@ -40,7 +40,7 @@ export const environment: Environment = { general: { appTheme: 'theme-default', autoLogin: false, - autoStart: true, + autoLaunch: true, continueRunWhenClose: true, locale: 'ko', hrInfoLocale: 'ko', 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 c4bf9ec0..078b142a 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 @@ -62,6 +62,12 @@ export class BrowserNativeService extends NativeService { }); } + changeAutoLaunch(autoLaunch: boolean): Promise { + return new Promise((resolve, reject) => { + resolve(true); + }); + } + notify(noti: NotificationRequest): void { this.notificationService.notify(noti, () => { window.focus(); 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 9d4dbe6f..05dd13c0 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 @@ -97,6 +97,21 @@ export class ElectronNativeService implements NativeService { return this.showSetting$; } + changeAutoLaunch(autoLaunch: boolean): Promise { + return new Promise((resolve, reject) => { + try { + resolve( + this.ipcRenderer.sendSync( + MessengerChannel.ChangeAutoLaunch, + autoLaunch + ) + ); + } catch (error) { + reject(error); + } + }); + } + notify(noti: NotificationRequest): void { this.ipcRenderer.send(NotificationChannel.Notify, noti); } 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 23d95c86..6bc3be7d 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 @@ -1,7 +1,8 @@ export enum MessengerChannel { Logout = 'UCAP::messenger::logout', ChangeStatus = 'UCAP::messenger::changeStatus', - ShowSetting = 'UCAP::messenger::showSetting' + ShowSetting = 'UCAP::messenger::showSetting', + ChangeAutoLaunch = 'UCAP::messenger::changeAutoLaunch' } export enum ChatChannel { 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 21459187..7c36af6e 100644 --- a/projects/ucap-webmessenger-native/src/lib/services/native.service.ts +++ b/projects/ucap-webmessenger-native/src/lib/services/native.service.ts @@ -14,6 +14,8 @@ export abstract class NativeService { abstract changeStatus(): Observable; abstract showSetting(): Observable; + abstract changeAutoLaunch(autoLaunch: boolean): Promise; + abstract notify(noti: NotificationRequest): void; abstract closeAllNotify(): void; diff --git a/projects/ucap-webmessenger-ui-settings/src/lib/components/general.component.html b/projects/ucap-webmessenger-ui-settings/src/lib/components/general.component.html index a658431d..4414efa2 100644 --- a/projects/ucap-webmessenger-ui-settings/src/lib/components/general.component.html +++ b/projects/ucap-webmessenger-ui-settings/src/lib/components/general.component.html @@ -40,25 +40,25 @@

응용 프로그램

응용 프로그램 자동 시작Windows 실행 시 자동 실행 백그라운드에서 응용 프로그램 열기실행 시 창 숨기기 - + diff --git a/projects/ucap-webmessenger-ui-settings/src/lib/components/general.component.ts b/projects/ucap-webmessenger-ui-settings/src/lib/components/general.component.ts index a89d8f9c..0787b678 100644 --- a/projects/ucap-webmessenger-ui-settings/src/lib/components/general.component.ts +++ b/projects/ucap-webmessenger-ui-settings/src/lib/components/general.component.ts @@ -65,7 +65,7 @@ export class GeneralComponent implements OnInit { } onChangeAutoStart(event: MatCheckboxChange) { - this.emit({ ...this.setting, autoStart: event.checked }); + this.emit({ ...this.setting, autoLaunch: event.checked }); } onChangeStartBackgroudMode(event: MatCheckboxChange) { this.emit({ ...this.setting, startBackgroudMode: event.checked }); diff --git a/projects/ucap-webmessenger-ui-settings/src/lib/models/settings.ts b/projects/ucap-webmessenger-ui-settings/src/lib/models/settings.ts index b5ca9e4c..6e1cdba7 100644 --- a/projects/ucap-webmessenger-ui-settings/src/lib/models/settings.ts +++ b/projects/ucap-webmessenger-ui-settings/src/lib/models/settings.ts @@ -1,6 +1,6 @@ export interface GeneralSetting { appTheme: string; - autoStart: boolean; + autoLaunch: boolean; startBackgroudMode: boolean; continueRunWhenClose: boolean; autoLogin: boolean;