From 55025f5b486047083d89056ea9e2927144ce9993 Mon Sep 17 00:00:00 2001 From: liujiahui Date: Wed, 7 May 2025 09:40:54 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=BA=9F=E5=BC=83=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entry/src/main/ets/pages/ServerSocketPage.ets | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ServerSocket/entry/src/main/ets/pages/ServerSocketPage.ets b/ServerSocket/entry/src/main/ets/pages/ServerSocketPage.ets index 9726939..751cf2c 100644 --- a/ServerSocket/entry/src/main/ets/pages/ServerSocketPage.ets +++ b/ServerSocket/entry/src/main/ets/pages/ServerSocketPage.ets @@ -115,7 +115,7 @@ struct ServerSocketPage { }; wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj: WantAgent) => { - backgroundTaskManager.startBackgroundRunning(getContext(this), + backgroundTaskManager.startBackgroundRunning(this.getUIContext().getHostContext(), backgroundTaskManager.BackgroundMode.DATA_TRANSFER, wantAgentObj).then(() => { this.connectInit(); Logger.info(`Succeeded in operationing startBackgroundRunning.`); @@ -126,7 +126,7 @@ struct ServerSocketPage { } stopContinuousTask() { - backgroundTaskManager.stopBackgroundRunning(getContext(this)).then(() => { + backgroundTaskManager.stopBackgroundRunning(this.getUIContext().getHostContext()).then(() => { Logger.info(`Succeeded in operationing stopBackgroundRunning.`); }).catch((err: BusinessError) => { Logger.error(`Failed to operation stopBackgroundRunning. Code is ${err.code}, message is ${err.message}`); @@ -142,11 +142,11 @@ struct ServerSocketPage { return; } this.isListen = true; - promptAction.showToast({ message: $r('app.string.tcp_server_listen_tips') }); + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.tcp_server_listen_tips') }); this.tcpServer.on('connect', (client: socket.TCPSocketConnection) => { Logger.info('on connect success'); this.isSend = true; - promptAction.showToast({ message: $r('app.string.tcp_server_connect_tips') }); + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.tcp_server_connect_tips') }); this.socketClient = client; this.socketClient.on('close', () => { Logger.info('on close success'); @@ -164,7 +164,8 @@ struct ServerSocketPage { async sendFile() { try { - const mediaBuffer: Uint8Array = await getContext(this).resourceManager.getMediaContent($r('app.media.Video')); + const mediaBuffer: Uint8Array = + await this.getUIContext().getHostContext()!.resourceManager.getMediaContent($r('app.media.Video')); let tcpSendOptions: socket.TCPSendOptions = {} as socket.TCPSendOptions; // slice size: 1024 * 1024 const sendNum = Math.floor(mediaBuffer.byteLength / (1024 * 1024)); @@ -191,7 +192,7 @@ struct ServerSocketPage { Logger.error('send fail' + JSON.stringify(err)); return; } - promptAction.showToast({ message: $r('app.string.message_send_tips') }); + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.message_send_tips') }); }); } } catch (err) { -- Gitee From a5580c3ded811691aac3f7731597c7bc0a9d921e Mon Sep 17 00:00:00 2001 From: liujiahui Date: Tue, 13 May 2025 16:48:06 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=BA=9F=E5=BC=83api=20=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entry/src/main/ets/pages/HTTPReconnection.ets | 4 ++-- .../entry/src/main/ets/pages/RCPReconnection.ets | 4 ++-- .../entry/src/main/ets/pages/SocketReconnection.ets | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/NetworkReconnection/entry/src/main/ets/pages/HTTPReconnection.ets b/NetworkReconnection/entry/src/main/ets/pages/HTTPReconnection.ets index b06255f..8cda44f 100644 --- a/NetworkReconnection/entry/src/main/ets/pages/HTTPReconnection.ets +++ b/NetworkReconnection/entry/src/main/ets/pages/HTTPReconnection.ets @@ -103,7 +103,7 @@ export struct HTTPReconnection { }); this.httpRequest.on('dataEnd', () => { - promptAction.showToast({ message: $r('app.string.download_success') }); + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.download_success') }); this.downloadSize = 0; this.contentLength = 0; fs.closeSync(file); @@ -134,7 +134,7 @@ export struct HTTPReconnection { }); } catch (err) { this.isDownload = false; - promptAction.showToast({ message: $r('app.string.download_error') }); + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.download_error') }); return; } } diff --git a/NetworkReconnection/entry/src/main/ets/pages/RCPReconnection.ets b/NetworkReconnection/entry/src/main/ets/pages/RCPReconnection.ets index 4d1adb6..0e715ff 100644 --- a/NetworkReconnection/entry/src/main/ets/pages/RCPReconnection.ets +++ b/NetworkReconnection/entry/src/main/ets/pages/RCPReconnection.ets @@ -127,7 +127,7 @@ export struct RCPReconnection { fs.writeSync(file.fd, response.body); fs.closeSync(file); this.isDownload = false; - promptAction.showToast({ message: $r('app.string.download_success') }); + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.download_success') }); } catch (err) { Logger.info(JSON.stringify(err)); } finally { @@ -153,7 +153,7 @@ export struct RCPReconnection { } }) } catch (err) { - promptAction.showToast({ message: $r('app.string.download_error') }); + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.download_error') }); this.isDownload = false; return; } diff --git a/NetworkReconnection/entry/src/main/ets/pages/SocketReconnection.ets b/NetworkReconnection/entry/src/main/ets/pages/SocketReconnection.ets index b53c5b2..82aa940 100644 --- a/NetworkReconnection/entry/src/main/ets/pages/SocketReconnection.ets +++ b/NetworkReconnection/entry/src/main/ets/pages/SocketReconnection.ets @@ -109,7 +109,7 @@ export struct SocketReconnection { tcpSocketConnect() { if (!this.netAvailable) { - promptAction.showToast({ message: $r('app.string.connect_error') }); + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.connect_error') }); return; } @@ -132,7 +132,7 @@ export struct SocketReconnection { this.tcp.bind(clientIpAddress, (err: BusinessError) => { if (err) { Logger.error('bind fail' + JSON.stringify(err)); - promptAction.showToast({ message: $r('app.string.connect_error') }); + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.connect_error') }); return; } @@ -146,7 +146,7 @@ export struct SocketReconnection { this.tcp?.connect(tcpConnect, (err: BusinessError) => { if (err) { Logger.error('connect fail'); - promptAction.showToast({ message: $r('app.string.connect_error') }); + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.connect_error') }); return; } }); @@ -159,7 +159,7 @@ export struct SocketReconnection { socketDownloadFile() { if (!this.netAvailable) { - promptAction.showToast({ message: $r('app.string.net_lost') }); + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.net_lost') }); return; } this.isDownload = true; @@ -223,7 +223,7 @@ export struct SocketReconnection { fs.writeSync(file.fd, this.receivedDataBuf.subarray(8 + i * (1024 * 1024 + 8), this.receivedDataLen).buffer, { offset: offset }); fs.close(file); - promptAction.showToast({ message: $r('app.string.download_success') }); + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.download_success') }); this.stateInit(); } } -- Gitee