From 5ec864d3109b7466f87f91d48372bda7167f80ad Mon Sep 17 00:00:00 2001 From: zhangyuming27 Date: Thu, 18 Sep 2025 17:27:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20IDE=E6=8E=A5=E5=8F=A3=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/entryability/EntryAbility.ets | 87 ++++++++++++------- 1 file changed, 57 insertions(+), 30 deletions(-) diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 34d025c..088817c 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -56,28 +56,39 @@ export default class EntryAbility extends UIAbility { let mailInfo: MailInfo = new MailInfo(undefined, undefined, undefined, undefined, undefined); this.distributedObject = distributedDataObject.create(this.context, mailInfo); // Add a data restored listener. - this.distributedObject.on('status', (sessionId: string, networkId: string, status: 'online' | 'offline' | 'restored') => { - Logger.info('EntryAbility', 'status changed ' + sessionId + ' ' + status + ' ' + networkId); - if (status === 'restored') { - if (!this.distributedObject) { - return; - } - AppStorage.setOrCreate('recipient', this.distributedObject['recipient']); - AppStorage.setOrCreate('sender', this.distributedObject['sender']); - AppStorage.setOrCreate('subject', this.distributedObject['subject']); - AppStorage.setOrCreate('emailContent', this.distributedObject['emailContent']); - AppStorage.setOrCreate('attachments', this.distributedObject['attachments']); - let attachments = this.distributedObject['attachments'] as commonType.Assets; - Logger.info('this.distributedObject[attachments] ' + JSON.stringify(this.distributedObject['attachments'])) - for (const attachment of attachments) { - this.fileCopy(attachment); + try { + this.distributedObject.on('status', (sessionId: string, networkId: string, status: 'online' | 'offline' | 'restored') => { + Logger.info('EntryAbility', 'status changed ' + sessionId + ' ' + status + ' ' + networkId); + if (status === 'restored') { + if (!this.distributedObject) { + return; + } + AppStorage.setOrCreate('recipient', this.distributedObject['recipient']); + AppStorage.setOrCreate('sender', this.distributedObject['sender']); + AppStorage.setOrCreate('subject', this.distributedObject['subject']); + AppStorage.setOrCreate('emailContent', this.distributedObject['emailContent']); + AppStorage.setOrCreate('attachments', this.distributedObject['attachments']); + let attachments = this.distributedObject['attachments'] as commonType.Assets; + Logger.info('this.distributedObject[attachments] ' + JSON.stringify(this.distributedObject['attachments'])) + for (const attachment of attachments) { + this.fileCopy(attachment); + } } - } - }); + }); + } catch (error) { + Logger.error('EntryAbility', 'distributedDataObject failed', `code ${(error as BusinessError).code}`); + } + let sessionId : string = want.parameters?.distributedSessionId as string; Logger.info('sessionId' + sessionId); - this.distributedObject.setSessionId(sessionId); - this.context.restoreWindowStage(new LocalStorage()); + this.distributedObject.setSessionId(sessionId).catch((error: Error) => { + Logger.error('EntryAbility', 'distributedDataObject set session ID failed', `code ${(error as BusinessError).code}`); + }); + try { + this.context.restoreWindowStage(new LocalStorage()); + } catch (error) { + Logger.error('EntryAbility', 'restore window stage failed', `code ${(error as BusinessError).code}`); + } } onWindowStageRestore(windowStage: window.WindowStage): void { @@ -113,7 +124,9 @@ export default class EntryAbility extends UIAbility { AppStorage.get('subject'), AppStorage.get('emailContent'), assets); let source = mailInfo.flatAssets(); this.distributedObject = distributedDataObject.create(this.context, source); - this.distributedObject.setSessionId(sessionId); + this.distributedObject.setSessionId(sessionId).catch((err: Error) => { + Logger.error('EntryAbility', 'Failed to set session Id, ', `Catch err: ${err}`); + }); await this.distributedObject.save(wantParam.targetDevice as string).then(() => { Logger.info('onContinue distributedObject save success'); }).catch((err: BusinessError) => { @@ -165,18 +178,32 @@ export default class EntryAbility extends UIAbility { * @returns */ private getAssetInfo(append: AppendixBean) { - let filePath = uiContext!.getHostContext()!.distributedFilesDir + '/' + append.fileName; - fileIo.statSync(filePath); - let uri: string = fileUri.getUriFromPath(filePath); - let stat = fileIo.statSync(filePath); let attachment: commonType.Asset = { - name: append.fileName, - uri: uri, - path: filePath, - createTime: stat.ctime.toString(), - modifyTime: stat.ctime.toString(), - size: stat.size.toString() + name: '', + uri: '', + path: '', + createTime: '', + modifyTime: '', + size: '' }; + let filePath = uiContext!.getHostContext()!.distributedFilesDir + '/' + append.fileName; + try { + fileIo.statSync(filePath); + let uri: string = fileUri.getUriFromPath(filePath); + let stat = fileIo.statSync(filePath); + attachment = { + name: append.fileName, + uri: uri, + path: filePath, + createTime: stat.ctime.toString(), + modifyTime: stat.ctime.toString(), + size: stat.size.toString() + }; + return attachment; + } catch (error) { + Logger.error('EntryAbility', 'obtain attribute failed', `code ${(error as BusinessError).code}`); + } + return attachment; } -- Gitee