diff --git a/electron-projects/ucap-webmessenger-electron/src/index.ts b/electron-projects/ucap-webmessenger-electron/src/index.ts index 6169024d..f963e4ee 100644 --- a/electron-projects/ucap-webmessenger-electron/src/index.ts +++ b/electron-projects/ucap-webmessenger-electron/src/index.ts @@ -439,6 +439,24 @@ ipcMain.on( } ); +ipcMain.on( + MessengerChannel.ChangeDownloadPath, + (event: IpcMainEvent, ...args: any[]) => { + const downloadPath = args[0] as string; + + if (!!downloadPath && downloadPath.length > 0) { + console.log('in electron', downloadPath); + + appStorage.downloadPath = downloadPath; + log.info('downloadPath is changed to ', appStorage.downloadPath); + + event.returnValue = appStorage.downloadPath; + } else { + event.returnValue = ''; + } + } +); + ipcMain.on( UpdaterChannel.StartCheckInstant, (event: IpcMainEvent, ...args: any[]) => { @@ -496,7 +514,11 @@ ipcMain.on( const fileName: string = args[1]; const mimeType: string = args[2]; let savePath: string = path.join( - !!args[3] ? args[3] : app.getPath('downloads'), + !!args[3] + ? args[3] + : !!appStorage.downloadPath + ? appStorage.downloadPath + : app.getPath('downloads'), fileName ); savePath = await FileUtil.uniqueFileName(savePath); diff --git a/electron-projects/ucap-webmessenger-electron/src/lib/storage.ts b/electron-projects/ucap-webmessenger-electron/src/lib/storage.ts index 4c3ce558..a0413e33 100644 --- a/electron-projects/ucap-webmessenger-electron/src/lib/storage.ts +++ b/electron-projects/ucap-webmessenger-electron/src/lib/storage.ts @@ -1,6 +1,8 @@ import ElectronStore from 'electron-store'; +import { app } from 'electron'; const STORE_KEY_STARTUPHIDEWINDOW = 'options.startupHideWindow'; +const STORE_KEY_DOWNLOADFOLDER = 'options.downloadPath'; export class Storage { private readonly store: ElectronStore; @@ -13,10 +15,14 @@ export class Storage { properties: { startupHideWindow: { type: 'boolean' + }, + downloadPath: { + type: 'string' } }, default: { - startupHideWindow: false + startupHideWindow: false, + downloadPath: app.getPath('downloads') } } }, @@ -31,4 +37,11 @@ export class Storage { set startupHideWindow(startupHideWindow: boolean) { this.store.set(STORE_KEY_STARTUPHIDEWINDOW, startupHideWindow); } + + get downloadPath(): string { + return this.store.get(STORE_KEY_DOWNLOADFOLDER, false); + } + set downloadPath(downloadPath: string) { + this.store.set(STORE_KEY_DOWNLOADFOLDER, downloadPath); + } } 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 79fb0782..d0770a2f 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 @@ -187,6 +187,10 @@ export class MessengerSettingsDialogComponent implements OnInit { ); } + if (oriSettings.chat.downloadPath !== modSettings.chat.downloadPath) { + this.nativeService.changeDownloadPath(modSettings.chat.downloadPath); + } + return modSettings; } } 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 1ac08dba..f4ca0f3f 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 @@ -90,6 +90,12 @@ export class BrowserNativeService extends NativeService { }); } + changeDownloadPath(downloadPath: string): Promise { + return new Promise((resolve, reject) => { + resolve(downloadPath); + }); + } + 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 9ba9182c..525472b4 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 @@ -147,6 +147,21 @@ export class ElectronNativeService implements NativeService { }); } + changeDownloadPath(downloadPath: string): Promise { + return new Promise((resolve, reject) => { + try { + resolve( + this.ipcRenderer.sendSync( + MessengerChannel.ChangeDownloadPath, + downloadPath + ) + ); + } 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 a02c57a0..5780a9ce 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 @@ -4,6 +4,7 @@ export enum MessengerChannel { ShowSetting = 'UCAP::messenger::showSetting', ChangeAutoLaunch = 'UCAP::messenger::changeAutoLaunch', ChangeStartupHideWindow = 'UCAP::messenger::changeStartupHideWindow', + ChangeDownloadPath = 'UCAP::messenger::changeDownloadPath', GetNetworkInfo = 'UCAP::messenger::getNetworkInfo' } 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 7bdcfe59..d5171bf8 100644 --- a/projects/ucap-webmessenger-native/src/lib/services/native.service.ts +++ b/projects/ucap-webmessenger-native/src/lib/services/native.service.ts @@ -30,6 +30,7 @@ export abstract class NativeService { abstract changeStartupHideWindow( startupHideWindow: boolean ): Promise; + abstract changeDownloadPath(downloadPath: string): Promise; abstract notify(noti: NotificationRequest): void; abstract closeAllNotify(): void; diff --git a/projects/ucap-webmessenger-ui-settings/src/lib/components/chat.component.ts b/projects/ucap-webmessenger-ui-settings/src/lib/components/chat.component.ts index 2148c2f4..8e55143e 100644 --- a/projects/ucap-webmessenger-ui-settings/src/lib/components/chat.component.ts +++ b/projects/ucap-webmessenger-ui-settings/src/lib/components/chat.component.ts @@ -41,7 +41,9 @@ export class ChatComponent implements OnInit { this._isNodeWebkit = this.enviromentsService.nodeWebkit(); } - ngOnInit() {} + ngOnInit() { + this.logger.debug('chat setting', this.setting); + } onSelectionChangeFontFamily(event: MatSelectChange) { this.emit({ ...this.setting, fontFamily: event.value }); @@ -56,7 +58,9 @@ export class ChatComponent implements OnInit { this.nativeService .selectDirectory() .then(path => { - this.emit({ ...this.setting, downloadPath: path }); + if (!!path && path.length > 0) { + this.emit({ ...this.setting, downloadPath: path }); + } }) .catch(reason => {}); }