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
26 changes: 26 additions & 0 deletions src/apps/desktop/src/api/ohos/browser.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use bitfun_core::util::JS_THREADSAFE_FUNCTION;
use log::{info,error};
#[tauri::command]
pub async fn open_browser(url: String) -> Result<(), String> {
let function = {
let lock = JS_THREADSAFE_FUNCTION.read();
lock.get("open_browser").cloned()
};
let Some(function) = function else {
return Err("The Arkts has not register the function".to_owned());
};
let res = function.call_async(Ok(url)).await;
match res {
Ok(res) => match res.await{
Ok(_) => {
info!("open_browser successfully");
Ok(())
},
Err(err) => {
error!("open_browser failed: {}", err);
Err(err.to_string())
}
},
Err(err) => Err(err.to_string()),
}
}
3 changes: 2 additions & 1 deletion src/apps/desktop/src/api/ohos/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod ohos_file_system;
pub mod window;
pub mod window;
pub mod browser;
13 changes: 12 additions & 1 deletion src/apps/desktop/src/api/system_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,18 @@ pub async fn run_system_command(
success: result.success,
})
}

#[tauri::command]
pub async fn open_external_ohos(url: String) -> Result<(), String> {
#[cfg(target_env = "ohos")]
{
use crate::api::ohos::browser::open_browser;
open_browser(url).await
}
#[cfg(not(target_env = "ohos"))]
{
Err("open_external is only supported on ohos".to_string())
}
}
#[tauri::command]
pub async fn set_macos_edit_menu_mode(
state: State<'_, AppState>,
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 @@ -742,6 +742,7 @@ pub async fn _run() {
api::terminal_api::terminal_shutdown_all,
api::terminal_api::terminal_get_history,
get_system_info,
open_external_ohos,
send_system_notification,
check_command_exists,
check_commands_exist,
Expand Down
2 changes: 1 addition & 1 deletion src/apps/desktop/src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ fn resize_agent_companion_window(

#[tauri::command]
pub async fn show_agent_companion_desktop_pet(app: tauri::AppHandle) -> Result<(), String> {
Err("Failed to create Agent companion window".to_string());
Err("Failed to create Agent companion window".to_string())
}

#[tauri::command]
Expand Down
15 changes: 15 additions & 0 deletions src/apps/vcoder/entry/src/main/ets/entryability/EntryAbility.ets
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ export default class EntryAbility extends RustAbility {
return 'false';
}
});
RustModule.registerArktsFunction('open_browser', async (err: Error, url: string): Promise<string> => {
try {
let want : Want = {
"action": "ohos.want.action.viewData",
"entities": ["entity.system.browsable"],
"uri": url
}
await this.context.startAbility(want);
hilog.info(201, 'vnext', `open url succeed: ${url}`);
return `start ability succeed with ${url}`;
} catch (error) {
hilog.info(201, 'vnext', `fail to open ${url} ${error.code}`);
return `fail to open ${url} ${error.code}`;
}
});
RustModule.registerArktsFunction('window_is_minimized', async (err: Error, arg: string): Promise<string> => {
let state = windowStage.getMainWindowSync().getWindowStatus();
if (state == window.WindowStatusType.MINIMIZE) {
Expand Down
13 changes: 10 additions & 3 deletions src/web-ui/src/infrastructure/api/service-api/SystemAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,17 @@ export class SystemAPI {

async openExternal(url: string): Promise<void> {
try {
await openUrl(url);
// 尝试调用 open_external_ohos (OHOS平台会成功)
await api.invoke('open_external_ohos', {url});
} catch (error) {
log.error('Failed to open external URL', { url, error });
throw new Error(`Failed to open external URL: ${error}`);
// 非 OHOS 平台会收到错误,然后回退到 openUrl
log.warn('open_external_ohos failed, falling back to openUrl', { url, error });
try {
await openUrl(url);
} catch (error) {
log.error('Failed to open external URL', { url, error });
throw new Error(`Failed to open external URL: ${error}`);
}
}
}

Expand Down
Loading