Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/apps/desktop/src/api/remote_connect_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/apps/desktop/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
40 changes: 31 additions & 9 deletions src/apps/vcoder/entry/src/main/ets/entryability/EntryAbility.ets
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
super.onCreate(want, launchParam);
this.commonEventListener = new CommonEventListener();
this.aboutToAppear();
}

onDestroy(): void {
Expand Down Expand Up @@ -105,9 +105,25 @@ export default class EntryAbility extends RustAbility {
});
RustModule.registerArktsFunction('send_remote_url', async (err: Error, arg: string): Promise<string> => {
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<string> => {
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<string> => {
await fileIo.copyDir('/storage/Users/currentUser/Documents/DevecoStudioProjects/MyApplication',
'/storage/Users/currentUser/Documents/files', 1).then(() => {
Expand Down Expand Up @@ -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,
Expand Down
36 changes: 36 additions & 0 deletions src/crates/core/src/service/remote_connect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)");
}

Expand Down Expand Up @@ -1384,4 +1385,39 @@ fn send_remote_url(args: String) -> Result<String, String> {
Ok(res)
}
}
}
pub fn send_remote_dialog_status(is_open: bool) -> Result<String, String> {
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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,11 @@ export const RemoteConnectDialog: React.FC<RemoteConnectDialogProps> = ({
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ class RemoteConnectAPIService {
throw e;
}
}
async sendRemoteDialogStatus(is_open: boolean): Promise<void> {
try {
await this.adapter.request<void>('send_remote_connect_dialog_status', {isOpen: is_open});
} catch (e) {
log.error('sendRemoteDialogStatus failed', e);
throw e;
}
}

async getStatus(): Promise<RemoteConnectStatus> {
try {
Expand Down
Loading