OpenHarmony: misc api

This commit is contained in:
Coder2 2025-10-31 21:01:53 +08:00
parent 89540d980a
commit 41256bcb30
No known key found for this signature in database
GPG key ID: 98C112D1F699AA4C
6 changed files with 47 additions and 8 deletions

View file

@ -1658,6 +1658,11 @@ elseif(OHOS)
endif()
endif()
sdl_glob_sources(
"${SDL3_SOURCE_DIR}/src/misc/ohos/*.c"
)
set(HAVE_SDL_MISC TRUE)
sdl_glob_sources("${SDL3_SOURCE_DIR}/src/locale/ohos/*.c")
set(HAVE_SDL_LOCALE TRUE)

View file

@ -6,13 +6,18 @@ import { inputMethod } from '@kit.IMEKit'
import { Action, Key, KeyEvent } from '@kit.InputKit';
import { pasteboard, BusinessError } from '@kit.BasicServicesKit';
import { webview } from '@kit.ArkWeb';
import WebPageExternal from './WebPageExternal';
import WebPageExternal, { updateURL } from './WebPageExternal';
import { common } from '@kit.AbilityKit';
const DOMAIN = 0x0000;
let controller = inputMethod.getController()
let input = false
let targetText = ""
let dlg = new CustomDialogController({
builder: WebPageExternal({onClose: () => { dlg.close() }})
})
let context: UIContext
export class ArkNapiCallback {
onMainLaunch() {
@ -30,6 +35,11 @@ export class ArkNapiCallback {
return 1
}
openLink(url: string) {
let con = context.getHostContext() as common.UIAbilityContext
con.openLink(url)
}
setPasteboardString(text: string) {
let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, text);
let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
@ -66,11 +76,7 @@ let callbackRef: ArkNapiCallback = new ArkNapiCallback()
@Component
struct Index {
async aboutToAppear(): Promise<void> {
let dlg = new CustomDialogController({
builder: WebPageExternal({onClose: () => { dlg.close() }, url: "https://cn.bing.com"})
})
dlg.open()
context = this.getUIContext()
sdltest.sdlCallbackInit(callbackRef)
focusControl.requestFocus('mainView')
await controller.attach(true, {

View file

@ -1,11 +1,15 @@
import webview from "@ohos.web.webview";
let pageURL = ""
export function updateURL(url: string)
{
pageURL = url;
}
@CustomDialog
export default struct WebPageExternal {
controller: CustomDialogController
webcontroller: webview.WebviewController = new webview.WebviewController();
onClose: () => void = () => {}
url: string = ""
build() {
Column() {
@ -27,7 +31,7 @@ export default struct WebPageExternal {
.height(20)
}
Web({
src: this.url,
src: pageURL,
controller: this.webcontroller
})
.height('90%')

View file

@ -294,6 +294,19 @@ void OHOS_MessageBox(const char* title, const char* message)
napi_call_threadsafe_function(napiEnv.func, data, napi_tsfn_nonblocking);
}
void OHOS_OpenLink(const char* url)
{
napiCallbackData *data = SDL_malloc(sizeof(napiCallbackData));
SDL_memset(data, 0, sizeof(napiCallbackData));
data->func = "openLink";
data->argCount = 1;
data->arg[0].type = String;
data->arg[0].enabled = true;
data->arg[0].data.str = url;
napi_call_threadsafe_function(napiEnv.func, data, napi_tsfn_blocking);
}
const char* OHOS_Locale()
{
napiCallbackData *data = SDL_malloc(sizeof(napiCallbackData));

View file

@ -14,6 +14,7 @@ int OHOS_FetchHeight();
void OHOS_MessageBox(const char* title, const char* message);
const char* OHOS_Locale();
void OHOS_OpenLink(const char* url);
void OHOS_SetClipboardText(const char* data);
bool OHOS_IsScreenKeyboardShown();

View file

@ -0,0 +1,10 @@
#include "SDL_internal.h"
#include "../../core/ohos/SDL_ohos.h"
#include "../SDL_sysurl.h"
bool SDL_SYS_OpenURL(const char *url)
{
OHOS_OpenLink(url);
return true;
}