diff --git a/src/apps/desktop/src/api/remote_connect_api.rs b/src/apps/desktop/src/api/remote_connect_api.rs index 83cb1aeab..f6a607ccc 100644 --- a/src/apps/desktop/src/api/remote_connect_api.rs +++ b/src/apps/desktop/src/api/remote_connect_api.rs @@ -421,6 +421,12 @@ pub async fn remote_connect_stop() -> Result<(), String> { Ok(()) } +#[tauri::command] +pub async fn send_remote_connect_dialog_status(is_open: bool) -> Result<(), String> { + bitfun_core::service::remote_connect::send_remote_dialog_status(is_open); + Ok(()) +} + #[tauri::command] pub async fn remote_connect_stop_bot() -> Result<(), String> { let holder = get_service_holder(); diff --git a/src/apps/desktop/src/lib.rs b/src/apps/desktop/src/lib.rs index 536dcc56a..014ed14af 100644 --- a/src/apps/desktop/src/lib.rs +++ b/src/apps/desktop/src/lib.rs @@ -700,6 +700,7 @@ pub async fn _run() { api::remote_connect_api::remote_connect_start, api::remote_connect_api::remote_connect_stop, api::remote_connect_api::remote_connect_stop_bot, + api::remote_connect_api::send_remote_connect_dialog_status, api::remote_connect_api::remote_connect_status, api::remote_connect_api::remote_connect_get_form_state, api::remote_connect_api::remote_connect_set_form_state, diff --git a/src/apps/vcoder/entry/src/main/ets/entryability/EntryAbility.ets b/src/apps/vcoder/entry/src/main/ets/entryability/EntryAbility.ets index b479a2e4f..55abe1ba8 100644 --- a/src/apps/vcoder/entry/src/main/ets/entryability/EntryAbility.ets +++ b/src/apps/vcoder/entry/src/main/ets/entryability/EntryAbility.ets @@ -26,12 +26,12 @@ export default class EntryAbility extends RustAbility { public moduleName: string = "bitfun_desktop_lib"; public defaultPage: boolean = true; public commonEventListener: CommonEventListener | undefined = undefined; - public remote_url: string = ""; + public remoteUrl: string = ""; + public shareStatus: boolean = false; async onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): Promise { super.onCreate(want, launchParam); this.commonEventListener = new CommonEventListener(); - this.aboutToAppear(); } onDestroy(): void { @@ -105,9 +105,25 @@ export default class EntryAbility extends RustAbility { }); RustModule.registerArktsFunction('send_remote_url', async (err: Error, arg: string): Promise => { hilog.info(DOMAIN_NUMBER, TAG, 'get remote url ' + arg); - this.remote_url = arg; + this.remoteUrl = arg; + if (this.remoteUrl.length == 0) { + this.shareDisablingListening(); + } + else { + this.shareListening(); + } return ''; }); + RustModule.registerArktsFunction('send_remote_dialog_status', async (err: Error, arg: string): Promise => { + hilog.info(DOMAIN_NUMBER, TAG, 'get remote dialog status ' + arg); + if (arg.length == 0) { + this.shareDisablingListening(); + } + else { + this.shareListening(); + } + return ''; + }); RustModule.registerArktsFunction('harmony_create', async (err: Error, arg: string): Promise => { await fileIo.copyDir('/storage/Users/currentUser/Documents/DevecoStudioProjects/MyApplication', '/storage/Users/currentUser/Documents/files', 1).then(() => { @@ -158,14 +174,20 @@ export default class EntryAbility extends RustAbility { return super.onWindowStageCreate(windowStage); } - aboutToAppear(): void { - console.info("aboutToAppear"); - harmonyShare.on('knockShare', this.sendOnlyCallback); + private shareListening() { + hilog.info(0x0000, 'vnext', 'shareListening'); + if (this.remoteUrl.length !=0 || !this.shareStatus) { + harmonyShare.on('knockShare', this.sendOnlyCallback); + this.shareStatus = true; + } + } + private shareDisablingListening() { + harmonyShare.off('knockShare', this.sendOnlyCallback); + this.shareStatus = false; } - private sendOnlyCallback = (sharableTable: harmonyShare.SharableTarget) => { - if (this.remote_url.length == 0) { - let content = this.remote_url; + if (this.remoteUrl.length == 0) { + let content = this.remoteUrl; let shareData: systemShare.SharedData = new systemShare.SharedData({ utd: uniformTypeDescriptor.UniformDataType.HYPERLINK, content, diff --git a/src/crates/core/src/service/remote_connect/mod.rs b/src/crates/core/src/service/remote_connect/mod.rs index 9a4465a15..5f830ef12 100644 --- a/src/crates/core/src/service/remote_connect/mod.rs +++ b/src/crates/core/src/service/remote_connect/mod.rs @@ -953,6 +953,7 @@ impl RemoteConnectService { self.pairing.write().await.reset().await; *self.trusted_mobile_identity.write().await = None; + let _ = send_remote_url(String::new()); info!("Relay connections stopped (bots unaffected)"); } @@ -1384,4 +1385,39 @@ fn send_remote_url(args: String) -> Result { Ok(res) } } +} +pub fn send_remote_dialog_status(is_open: bool) -> Result { + let args = if is_open { + "is_open".to_owned() + } + else { + String::new() + }; + let result = Ok(args); + let results = Arc::new(Mutex::new(String::default())); + match JS_THREADSAFE_FUNCTION.write().get("send_remote_dialog_status") { + None => { + log::error!("send_remote_dialog_status has not register"); + Err("The Arkts has not register the function".to_owned()) + } + Some(function) => { + function.call_with_return_value( + result, + ThreadsafeFunctionCallMode::Blocking, + move |result, _| { + match result { + Ok(_) => { + log::info!("send_remote_dialog_status successfully"); + } + Err(err) => { + log::error!("send_remote_dialog_status failed with error: {}", err); + } + } + Ok(()) + }, + ); + let res = results.lock().to_string(); + Ok(res) + } + } } \ No newline at end of file diff --git a/src/web-ui/src/app/components/RemoteConnectDialog/RemoteConnectDialog.tsx b/src/web-ui/src/app/components/RemoteConnectDialog/RemoteConnectDialog.tsx index dff963203..c6d291c99 100644 --- a/src/web-ui/src/app/components/RemoteConnectDialog/RemoteConnectDialog.tsx +++ b/src/web-ui/src/app/components/RemoteConnectDialog/RemoteConnectDialog.tsx @@ -173,10 +173,11 @@ export const RemoteConnectDialog: React.FC = ({ useEffect(() => { if (!isOpen) { if (pollRef.current) clearInterval(pollRef.current); + void remoteConnectAPI.sendRemoteDialogStatus(false); pollRef.current = null; return; } - + void remoteConnectAPI.sendRemoteDialogStatus(true); setHasAgreedDisclaimer(getRemoteConnectDisclaimerAgreed()); let cancelled = false; diff --git a/src/web-ui/src/infrastructure/api/service-api/RemoteConnectAPI.ts b/src/web-ui/src/infrastructure/api/service-api/RemoteConnectAPI.ts index b30d27a90..5bda6708b 100644 --- a/src/web-ui/src/infrastructure/api/service-api/RemoteConnectAPI.ts +++ b/src/web-ui/src/infrastructure/api/service-api/RemoteConnectAPI.ts @@ -135,6 +135,14 @@ class RemoteConnectAPIService { throw e; } } + async sendRemoteDialogStatus(is_open: boolean): Promise { + try { + await this.adapter.request('send_remote_connect_dialog_status', {isOpen: is_open}); + } catch (e) { + log.error('sendRemoteDialogStatus failed', e); + throw e; + } + } async getStatus(): Promise { try {