From 2ee24288922584506b4d1ee251d7810da9fd06ea Mon Sep 17 00:00:00 2001 From: liujiahui Date: Tue, 19 Aug 2025 15:22:32 +0800 Subject: [PATCH 01/18] =?UTF-8?q?imp:=E4=BF=AE=E6=94=B9=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/view/RemoteFileList.ets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entry/src/main/ets/view/RemoteFileList.ets b/entry/src/main/ets/view/RemoteFileList.ets index aaa0ba9..9dcd040 100644 --- a/entry/src/main/ets/view/RemoteFileList.ets +++ b/entry/src/main/ets/view/RemoteFileList.ets @@ -103,7 +103,7 @@ export struct RemoteFileList { }; // Start cross device file access - await fs.connectDfs(this.networkId, listeners).then(async () => { + fs.connectDfs(this.networkId, listeners).then(async () => { this.pathDir = this.context.distributedFilesDir; this.remoteFileListArr = await fs.listFile(this.pathDir); -- Gitee From b34ba1331819d5b8c870b4ed50f431b42e495ff6 Mon Sep 17 00:00:00 2001 From: liujiahui Date: Tue, 19 Aug 2025 15:33:19 +0800 Subject: [PATCH 02/18] =?UTF-8?q?imp:=E6=B7=BB=E5=8A=A0=E5=90=8C=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/pages/Index.ets | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 08408bd..4a58801 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -12,18 +12,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +// [Start common] import { common } from '@kit.AbilityKit'; +// [End common] +// [StartExclude common] +// [Start import_file] import { fileIo as fs } from '@kit.CoreFileKit'; +// [End import_file] import CommonUtils from '../utils/CommonUtils'; import { hilog } from '@kit.PerformanceAnalysisKit'; +// [EndExclude common] + @Entry @Component struct Index { + // [StartExclude common] @Provide('pageInfo') pageStack: NavPathStack = new NavPathStack(); @Provide('isDeleteChange') isDeleteChange: boolean = false; @State uiContext: UIContext | undefined = AppStorage.get('uiContext'); + // [EndExclude common] @State context: Context = this.getUIContext().getHostContext() as common.UIAbilityContext; + // [StartExclude common] @State fileTile: string = ''; @State fileContent: string = ''; @@ -173,4 +183,5 @@ struct Index { .height('100%') .width('100%') } + // [EndExclude common] } \ No newline at end of file -- Gitee From 13da5c67fc3cc4110c3fc3559f615ee47e146ec1 Mon Sep 17 00:00:00 2001 From: liujiahui Date: Tue, 19 Aug 2025 15:35:30 +0800 Subject: [PATCH 03/18] =?UTF-8?q?imp:=E6=B7=BB=E5=8A=A0=E5=90=8C=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/pages/Index.ets | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 4a58801..06d64a0 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -12,28 +12,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -// [Start common] +// [Start import_common] import { common } from '@kit.AbilityKit'; -// [End common] -// [StartExclude common] +// [End import_common] +// [StartExclude import_common] // [Start import_file] import { fileIo as fs } from '@kit.CoreFileKit'; // [End import_file] import CommonUtils from '../utils/CommonUtils'; import { hilog } from '@kit.PerformanceAnalysisKit'; -// [EndExclude common] +// [EndExclude import_common] @Entry @Component struct Index { - // [StartExclude common] + // [StartExclude import_common] @Provide('pageInfo') pageStack: NavPathStack = new NavPathStack(); @Provide('isDeleteChange') isDeleteChange: boolean = false; @State uiContext: UIContext | undefined = AppStorage.get('uiContext'); - // [EndExclude common] + // [EndExclude import_common] @State context: Context = this.getUIContext().getHostContext() as common.UIAbilityContext; - // [StartExclude common] + // [StartExclude import_common] @State fileTile: string = ''; @State fileContent: string = ''; @@ -183,5 +183,5 @@ struct Index { .height('100%') .width('100%') } - // [EndExclude common] + // [EndExclude import_common] } \ No newline at end of file -- Gitee From 52e8a42a94c53dac5946153c20e5740339cf5a54 Mon Sep 17 00:00:00 2001 From: liujiahui Date: Tue, 19 Aug 2025 15:36:52 +0800 Subject: [PATCH 04/18] =?UTF-8?q?imp:=E6=B7=BB=E5=8A=A0=E5=90=8C=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/pages/Index.ets | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 06d64a0..3d9bc10 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -14,11 +14,11 @@ */ // [Start import_common] import { common } from '@kit.AbilityKit'; -// [End import_common] + // [StartExclude import_common] // [Start import_file] import { fileIo as fs } from '@kit.CoreFileKit'; -// [End import_file] + import CommonUtils from '../utils/CommonUtils'; import { hilog } from '@kit.PerformanceAnalysisKit'; @@ -183,5 +183,9 @@ struct Index { .height('100%') .width('100%') } + // [EndExclude import_common] -} \ No newline at end of file +} + +// [End import_common] +// [End import_file] \ No newline at end of file -- Gitee From 148765739f9c6e7898dd079f58f82de92cf97fd4 Mon Sep 17 00:00:00 2001 From: liujiahui Date: Tue, 19 Aug 2025 15:38:55 +0800 Subject: [PATCH 05/18] =?UTF-8?q?imp:=E6=B7=BB=E5=8A=A0=E5=90=8C=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/pages/Index.ets | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 3d9bc10..bf9e7e2 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -18,16 +18,18 @@ import { common } from '@kit.AbilityKit'; // [StartExclude import_common] // [Start import_file] import { fileIo as fs } from '@kit.CoreFileKit'; - +// [StartExclude import_file] import CommonUtils from '../utils/CommonUtils'; import { hilog } from '@kit.PerformanceAnalysisKit'; // [EndExclude import_common] +// [EndExclude import_file] @Entry @Component struct Index { // [StartExclude import_common] + // [StartExclude import_file] @Provide('pageInfo') pageStack: NavPathStack = new NavPathStack(); @Provide('isDeleteChange') isDeleteChange: boolean = false; @State uiContext: UIContext | undefined = AppStorage.get('uiContext'); @@ -36,14 +38,18 @@ struct Index { // [StartExclude import_common] @State fileTile: string = ''; @State fileContent: string = ''; + // [EndExclude import_file] createFile() { + // [StartExclude import_file] if (this.fileTile === '' && this.fileContent === '') { CommonUtils.showToast($r('app.string.file_name_and_file_content_cannot_be_empty'), this.uiContext!); return; } + // [EndExclude import_file] // Get the file path of the distributed directory let pathDir: string = this.context.distributedFilesDir; + // [StartExclude import_file] let filePath: string = pathDir + `/${this.fileTile}.txt`; try { // Create files in a distributed directory @@ -60,8 +66,10 @@ struct Index { hilog.error(0x0000, 'Index', '%{public}s', 'Failed to openSync / writeSync / closeSync. Code: $\{error.code}, message: $\{error.message}'); } + // [EndExclude import_file] } + // [StartExclude import_file] clear() { this.fileTile = ''; this.fileContent = ''; @@ -185,6 +193,7 @@ struct Index { } // [EndExclude import_common] + // [EndExclude import_file] } // [End import_common] -- Gitee From 4cc1352755e302f71390e4d511f49408bac829fa Mon Sep 17 00:00:00 2001 From: liujiahui Date: Tue, 19 Aug 2025 15:42:13 +0800 Subject: [PATCH 06/18] =?UTF-8?q?imp:=E6=B7=BB=E5=8A=A0=E5=90=8C=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/pages/Index.ets | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index bf9e7e2..66d0e39 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -25,10 +25,12 @@ import { hilog } from '@kit.PerformanceAnalysisKit'; // [EndExclude import_common] // [EndExclude import_file] +// [Start create_file] @Entry @Component struct Index { // [StartExclude import_common] + // [StartExclude create_file] // [StartExclude import_file] @Provide('pageInfo') pageStack: NavPathStack = new NavPathStack(); @Provide('isDeleteChange') isDeleteChange: boolean = false; @@ -39,9 +41,11 @@ struct Index { @State fileTile: string = ''; @State fileContent: string = ''; // [EndExclude import_file] + // [EndExclude create_file] createFile() { // [StartExclude import_file] + // [StartExclude create_file] if (this.fileTile === '' && this.fileContent === '') { CommonUtils.showToast($r('app.string.file_name_and_file_content_cannot_be_empty'), this.uiContext!); return; @@ -49,6 +53,7 @@ struct Index { // [EndExclude import_file] // Get the file path of the distributed directory let pathDir: string = this.context.distributedFilesDir; + // [EndExclude create_file] // [StartExclude import_file] let filePath: string = pathDir + `/${this.fileTile}.txt`; try { @@ -59,9 +64,11 @@ struct Index { fs.writeSync(file.fd, this.fileContent); // close file fs.closeSync(file.fd); + // [StartExclude create_file] CommonUtils.showToast($r('app.string.created_successfully'), this.uiContext!); this.fileTile = ''; this.fileContent = ''; + // [EndExclude create_file] } catch (error) { hilog.error(0x0000, 'Index', '%{public}s', 'Failed to openSync / writeSync / closeSync. Code: $\{error.code}, message: $\{error.message}'); @@ -69,6 +76,7 @@ struct Index { // [EndExclude import_file] } + // [StartExclude create_file] // [StartExclude import_file] clear() { this.fileTile = ''; @@ -194,7 +202,9 @@ struct Index { // [EndExclude import_common] // [EndExclude import_file] + // [EndExclude create_file] } // [End import_common] -// [End import_file] \ No newline at end of file +// [End import_file] +// [End create_file] \ No newline at end of file -- Gitee From 7f8b5594f6398498dd5667f8f64a87966c105e89 Mon Sep 17 00:00:00 2001 From: liujiahui Date: Tue, 19 Aug 2025 15:45:36 +0800 Subject: [PATCH 07/18] =?UTF-8?q?imp:=E6=B7=BB=E5=8A=A0=E5=90=8C=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/view/RemoteFileList.ets | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/entry/src/main/ets/view/RemoteFileList.ets b/entry/src/main/ets/view/RemoteFileList.ets index 9dcd040..e2fd868 100644 --- a/entry/src/main/ets/view/RemoteFileList.ets +++ b/entry/src/main/ets/view/RemoteFileList.ets @@ -30,8 +30,10 @@ export function RemoteFileListBuild() { RemoteFileList(); } +// [Start getRemoteFileList] @Component export struct RemoteFileList { + // [StartExclude getRemoteFileList] @Consume('pageInfo') pageStack: NavPathStack; @State uiContext: UIContext | undefined = AppStorage.get('uiContext'); @State context: Context = this.getUIContext().getHostContext() as common.UIAbilityContext; @@ -86,6 +88,7 @@ export struct RemoteFileList { `Failed to disconnect dfs. Code: ${err.code}, message: ${err.message}`); }); } + // [EndExclude getRemoteFileList] // Retrieve the file list in the remote distributed directory async getRemoteFileList() { @@ -127,6 +130,7 @@ export struct RemoteFileList { } } + // [StartExclude getRemoteFileList] // Copy files copyFile() { if (!this.selectedValue) { @@ -177,7 +181,9 @@ export struct RemoteFileList { } } + // [EndExclude getRemoteFileList] build() { + // [StartExclude getRemoteFileList] NavDestination() { Column({ space: 12 }) { EditTitleBar({ @@ -315,5 +321,7 @@ export struct RemoteFileList { .systemTransition(NavigationSystemTransitionType.SLIDE_RIGHT) .title(this.isEdit ? $r('app.string.edit') : $r('app.string.remote_file')) .hideTitleBar(true) + // [EndExclude getRemoteFileList] } -} \ No newline at end of file +} +// [End getRemoteFileList] \ No newline at end of file -- Gitee From 981523ef100d65d1d193a2d303b4313e626ff0d4 Mon Sep 17 00:00:00 2001 From: liujiahui Date: Tue, 19 Aug 2025 15:51:06 +0800 Subject: [PATCH 08/18] =?UTF-8?q?imp:=E6=B7=BB=E5=8A=A0=E5=90=8C=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/view/Preview.ets | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/entry/src/main/ets/view/Preview.ets b/entry/src/main/ets/view/Preview.ets index 0a7c814..7c78db5 100644 --- a/entry/src/main/ets/view/Preview.ets +++ b/entry/src/main/ets/view/Preview.ets @@ -27,8 +27,10 @@ export function PreviewBuild() { } +// [Start preview] @Component export struct Preview { + // [StartExclude preview] @State uiContext: UIContext | undefined = AppStorage.get('uiContext'); @Consume('pageInfo') pageStack: NavPathStack; controller: TextInputController = new TextInputController(); @@ -39,23 +41,29 @@ export struct Preview { @State isEdit: boolean = false; @Consume('isDeleteChange') isDeleteChange: boolean; + // [EndExclude preview] + aboutToAppear(): void { const param = this.pageStack.getParamByName('Preview')[0] as Param; - this.fileTile = param.fileName; - this.filePath = param.path; - this.targetPath = this.filePath + `/${this.fileTile}`; + this.fileTile = param.fileName; // Incoming file name + this.filePath = param.path; // The corresponding file sandbox path passed in + this.targetPath = this.filePath + `/${this.fileTile}`; //Splicing into the file path to be read try { - this.fileContent = fs.readTextSync(this.targetPath); + this.fileContent = fs.readTextSync(this.targetPath); //Read the file, fileContent is the content of the read file } catch (error) { hilog.error(0xFF00, 'error', '%{public}s', 'have errors', `${JSON.stringify(error)}`); } } + // [StartExclude preview] stopEdit() { this.controller.stopEditing(); } + // [EndExclude preview] + build() { + // [StartExclude preview] NavDestination() { Column({ space: 12 }) { TitleBar({ @@ -109,5 +117,9 @@ export struct Preview { .justifyContent(FlexAlign.Start) } .hideTitleBar(true) + + // [EndExclude preview] } } + +// [End preview] -- Gitee From 7c614d535e4ac89b0170d81dadd6ac7db0ee0f5c Mon Sep 17 00:00:00 2001 From: liujiahui Date: Tue, 19 Aug 2025 15:58:52 +0800 Subject: [PATCH 09/18] =?UTF-8?q?imp:=E6=B7=BB=E5=8A=A0=E5=90=8C=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/components/TitleBar.ets | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/entry/src/main/ets/components/TitleBar.ets b/entry/src/main/ets/components/TitleBar.ets index 97817a7..58f7a38 100644 --- a/entry/src/main/ets/components/TitleBar.ets +++ b/entry/src/main/ets/components/TitleBar.ets @@ -17,8 +17,10 @@ import CommonUtils from '../utils/CommonUtils'; import { TitleBarDeleteDialog } from './TitleBarDeleteDialog'; import { hilog } from '@kit.PerformanceAnalysisKit'; +// [Start save_file] @Component export struct TitleBar { + // [StartExclude save_file] @State uiContext: UIContext | undefined = AppStorage.get('uiContext'); @Consume('pageInfo') pageStack: NavPathStack; @Link isEdit: boolean; @@ -50,21 +52,25 @@ export struct TitleBar { this.oldFileContent = this.fileContent; } + // [EndExclude save_file] + saveFile() { try { const file = fs.openSync(this.filePath + `/${this.fileTile}`, - fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE | fs.OpenMode.TRUNC); + fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE | fs.OpenMode.TRUNC); // Open files in read-write mode const writeOptions: WriteOptions = { offset: 0, // Key point: Reset write position length: this.fileContent.length }; - let writeLen = fs.writeSync(file.fd, this.fileContent, writeOptions); + let writeLen = fs.writeSync(file.fd, this.fileContent, writeOptions); // write file fs.fsyncSync(file.fd); if (writeLen) { - fs.closeSync(file); + fs.closeSync(file); // close file CommonUtils.showToast($r('app.string.successfully_saved'), this.uiContext!); - this.pageStack.pop(); + this.pageStack.pop(); // Back to previous level + // [StartExclude save_file] this.isDeleteChange = !this.isDeleteChange; + // [EndExclude save_file] } } catch (error) { hilog.error(0xFF00, 'error', '%{public}s', 'have errors', `${JSON.stringify(error)}`); @@ -72,6 +78,7 @@ export struct TitleBar { } build() { + // [StartExclude save_file] Row() { Row() { Row() { @@ -146,5 +153,9 @@ export struct TitleBar { } .width('100%') .justifyContent(FlexAlign.SpaceBetween) + + // [EndExclude save_file] } -} \ No newline at end of file +} + +// [End save_file] \ No newline at end of file -- Gitee From b274f002e3f3b1d8c3b562741b8b9cbba8b3e2e1 Mon Sep 17 00:00:00 2001 From: liujiahui Date: Tue, 19 Aug 2025 16:01:02 +0800 Subject: [PATCH 10/18] =?UTF-8?q?imp:=E6=B7=BB=E5=8A=A0=E5=90=8C=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/utils/CommonUtils.ets | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/entry/src/main/ets/utils/CommonUtils.ets b/entry/src/main/ets/utils/CommonUtils.ets index 7011650..b594ac5 100644 --- a/entry/src/main/ets/utils/CommonUtils.ets +++ b/entry/src/main/ets/utils/CommonUtils.ets @@ -16,7 +16,9 @@ import { hilog } from "@kit.PerformanceAnalysisKit"; import { fileIo as fs } from '@kit.CoreFileKit'; import { BusinessError } from "@kit.BasicServicesKit"; +// [Start delete_file] class CommonUtils { + // [StartExclude delete_file] public showToast(message: ResourceStr, uiContext: UIContext) { try { uiContext.getPromptAction().showToast({ message }); @@ -24,6 +26,7 @@ class CommonUtils { hilog.error(0xFF00, 'error', '%{public}s', 'have errors', `${JSON.stringify(error)}`); } }; + // [EndExclude delete_file] public delete(selectedValue: string, pathDir: string, uiContext: UIContext, callback: (result: boolean) => void) { const srcUri = pathDir + `/${selectedValue}`; @@ -41,3 +44,4 @@ class CommonUtils { } export default new CommonUtils(); +// [End delete_file] -- Gitee From 716d24338e3af9ef1baea9a265436d49ace3a71f Mon Sep 17 00:00:00 2001 From: liujiahui Date: Tue, 19 Aug 2025 16:02:48 +0800 Subject: [PATCH 11/18] =?UTF-8?q?imp:=E6=B7=BB=E5=8A=A0=E5=90=8C=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/utils/CommonUtils.ets | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/entry/src/main/ets/utils/CommonUtils.ets b/entry/src/main/ets/utils/CommonUtils.ets index b594ac5..64af4a7 100644 --- a/entry/src/main/ets/utils/CommonUtils.ets +++ b/entry/src/main/ets/utils/CommonUtils.ets @@ -26,10 +26,11 @@ class CommonUtils { hilog.error(0xFF00, 'error', '%{public}s', 'have errors', `${JSON.stringify(error)}`); } }; + // [EndExclude delete_file] public delete(selectedValue: string, pathDir: string, uiContext: UIContext, callback: (result: boolean) => void) { - const srcUri = pathDir + `/${selectedValue}`; + const srcUri = pathDir + `/${selectedValue}`; // Splicing the sandbox path of the required file fs.unlink(srcUri, (err: BusinessError) => { if (err) { hilog.error(0x0000, 'RemoteFile', '%{public}s', @@ -44,4 +45,5 @@ class CommonUtils { } export default new CommonUtils(); + // [End delete_file] -- Gitee From c943d2a776805eb21647f766ba48e4dc3c3d00a1 Mon Sep 17 00:00:00 2001 From: liujiahui Date: Tue, 19 Aug 2025 16:06:08 +0800 Subject: [PATCH 12/18] =?UTF-8?q?imp:=E6=B7=BB=E5=8A=A0=E5=90=8C=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/view/RemoteFileList.ets | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/entry/src/main/ets/view/RemoteFileList.ets b/entry/src/main/ets/view/RemoteFileList.ets index e2fd868..d0aa837 100644 --- a/entry/src/main/ets/view/RemoteFileList.ets +++ b/entry/src/main/ets/view/RemoteFileList.ets @@ -31,9 +31,11 @@ export function RemoteFileListBuild() { } // [Start getRemoteFileList] +// [Start copy_file] @Component export struct RemoteFileList { // [StartExclude getRemoteFileList] + // [StartExclude copy_file] @Consume('pageInfo') pageStack: NavPathStack; @State uiContext: UIContext | undefined = AppStorage.get('uiContext'); @State context: Context = this.getUIContext().getHostContext() as common.UIAbilityContext; @@ -88,6 +90,7 @@ export struct RemoteFileList { `Failed to disconnect dfs. Code: ${err.code}, message: ${err.message}`); }); } + // [EndExclude getRemoteFileList] // Retrieve the file list in the remote distributed directory @@ -130,6 +133,8 @@ export struct RemoteFileList { } } + // [EndExclude copy_file] + // [StartExclude getRemoteFileList] // Copy files copyFile() { @@ -137,12 +142,12 @@ export struct RemoteFileList { CommonUtils.showToast($r('app.string.Please_select_a_file'), this.uiContext!); } else { this.ProgressDialog.open(); - const srcUri = fileUri.getUriFromPath(this.pathDir + `/${this.selectedValue}`); - const destUri = fileUri.getUriFromPath(this.context.filesDir + `/${this.selectedValue}`); + const srcUri = fileUri.getUriFromPath(this.pathDir + `/${this.selectedValue}`); // To copy file path + const destUri = fileUri.getUriFromPath(this.context.filesDir + `/${this.selectedValue}`); // Target file path let progressListener: fs.ProgressListener = (progress: fs.Progress) => { - this.value = progress.processedSize; - this.total = progress.totalSize; + this.value = progress.processedSize; // Copy file size + this.total = progress.totalSize; // Total size of copied files if ((this.value / this.total * 100) > 99) { CommonUtils.showToast($r('app.string.Success_copy'), this.uiContext!); this.ProgressDialog.close(); @@ -165,6 +170,7 @@ export struct RemoteFileList { } } } + // [StartExclude copy_file] delete() { if (!this.selectedValue) { @@ -182,8 +188,10 @@ export struct RemoteFileList { } // [EndExclude getRemoteFileList] + // [EndExclude copy_file] build() { // [StartExclude getRemoteFileList] + // [StartExclude copy_file] NavDestination() { Column({ space: 12 }) { EditTitleBar({ @@ -321,7 +329,11 @@ export struct RemoteFileList { .systemTransition(NavigationSystemTransitionType.SLIDE_RIGHT) .title(this.isEdit ? $r('app.string.edit') : $r('app.string.remote_file')) .hideTitleBar(true) + // [EndExclude getRemoteFileList] + // [EndExclude copy_file] } } -// [End getRemoteFileList] \ No newline at end of file + +// [End getRemoteFileList] +// [End copy_file] \ No newline at end of file -- Gitee From 96bb559c94d6b463b0b34608dfdc2ead72abe5e9 Mon Sep 17 00:00:00 2001 From: liujiahui Date: Tue, 19 Aug 2025 16:07:33 +0800 Subject: [PATCH 13/18] =?UTF-8?q?imp:=E6=B7=BB=E5=8A=A0=E5=90=8C=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/view/RemoteFileList.ets | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/entry/src/main/ets/view/RemoteFileList.ets b/entry/src/main/ets/view/RemoteFileList.ets index d0aa837..41015bb 100644 --- a/entry/src/main/ets/view/RemoteFileList.ets +++ b/entry/src/main/ets/view/RemoteFileList.ets @@ -161,7 +161,7 @@ export struct RemoteFileList { fs.copy(srcUri, destUri, copyOption).then(() => { hilog.info(0x0000, 'RemoteFile', '%{public}s', 'Success to copy.'); }).catch((err: BusinessError) => { - hilog.error(0x0000, 'RemoteFile', '%{public}s', `Failed to copy. Code: ${err.code}, message: ${err.message}`); + hilog.error(0x0000, 'RemoteFile', `Failed to copy.Code:${err.code},message: ${err.message}`); }); } catch (err) { hilog.error(0x0000, 'RemoteFile', '%{public}s', @@ -170,6 +170,7 @@ export struct RemoteFileList { } } } + // [StartExclude copy_file] delete() { -- Gitee From 551c038b881fc79c291d4493c4e0c2b981a5686b Mon Sep 17 00:00:00 2001 From: liujiahui Date: Tue, 19 Aug 2025 16:09:49 +0800 Subject: [PATCH 14/18] =?UTF-8?q?imp:=E6=B7=BB=E5=8A=A0=E5=90=8C=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/view/LocalFileList.ets | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/entry/src/main/ets/view/LocalFileList.ets b/entry/src/main/ets/view/LocalFileList.ets index da5cf05..a133f1a 100644 --- a/entry/src/main/ets/view/LocalFileList.ets +++ b/entry/src/main/ets/view/LocalFileList.ets @@ -62,6 +62,7 @@ export struct LocalFileList { this.getFileList(); } + // [Start get_file] async getFileList() { this.isShowDialog = true; // Get the file path of the local directory @@ -72,14 +73,18 @@ export struct LocalFileList { } catch (error) { hilog.error(0xFF00, 'error', '%{public}s', 'have errors', `${JSON.stringify(error)}`); } + // [StartExclude get_file] if (this.localFileListArr.length > 0) { this.isShowDialog = false; } else { this.isEdit = false; this.isShowDialog = false; } + // [EndExclude get_file] } + // [End get_file] + delete() { if (!this.selectedValue) { CommonUtils.showToast($r('app.string.Please_select_a_file'), this.uiContext!); -- Gitee From 2c5b9ff458f7d0c55d1930a00405ca8d865abf3a Mon Sep 17 00:00:00 2001 From: liujihui <810520030@qq.com> Date: Thu, 21 Aug 2025 10:15:29 +0800 Subject: [PATCH 15/18] =?UTF-8?q?imp=EF=BC=9A=E5=8E=BB=E9=99=A4=E6=97=A0?= =?UTF-8?q?=E7=94=A8=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/view/LocalFileList.ets | 1 - 1 file changed, 1 deletion(-) diff --git a/entry/src/main/ets/view/LocalFileList.ets b/entry/src/main/ets/view/LocalFileList.ets index a133f1a..6834eeb 100644 --- a/entry/src/main/ets/view/LocalFileList.ets +++ b/entry/src/main/ets/view/LocalFileList.ets @@ -15,7 +15,6 @@ import { fileIo as fs } from '@kit.CoreFileKit'; import { common } from '@kit.AbilityKit'; import CommonUtils from '../utils/CommonUtils'; -import { BusinessError } from '@kit.BasicServicesKit'; import { ListComp } from '../components/ListComp'; import { Loading } from '../components/Loading'; import { EditTitleBar } from '../components/EditTitleBar'; -- Gitee From ea68fefc8a6c6b926cc286665fff73354f13ea13 Mon Sep 17 00:00:00 2001 From: liujiahui Date: Mon, 25 Aug 2025 19:34:30 +0800 Subject: [PATCH 16/18] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E6=94=B9=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.en.md | 8 +-- README.md | 16 ++--- entry/src/main/ets/components/TitleBar.ets | 6 +- .../main/ets/entryability/EntryAbility.ets | 9 ++- entry/src/main/ets/pages/Index.ets | 1 + entry/src/main/ets/view/RemoteFileList.ets | 63 ++++++++++++------- 6 files changed, 65 insertions(+), 38 deletions(-) diff --git a/README.en.md b/README.en.md index f92fdd9..337ccac 100644 --- a/README.en.md +++ b/README.en.md @@ -54,7 +54,7 @@ This example demonstrates how to access and copy files across multiple devices. ## Specific Implementation -1. Obtain the sandbox path of the current application's distributed shared directory using [getUIContext()](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/ts-custom-component-api#getuicontext)Then obtain [getHostContext()](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-arkui-uicontext#gethostcontext12) +1. Obtain the sandbox path of the current application's distributed shared directory using [getUIContext()](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/ts-custom-component-api#getuicontext)Then obtain [getHostContext()](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/arkts-apis-uicontext-uicontext#gethostcontext12) Subsequently, access the distributedFilesDir distributed shared directory. 2. Create files through [fs.openSync()](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-file-fs#fsopensync)Open files or directories using synchronization method, and then use [fs.riteSync()](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-file-fs#fswritesync )Write data to a file using a synchronous method, and finally use [fs.closeSync()](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-file-fs#fsclosesync)Close the file or directory using the synchronization method to create it successfully. 3. Access local files through [fs.listFile()](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-file-fs#fslistfile)List all files in the local filesDir sandbox path directory. @@ -75,8 +75,8 @@ This example demonstrates how to access and copy files across multiple devices. ## Constraints and limitations 1. This example only supports running on standard systems and supports devices such as Huawei phones. -2. HarmonyOS system: HarmonyOS 5.1.0 Release and above. -3. DevEco Studio version: DevEco Studio 5.1.0 Release and above. -4. HarmonyOS SDK version: HarmonyOS 5.1.0 Release SDK or above. +2. HarmonyOS system: HarmonyOS 5.1.1 Release and above. +3. DevEco Studio version: DevEco Studio 5.1.1 Release and above. +4. HarmonyOS SDK version: HarmonyOS 5.1.1 Release SDK or above. 5. Dual end devices need to log in to the same Huawei account. 6. Dual end devices require Wi Fi and Bluetooth switches to be turned on. When conditions permit, it is recommended that both devices be connected to the same local area network to improve data transmission speed. \ No newline at end of file diff --git a/README.md b/README.md index a0a3829..c813808 100644 --- a/README.md +++ b/README.md @@ -10,14 +10,14 @@ ## 使用说明 -1. 首页填写文件名和文件内容,点击“确定”按钮创建文件,若需要修改填写内容,点击“清空”按钮。 +1. 首页填写文件名和文件内容,点击“确定”按钮创建文件,若需要修改填写内容,点击“清除”按钮。 2. 创建成功后,点击“远端文件”按钮,查看已创建好的文件。 -3. 远端文件列表列表: +3. 远端文件列表: - 右上角打开编辑状态,选择某一项文件,可在底部进行删除,或拷贝复制操作。左上角可取消编辑状态。 - 点击任意一项文件,进入预览界面。 -4. 本地文件列表列表:页面功能和远端文件列表大致相同,区别在于: +4. 本地文件列表:页面功能和远端文件列表大致相同,区别在于: - 本地文件需要在远端文件列表中进行拷贝复制到本地。 - - 编辑状态下无拷贝按钮。 + - 编辑状态下无复制按钮。 5. 预览界面: - 点击编辑区域,自动进入编辑状态。 - 右上角对钩为编辑后保存按钮。 @@ -51,7 +51,7 @@ ## 具体实现 -1. 获取当前应用分布式共享目录沙箱路径,通过[getUIContext()](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/ts-custom-component-api#getuicontext)然后获取[getHostContext()](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-arkui-uicontext#gethostcontext12) +1. 获取当前应用分布式共享目录沙箱路径,通过[getUIContext()](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/ts-custom-component-api#getuicontext)然后获取[getHostContext()](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/arkts-apis-uicontext-uicontext#gethostcontext12) ,随后访问distributedFilesDir分布式共享目录。 2. 创建文件通过[fs.openSync()](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-file-fs#fsopensync)以同步方法打开文件或目录,然后通过[fs.writeSync()](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-file-fs#fswritesync)以同步方法将数据写入文件,最后通过[fs.closeSync()](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-file-fs#fsclosesync)以同步方法关闭文件或目录,即可创建成功。 3. 访问本地文件,通过[fs.listFile()](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-file-fs#fslistfile)列出本地filesDir沙箱路径目录下所有文件。 @@ -72,8 +72,8 @@ ## 约束与限制 1. 本示例仅支持标准系统上运行,支持设备:华为手机。 -2. HarmonyOS系统:HarmonyOS 5.1.0 Release及以上。 -3. DevEco Studio版本:DevEco Studio 5.1.0 Release及以上。 -4. HarmonyOS SDK版本:HarmonyOS 5.1.0 Release SDK及以上。 +2. HarmonyOS系统:HarmonyOS 5.1.1 Release及以上。 +3. DevEco Studio版本:DevEco Studio 5.1.1 Release及以上。 +4. HarmonyOS SDK版本:HarmonyOS 5.1.1 Release SDK及以上。 5. 双端设备需要登录同一华为账号。 6. 双端设备需要打开Wi-Fi和蓝牙开关。条件允许时,建议双端设备接入同一个局域网,可提升数据传输的速度。 diff --git a/entry/src/main/ets/components/TitleBar.ets b/entry/src/main/ets/components/TitleBar.ets index 58f7a38..7701a7b 100644 --- a/entry/src/main/ets/components/TitleBar.ets +++ b/entry/src/main/ets/components/TitleBar.ets @@ -15,6 +15,7 @@ import { fileIo as fs, WriteOptions } from '@kit.CoreFileKit'; import CommonUtils from '../utils/CommonUtils'; import { TitleBarDeleteDialog } from './TitleBarDeleteDialog'; +import { util } from '@kit.ArkTS'; import { hilog } from '@kit.PerformanceAnalysisKit'; // [Start save_file] @@ -60,9 +61,10 @@ export struct TitleBar { fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE | fs.OpenMode.TRUNC); // Open files in read-write mode const writeOptions: WriteOptions = { offset: 0, // Key point: Reset write position - length: this.fileContent.length }; - let writeLen = fs.writeSync(file.fd, this.fileContent, writeOptions); // write file + const textEncoder = new util.TextEncoder(); // Create an instance of TextEncoder and specify UTF-8 encoding + const encodedData = textEncoder.encodeInto(this.fileContent); // Convert a string to Uint8Array in UTF-8 format + let writeLen = fs.writeSync(file.fd, encodedData.buffer, writeOptions); // write file fs.fsyncSync(file.fd); if (writeLen) { fs.closeSync(file); // close file diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 6da9648..b1b5290 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -19,6 +19,7 @@ import { window } from '@kit.ArkUI'; const DOMAIN = 0x0000; let uiContext: UIContext | undefined = undefined; +let isHavePermissions: boolean = false; export default class EntryAbility extends UIAbility { onCreate(_want: Want, _launchParam: AbilityConstant.LaunchParam): void { @@ -75,19 +76,25 @@ export default class EntryAbility extends UIAbility { */ async permissions() { try { + if (isHavePermissions) { + return; + } let atManager = abilityAccessCtrl.createAtManager(); const result = await atManager.requestPermissionsFromUser(this.context, ['ohos.permission.DISTRIBUTED_DATASYNC']); if (result.authResults[0] !== -1) { uiContext!.getPromptAction().showToast({ message: $r('app.string.authorization_successful') }); + isHavePermissions = true; } const resultAgain = await atManager.requestPermissionOnSetting(this.context, ['ohos.permission.DISTRIBUTED_DATASYNC']); if (resultAgain[0] === 0) { uiContext!.getPromptAction().showToast({ message: $r('app.string.authorization_successful') }); + isHavePermissions = true; + } else { + uiContext!.getPromptAction().showToast({ message: $r('app.string.reauthorization') }); } - uiContext!.getPromptAction().showToast({ message: $r('app.string.reauthorization') }); } catch (error) { hilog.error(0xFF00, 'error', '%{public}s', 'have errors', `${JSON.stringify(error)}`); } diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 66d0e39..00f6a82 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -40,6 +40,7 @@ struct Index { // [StartExclude import_common] @State fileTile: string = ''; @State fileContent: string = ''; + // [EndExclude import_file] // [EndExclude create_file] diff --git a/entry/src/main/ets/view/RemoteFileList.ets b/entry/src/main/ets/view/RemoteFileList.ets index 41015bb..1d76c44 100644 --- a/entry/src/main/ets/view/RemoteFileList.ets +++ b/entry/src/main/ets/view/RemoteFileList.ets @@ -48,6 +48,11 @@ export struct RemoteFileList { @State value: number = 0; @State total: number = 0; @State networkId: string = ''; + listeners: fs.DfsListeners = { + onStatus: (_networkId: string, _status: number): void => { + hilog.info(0x0000, 'RemoteFile', '%{public}s', 'Failed to access public directory'); + } + }; ProgressDialog: CustomDialogController = new CustomDialogController({ builder: ProgressDialog({ value: this.value, @@ -81,6 +86,35 @@ export struct RemoteFileList { this.getRemoteFileList(); } + syncDevice(deviceInfoList: Array) { + // Create connection promises for each device information + const connectPromises = deviceInfoList.map(deviceInfo => { + return fs.connectDfs(deviceInfo.networkId, this.listeners) + .catch((error: BusinessError) => { + hilog.error(0x0000, 'RemoteFile', '%{public}s', + `Failed to connect dfs for network ${deviceInfo.networkId}. Code: ${error.code}, message: ${error.message}`); + }); + }); + + // Wait for all connection operations to complete + Promise.all(connectPromises).then(async () => { + // Process data after all connection operations are completed + this.pathDir = this.context.distributedFilesDir; + this.remoteFileListArr = await fs.listFile(this.pathDir); + console.log('test==remoteFileListArr', JSON.stringify(this.remoteFileListArr)) + + if (this.remoteFileListArr.length > 0) { + this.isShowDialog = false; + } else { + this.isShowDialog = false; + this.isEdit = false; + } + }).catch((error: BusinessError) => { + hilog.error(0x0000, 'RemoteFile', '%{public}s', + `Error in connection process. Code: ${error.code}, message: ${error.message}`); + }); + } + aboutToDisappear(): void { fs.disconnectDfs(this.networkId).then(() => { hilog.info(0x0000, 'RemoteFile', '%{public}s', 'Success to disconnect dfs'); @@ -101,29 +135,9 @@ export struct RemoteFileList { let deviceInfoList: Array = dmInstance.getAvailableDeviceListSync(); if (deviceInfoList && deviceInfoList.length > 0) { this.networkId = deviceInfoList[0].networkId!; - // Define callbacks for accessing public file directories - let listeners: fs.DfsListeners = { - onStatus: (_networkId: string, _status: number): void => { - hilog.info(0x0000, 'RemoteFile', '%{public}s', 'Failed to access public directory'); - } - }; // Start cross device file access - fs.connectDfs(this.networkId, listeners).then(async () => { - this.pathDir = this.context.distributedFilesDir; - this.remoteFileListArr = await fs.listFile(this.pathDir); - - if (this.remoteFileListArr.length > 0) { - this.isShowDialog = false; - } else { - this.isShowDialog = false; - this.isEdit = false; - } - }).catch((error: BusinessError) => { - let err: BusinessError = error as BusinessError; - hilog.error(0x0000, 'RemoteFile', '%{public}s', - `Failed to connect dfs. Code: ${err.code}, message: ${err.message}`); - }); + this.syncDevice(deviceInfoList); } else { CommonUtils.showToast($r('app.string.no_devices_currently_available'), this.uiContext!); this.isShowDialog = false; @@ -144,7 +158,11 @@ export struct RemoteFileList { this.ProgressDialog.open(); const srcUri = fileUri.getUriFromPath(this.pathDir + `/${this.selectedValue}`); // To copy file path const destUri = fileUri.getUriFromPath(this.context.filesDir + `/${this.selectedValue}`); // Target file path - + const existingPath = this.context.filesDir + `/${this.selectedValue}` + let res = fs.accessSync(existingPath); + if (res) { + fs.unlinkSync(existingPath); + } let progressListener: fs.ProgressListener = (progress: fs.Progress) => { this.value = progress.processedSize; // Copy file size this.total = progress.totalSize; // Total size of copied files @@ -166,7 +184,6 @@ export struct RemoteFileList { } catch (err) { hilog.error(0x0000, 'RemoteFile', '%{public}s', `Failed to copy.Code try: ${err.code}, message: ${err.message}`); - } } } -- Gitee From 3ee3f1437c074ef9b24acb896838c91a96740c50 Mon Sep 17 00:00:00 2001 From: liujiahui Date: Tue, 26 Aug 2025 10:46:08 +0800 Subject: [PATCH 17/18] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E6=94=B9=E6=8E=88?= =?UTF-8?q?=E6=9D=83=E5=BC=B9=E7=AA=97=E9=87=8D=E5=A4=8D=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E3=80=81=E4=BB=A3=E7=A0=81=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/ets/components/DeleteDialog.ets | 4 +- .../src/main/ets/components/EditTitleBar.ets | 4 +- entry/src/main/ets/components/ListComp.ets | 4 +- entry/src/main/ets/components/Loading.ets | 4 +- .../main/ets/components/ProgressDialog.ets | 4 +- entry/src/main/ets/components/TitleBar.ets | 4 +- .../ets/components/TitleBarDeleteDialog.ets | 4 +- .../main/ets/entryability/EntryAbility.ets | 49 +++---------- entry/src/main/ets/pages/Index.ets | 54 +++++++++++++- entry/src/main/ets/utils/CommonUtils.ets | 10 +-- entry/src/main/ets/view/LocalFileList.ets | 4 +- entry/src/main/ets/view/Preview.ets | 4 +- entry/src/main/ets/view/RemoteFileList.ets | 73 +++++++++++++------ 13 files changed, 138 insertions(+), 84 deletions(-) diff --git a/entry/src/main/ets/components/DeleteDialog.ets b/entry/src/main/ets/components/DeleteDialog.ets index b3269a5..f3d527b 100644 --- a/entry/src/main/ets/components/DeleteDialog.ets +++ b/entry/src/main/ets/components/DeleteDialog.ets @@ -1,13 +1,13 @@ /* * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); + * Licensed under the Apache License, Version 2.0 (the 'License'); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, + * distributed under the License is distributed on an 'AS IS' BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. diff --git a/entry/src/main/ets/components/EditTitleBar.ets b/entry/src/main/ets/components/EditTitleBar.ets index 2c0e06a..8276ec0 100644 --- a/entry/src/main/ets/components/EditTitleBar.ets +++ b/entry/src/main/ets/components/EditTitleBar.ets @@ -1,13 +1,13 @@ /* * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); + * Licensed under the Apache License, Version 2.0 (the 'License'); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, + * distributed under the License is distributed on an 'AS IS' BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. diff --git a/entry/src/main/ets/components/ListComp.ets b/entry/src/main/ets/components/ListComp.ets index d3b9b70..5aadf24 100644 --- a/entry/src/main/ets/components/ListComp.ets +++ b/entry/src/main/ets/components/ListComp.ets @@ -1,13 +1,13 @@ /* * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); + * Licensed under the Apache License, Version 2.0 (the 'License'); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, + * distributed under the License is distributed on an 'AS IS' BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. diff --git a/entry/src/main/ets/components/Loading.ets b/entry/src/main/ets/components/Loading.ets index f5aef62..d5f7bbc 100644 --- a/entry/src/main/ets/components/Loading.ets +++ b/entry/src/main/ets/components/Loading.ets @@ -1,13 +1,13 @@ /* * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); + * Licensed under the Apache License, Version 2.0 (the 'License'); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, + * distributed under the License is distributed on an 'AS IS' BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. diff --git a/entry/src/main/ets/components/ProgressDialog.ets b/entry/src/main/ets/components/ProgressDialog.ets index 5357e9e..cadbbd8 100644 --- a/entry/src/main/ets/components/ProgressDialog.ets +++ b/entry/src/main/ets/components/ProgressDialog.ets @@ -1,13 +1,13 @@ /* * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); + * Licensed under the Apache License, Version 2.0 (the 'License'); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, + * distributed under the License is distributed on an 'AS IS' BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. diff --git a/entry/src/main/ets/components/TitleBar.ets b/entry/src/main/ets/components/TitleBar.ets index 7701a7b..421b9af 100644 --- a/entry/src/main/ets/components/TitleBar.ets +++ b/entry/src/main/ets/components/TitleBar.ets @@ -1,13 +1,13 @@ /* * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); + * Licensed under the Apache License, Version 2.0 (the 'License'); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, + * distributed under the License is distributed on an 'AS IS' BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. diff --git a/entry/src/main/ets/components/TitleBarDeleteDialog.ets b/entry/src/main/ets/components/TitleBarDeleteDialog.ets index 9c2b4ba..784bb62 100644 --- a/entry/src/main/ets/components/TitleBarDeleteDialog.ets +++ b/entry/src/main/ets/components/TitleBarDeleteDialog.ets @@ -1,13 +1,13 @@ /* * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); + * Licensed under the Apache License, Version 2.0 (the 'License'); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, + * distributed under the License is distributed on an 'AS IS' BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index b1b5290..d75407f 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,29 +1,35 @@ /* * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); + * Licensed under the Apache License, Version 2.0 (the 'License'); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, + * distributed under the License is distributed on an 'AS IS' BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -import { abilityAccessCtrl, AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { + abilityAccessCtrl, + AbilityConstant, + ConfigurationConstant, + Permissions, + UIAbility, + bundleManager, + Want +} from '@kit.AbilityKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { window } from '@kit.ArkUI'; const DOMAIN = 0x0000; let uiContext: UIContext | undefined = undefined; -let isHavePermissions: boolean = false; export default class EntryAbility extends UIAbility { onCreate(_want: Want, _launchParam: AbilityConstant.LaunchParam): void { - this.permissions(); try { this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); @@ -33,10 +39,6 @@ export default class EntryAbility extends UIAbility { } - onNewWant(_want: Want, _launchParam: AbilityConstant.LaunchParam): void { - this.permissions(); - } - onDestroy(): void { hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); } @@ -70,33 +72,4 @@ export default class EntryAbility extends UIAbility { // Ability has back to background hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); } - - /** - * Apply for the permission to exchange data between different devices. - */ - async permissions() { - try { - if (isHavePermissions) { - return; - } - let atManager = abilityAccessCtrl.createAtManager(); - const result = await atManager.requestPermissionsFromUser(this.context, ['ohos.permission.DISTRIBUTED_DATASYNC']); - - if (result.authResults[0] !== -1) { - uiContext!.getPromptAction().showToast({ message: $r('app.string.authorization_successful') }); - isHavePermissions = true; - } - - const resultAgain = - await atManager.requestPermissionOnSetting(this.context, ['ohos.permission.DISTRIBUTED_DATASYNC']); - if (resultAgain[0] === 0) { - uiContext!.getPromptAction().showToast({ message: $r('app.string.authorization_successful') }); - isHavePermissions = true; - } else { - uiContext!.getPromptAction().showToast({ message: $r('app.string.reauthorization') }); - } - } catch (error) { - hilog.error(0xFF00, 'error', '%{public}s', 'have errors', `${JSON.stringify(error)}`); - } - } } \ No newline at end of file diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 00f6a82..0b3a844 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -13,7 +13,7 @@ * limitations under the License. */ // [Start import_common] -import { common } from '@kit.AbilityKit'; +import { common, Permissions, bundleManager, abilityAccessCtrl } from '@kit.AbilityKit'; // [StartExclude import_common] // [Start import_file] @@ -34,6 +34,7 @@ struct Index { // [StartExclude import_file] @Provide('pageInfo') pageStack: NavPathStack = new NavPathStack(); @Provide('isDeleteChange') isDeleteChange: boolean = false; + @State atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager(); @State uiContext: UIContext | undefined = AppStorage.get('uiContext'); // [EndExclude import_common] @State context: Context = this.getUIContext().getHostContext() as common.UIAbilityContext; @@ -84,6 +85,57 @@ struct Index { this.fileContent = ''; } + onPageShow(): void { + const permissionResult = this.checkPermissions(['ohos.permission.DISTRIBUTED_DATASYNC']); + if (permissionResult) { + return; + } else { + this.permissions(); + } + } + + /** + * Apply for the permission to exchange data between different devices. + */ + async permissions() { + try { + const result = + await this.atManager.requestPermissionsFromUser(this.context, ['ohos.permission.DISTRIBUTED_DATASYNC']); + + if (result.authResults[0] !== -1) { + this.uiContext!.getPromptAction().showToast({ message: $r('app.string.authorization_successful') }); + } + + const resultAgain = + await this.atManager.requestPermissionOnSetting(this.context, ['ohos.permission.DISTRIBUTED_DATASYNC']); + if (resultAgain[0] === 0) { + this.uiContext!.getPromptAction().showToast({ message: $r('app.string.authorization_successful') }); + } else { + this.uiContext!.getPromptAction().showToast({ message: $r('app.string.reauthorization') }); + } + } catch (error) { + hilog.error(0xFF00, 'error', '%{public}s', 'have errors', `${JSON.stringify(error)}`); + } + } + + /** + * Check if authorized + * @param permissions Permission array + * @returns result + */ + checkPermissions(permissions: Permissions[]) { + // Get bundle information + let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION; + + const bundleInfo = bundleManager.getBundleInfoForSelfSync(bundleFlags); + // Extract tokenID identifier + const tokenID = bundleInfo.appInfo.accessTokenId; + // Verify if the application has been granted permission + const authResults = permissions.map((item) => this.atManager.checkAccessTokenSync(tokenID, item)); + // Return whether the result has been authorized or not + return authResults.every(v => v === abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED); + } + build() { Navigation(this.pageStack) { Column({ space: 12 }) { diff --git a/entry/src/main/ets/utils/CommonUtils.ets b/entry/src/main/ets/utils/CommonUtils.ets index 64af4a7..f0e23b4 100644 --- a/entry/src/main/ets/utils/CommonUtils.ets +++ b/entry/src/main/ets/utils/CommonUtils.ets @@ -1,20 +1,20 @@ /* * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); + * Licensed under the Apache License, Version 2.0 (the 'License'); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, + * distributed under the License is distributed on an 'AS IS' BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -import { hilog } from "@kit.PerformanceAnalysisKit"; +import { hilog } from '@kit.PerformanceAnalysisKit'; import { fileIo as fs } from '@kit.CoreFileKit'; -import { BusinessError } from "@kit.BasicServicesKit"; +import { BusinessError } from '@kit.BasicServicesKit'; // [Start delete_file] class CommonUtils { @@ -34,7 +34,7 @@ class CommonUtils { fs.unlink(srcUri, (err: BusinessError) => { if (err) { hilog.error(0x0000, 'RemoteFile', '%{public}s', - ("remove file failed with error message: " + err.message + ", error code: " + err.code)); + ('remove file failed with error message: ' + err.message + ', error code: ' + err.code)); callback(false); } else { this.showToast($r('app.string.delete_successfully'), uiContext!); diff --git a/entry/src/main/ets/view/LocalFileList.ets b/entry/src/main/ets/view/LocalFileList.ets index 6834eeb..2e98ea2 100644 --- a/entry/src/main/ets/view/LocalFileList.ets +++ b/entry/src/main/ets/view/LocalFileList.ets @@ -1,13 +1,13 @@ /* * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); + * Licensed under the Apache License, Version 2.0 (the 'License'); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, + * distributed under the License is distributed on an 'AS IS' BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. diff --git a/entry/src/main/ets/view/Preview.ets b/entry/src/main/ets/view/Preview.ets index 7c78db5..badb16d 100644 --- a/entry/src/main/ets/view/Preview.ets +++ b/entry/src/main/ets/view/Preview.ets @@ -1,13 +1,13 @@ /* * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); + * Licensed under the Apache License, Version 2.0 (the 'License'); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, + * distributed under the License is distributed on an 'AS IS' BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. diff --git a/entry/src/main/ets/view/RemoteFileList.ets b/entry/src/main/ets/view/RemoteFileList.ets index 1d76c44..b7dd70f 100644 --- a/entry/src/main/ets/view/RemoteFileList.ets +++ b/entry/src/main/ets/view/RemoteFileList.ets @@ -1,28 +1,28 @@ /* * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); + * Licensed under the Apache License, Version 2.0 (the 'License'); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, + * distributed under the License is distributed on an 'AS IS' BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -import { distributedDeviceManager } from "@kit.DistributedServiceKit"; +import { distributedDeviceManager } from '@kit.DistributedServiceKit'; import { fileIo as fs, fileUri } from '@kit.CoreFileKit'; -import { common } from "@kit.AbilityKit"; -import { BusinessError } from "@kit.BasicServicesKit"; +import { common } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; import CommonUtils from '../utils/CommonUtils'; -import { ProgressDialog } from "../components/ProgressDialog"; -import { ListComp } from "../components/ListComp"; -import { Loading } from "../components/Loading"; -import { EditTitleBar } from "../components/EditTitleBar"; -import { DeleteDialog } from "../components/DeleteDialog"; -import { hilog } from "@kit.PerformanceAnalysisKit"; +import { ProgressDialog } from '../components/ProgressDialog'; +import { ListComp } from '../components/ListComp'; +import { Loading } from '../components/Loading'; +import { EditTitleBar } from '../components/EditTitleBar'; +import { DeleteDialog } from '../components/DeleteDialog'; +import { hilog } from '@kit.PerformanceAnalysisKit'; @Builder @@ -48,6 +48,7 @@ export struct RemoteFileList { @State value: number = 0; @State total: number = 0; @State networkId: string = ''; + @State connectedNetworkIds: string[] = []; listeners: fs.DfsListeners = { onStatus: (_networkId: string, _status: number): void => { hilog.info(0x0000, 'RemoteFile', '%{public}s', 'Failed to access public directory'); @@ -90,6 +91,13 @@ export struct RemoteFileList { // Create connection promises for each device information const connectPromises = deviceInfoList.map(deviceInfo => { return fs.connectDfs(deviceInfo.networkId, this.listeners) + .then(() => { + if (!this.connectedNetworkIds.includes(deviceInfo.networkId!)) { + this.connectedNetworkIds.push(deviceInfo.networkId!); + } + hilog.info(0x0000, 'RemoteFile', '%{public}s', + `Success to connect dfs for network ${deviceInfo.networkId}`); + }) .catch((error: BusinessError) => { hilog.error(0x0000, 'RemoteFile', '%{public}s', `Failed to connect dfs for network ${deviceInfo.networkId}. Code: ${error.code}, message: ${error.message}`); @@ -101,7 +109,6 @@ export struct RemoteFileList { // Process data after all connection operations are completed this.pathDir = this.context.distributedFilesDir; this.remoteFileListArr = await fs.listFile(this.pathDir); - console.log('test==remoteFileListArr', JSON.stringify(this.remoteFileListArr)) if (this.remoteFileListArr.length > 0) { this.isShowDialog = false; @@ -115,14 +122,36 @@ export struct RemoteFileList { }); } - aboutToDisappear(): void { - fs.disconnectDfs(this.networkId).then(() => { - hilog.info(0x0000, 'RemoteFile', '%{public}s', 'Success to disconnect dfs'); - }).catch((error: BusinessError) => { - let err: BusinessError = error as BusinessError; - hilog.error(0x0000, 'RemoteFile', '%{public}s', - `Failed to disconnect dfs. Code: ${err.code}, message: ${err.message}`); + async disconnectAllDfs() { + // If there are no connected devices, return directly + if (this.connectedNetworkIds.length === 0) { + hilog.info(0x0000, 'RemoteFile', '%{public}s', 'No connected devices to disconnect'); + return; + } + + // Perform a disconnection operation on each connected device and generate a disconnection Promise array + const disconnectPromises = this.connectedNetworkIds.map(networkId => { + return fs.disconnectDfs(networkId) + .then(() => { + hilog.info(0x0000, 'RemoteFile', '%{public}s', + `Success to disconnect dfs for network ${networkId}`); + }) + .catch((error: BusinessError) => { + const err: BusinessError = error as BusinessError; + hilog.error(0x0000, 'RemoteFile', '%{public}s', + `Failed to disconnect dfs for network ${networkId}. Code: ${err.code}, message: ${err.message}`); + }); }); + + await Promise.all(disconnectPromises); + + // Clear the list of connected devices + this.connectedNetworkIds = []; + hilog.info(0x0000, 'RemoteFile', '%{public}s', 'All connected devices disconnect process completed'); + } + + aboutToDisappear(): void { + this.disconnectAllDfs(); } // [EndExclude getRemoteFileList] @@ -130,7 +159,7 @@ export struct RemoteFileList { // Retrieve the file list in the remote distributed directory async getRemoteFileList() { this.isShowDialog = true; - let dmInstance = distributedDeviceManager.createDeviceManager("com.example.crossDeviceFileOperation"); + let dmInstance = distributedDeviceManager.createDeviceManager('com.example.crossDeviceFileOperation'); try { let deviceInfoList: Array = dmInstance.getAvailableDeviceListSync(); if (deviceInfoList && deviceInfoList.length > 0) { @@ -158,7 +187,7 @@ export struct RemoteFileList { this.ProgressDialog.open(); const srcUri = fileUri.getUriFromPath(this.pathDir + `/${this.selectedValue}`); // To copy file path const destUri = fileUri.getUriFromPath(this.context.filesDir + `/${this.selectedValue}`); // Target file path - const existingPath = this.context.filesDir + `/${this.selectedValue}` + const existingPath = this.context.filesDir + `/${this.selectedValue}`; let res = fs.accessSync(existingPath); if (res) { fs.unlinkSync(existingPath); @@ -173,7 +202,7 @@ export struct RemoteFileList { } }; let copyOption: fs.CopyOptions = { - "progressListener": progressListener + 'progressListener': progressListener }; try { fs.copy(srcUri, destUri, copyOption).then(() => { -- Gitee From 91673d955b83825bff6c906435851da9ace5853c Mon Sep 17 00:00:00 2001 From: liujiahui Date: Tue, 26 Aug 2025 10:52:25 +0800 Subject: [PATCH 18/18] =?UTF-8?q?imp:=E4=BC=98=E5=8C=96=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/entryability/EntryAbility.ets | 10 +--------- entry/src/main/ets/pages/Index.ets | 2 +- entry/src/main/ets/view/RemoteFileList.ets | 2 +- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index d75407f..8f6c3a6 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -13,15 +13,7 @@ * limitations under the License. */ -import { - abilityAccessCtrl, - AbilityConstant, - ConfigurationConstant, - Permissions, - UIAbility, - bundleManager, - Want -} from '@kit.AbilityKit'; +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { window } from '@kit.ArkUI'; diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 0b3a844..7b70e34 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -13,7 +13,7 @@ * limitations under the License. */ // [Start import_common] -import { common, Permissions, bundleManager, abilityAccessCtrl } from '@kit.AbilityKit'; +import { abilityAccessCtrl, bundleManager, common, Permissions } from '@kit.AbilityKit'; // [StartExclude import_common] // [Start import_file] diff --git a/entry/src/main/ets/view/RemoteFileList.ets b/entry/src/main/ets/view/RemoteFileList.ets index b7dd70f..85f299a 100644 --- a/entry/src/main/ets/view/RemoteFileList.ets +++ b/entry/src/main/ets/view/RemoteFileList.ets @@ -13,7 +13,7 @@ * limitations under the License. */ import { distributedDeviceManager } from '@kit.DistributedServiceKit'; -import { fileIo as fs, fileUri } from '@kit.CoreFileKit'; +import { fileUri, fileIo as fs } from '@kit.CoreFileKit'; import { common } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import CommonUtils from '../utils/CommonUtils'; -- Gitee