mirror of
https://gitee.com/openharmony/filemanagement_user_file_service
synced 2024-11-27 01:21:32 +00:00
!928 DocumentViewPicker支持传递window拉起文管页面
Merge pull request !928 from BrainL/windowPicker
This commit is contained in:
commit
127020e5f1
@ -24,6 +24,7 @@
|
||||
#include "picker_napi_utils.h"
|
||||
#include "napi_base_context.h"
|
||||
#include "napi_common_want.h"
|
||||
#include "ui_extension_context.h"
|
||||
|
||||
|
||||
namespace OHOS {
|
||||
@ -51,6 +52,8 @@ struct PickerAsyncContext {
|
||||
std::shared_ptr<PickerCallBack> pickerCallBack;
|
||||
};
|
||||
|
||||
static sptr<Rosen::Window> window_;
|
||||
|
||||
class PickerNExporter final : public FileManagement::LibN::NExporter {
|
||||
public:
|
||||
inline static const std::string className_ = "Picker";
|
||||
|
@ -44,9 +44,10 @@ constexpr uint32_t NAPI_INIT_REF_COUNT = 1;
|
||||
constexpr size_t NAPI_ARGC_MAX = 5;
|
||||
|
||||
// Error codes
|
||||
const int32_t ERR_DEFAULT = 0;
|
||||
const int32_t ERR_OK = 0;
|
||||
const int32_t ERR_MEM_ALLOCATION = 2;
|
||||
const int32_t ERR_INVALID_OUTPUT = 3;
|
||||
const int32_t ERR_INV = -1;
|
||||
|
||||
struct JSAsyncContextOutput {
|
||||
napi_value error;
|
||||
|
@ -308,7 +308,7 @@ function parseAudioPickerSelectOption(args, action) {
|
||||
config.parameters.key_pick_num = option.maxSelectNumber;
|
||||
}
|
||||
}
|
||||
console.log('modal picker: audio select config: ' + JSON.stringify(config));
|
||||
console.log('[picker] audio select config: ' + JSON.stringify(config));
|
||||
return config;
|
||||
}
|
||||
|
||||
@ -317,7 +317,7 @@ function getDocumentPickerSelectResult(args) {
|
||||
error: undefined,
|
||||
data: undefined
|
||||
};
|
||||
if (args.resultCode === undefined) {
|
||||
if (args === undefined || args.resultCode === undefined) {
|
||||
selectResult.error = getErr(ErrCode.RESULT_ERROR);
|
||||
console.log('[picker] document select selectResult: ' + JSON.stringify(selectResult));
|
||||
return selectResult;
|
||||
@ -348,6 +348,7 @@ async function documentPickerSelect(...args) {
|
||||
let documentSelectConfig = undefined;
|
||||
let documentSelectResult = undefined;
|
||||
let selectResult = undefined;
|
||||
let documentSelectWindow = undefined;
|
||||
|
||||
try {
|
||||
if (this.context !== undefined) {
|
||||
@ -364,9 +365,12 @@ async function documentPickerSelect(...args) {
|
||||
console.error('[picker] documentSelectContext == undefined');
|
||||
throw getErr(ErrCode.CONTEXT_NO_EXIST);
|
||||
}
|
||||
if (this.window !== undefined) {
|
||||
documentSelectWindow = this.window;
|
||||
}
|
||||
documentSelectConfig = parseDocumentPickerSelectOption(args, ACTION.SELECT_ACTION_MODAL);
|
||||
console.error('[picker] DocumentSelect documentSelectConfig: ' + JSON.stringify(documentSelectConfig));
|
||||
documentSelectResult = await modalPicker(args, documentSelectContext, documentSelectConfig);
|
||||
documentSelectResult = await modalPicker(documentSelectContext, documentSelectConfig, documentSelectWindow);
|
||||
} catch (paramError) {
|
||||
console.error('[picker] DocumentSelect paramError: ' + JSON.stringify(paramError));
|
||||
}
|
||||
@ -414,7 +418,7 @@ function getAudioPickerSelectResult(args) {
|
||||
error: undefined,
|
||||
data: undefined
|
||||
};
|
||||
if (args.resultCode === undefined) {
|
||||
if (args === undefined || args.resultCode === undefined) {
|
||||
selectResult.error = getErr(ErrCode.RESULT_ERROR);
|
||||
console.log('[picker] getAudioPickerSelectResult selectResult: ' + JSON.stringify(selectResult));
|
||||
return selectResult;
|
||||
@ -444,7 +448,7 @@ function getDocumentPickerSaveResult(args) {
|
||||
data: undefined,
|
||||
suffix: -1
|
||||
};
|
||||
if (args.resultCode === undefined) {
|
||||
if (args === undefined || args.resultCode === undefined) {
|
||||
saveResult.error = getErr(ErrCode.RESULT_ERROR);
|
||||
console.log('[picker] getDocumentPickerSaveResult saveResult: ' + JSON.stringify(saveResult));
|
||||
return saveResult;
|
||||
@ -467,33 +471,36 @@ function getDocumentPickerSaveResult(args) {
|
||||
return saveResult;
|
||||
}
|
||||
|
||||
function startModalPicker(context, config) {
|
||||
function startModalPicker(context, config, window) {
|
||||
if (context === undefined) {
|
||||
console.log('[picker] modal picker: startModalPicker context undefined.');
|
||||
throw Error('[picker] modal picker: startModalPicker context undefined.');
|
||||
throw Error('[picker] Context undefined.');
|
||||
}
|
||||
if (config === undefined) {
|
||||
console.log('[picker] modal picker: startModalPicker config undefined.');
|
||||
throw Error('[picker] modal picker: startModalPicker config undefined.');
|
||||
throw Error('[picker] Config undefined.');
|
||||
}
|
||||
gContext = context;
|
||||
if (pickerHelper === undefined) {
|
||||
console.log('[picker] modal picker: pickerHelper undefined.');
|
||||
throw Error('[picker] PickerHelper undefined.');
|
||||
}
|
||||
let helper;
|
||||
if (window !== undefined) {
|
||||
helper = pickerHelper.startModalPicker(gContext, config, window);
|
||||
} else {
|
||||
helper = pickerHelper.startModalPicker(gContext, config);
|
||||
}
|
||||
let helper = pickerHelper.startModalPicker(gContext, config);
|
||||
if (helper === undefined) {
|
||||
console.log('[picker] modal picker: startModalPicker helper undefined.');
|
||||
throw Error('[picker] Please check the parameter you entered.');
|
||||
}
|
||||
return helper;
|
||||
}
|
||||
|
||||
async function modalPicker(args, context, config) {
|
||||
async function modalPicker(context, config, window) {
|
||||
try {
|
||||
console.log('[picker] modal picker: config: ' + JSON.stringify(config));
|
||||
let modalResult = await startModalPicker(context, config);
|
||||
console.log('[picker] Config: ' + JSON.stringify(config));
|
||||
let modalResult = await startModalPicker(context, config, window);
|
||||
return modalResult;
|
||||
} catch (resultError) {
|
||||
console.error('[picker] modal picker: Result error: ' + resultError);
|
||||
console.error('[picker] Result error: ' + resultError);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
@ -509,6 +516,7 @@ async function documentPickerSave(...args) {
|
||||
let documentSaveConfig = undefined;
|
||||
let documentSaveResult = undefined;
|
||||
let saveResult = undefined;
|
||||
let documentSaveWindow = undefined;
|
||||
|
||||
try {
|
||||
if (this.context !== undefined) {
|
||||
@ -520,11 +528,14 @@ async function documentPickerSave(...args) {
|
||||
console.error('[picker] getContext error: ' + getContextError);
|
||||
throw getErr(ErrCode.CONTEXT_NO_EXIST);
|
||||
}
|
||||
if (this.window !== undefined) {
|
||||
documentSaveWindow = this.window;
|
||||
}
|
||||
|
||||
documentSaveConfig = parseDocumentPickerSaveOption(args, ACTION.SAVE_ACTION_MODAL);
|
||||
console.log('[picker] document save start');
|
||||
|
||||
documentSaveResult = await modalPicker(args, documentSaveContext, documentSaveConfig);
|
||||
documentSaveResult = await modalPicker(documentSaveContext, documentSaveConfig, documentSaveWindow);
|
||||
saveResult = getDocumentPickerSaveResult(documentSaveResult);
|
||||
this.suffixIndex = saveResult.suffix;
|
||||
return sendResult(args, saveResult);
|
||||
@ -573,6 +584,7 @@ async function audioPickerSelect(...args) {
|
||||
console.log('[picker] audio select config: ' + JSON.stringify(audioSelectConfig));
|
||||
|
||||
let audioSelectContext = undefined;
|
||||
let audipSelectWindow = undefined;
|
||||
try {
|
||||
if (this.context !== undefined) {
|
||||
audioSelectContext = this.context;
|
||||
@ -588,7 +600,7 @@ async function audioPickerSelect(...args) {
|
||||
console.error('[picker] audioSelectContext == undefined');
|
||||
throw getErr(ErrCode.CONTEXT_NO_EXIST);
|
||||
}
|
||||
let modalSelectResult = await modalPicker(args, audioSelectContext, audioSelectConfig);
|
||||
let modalSelectResult = await modalPicker(audioSelectContext, audioSelectConfig, audipSelectWindow);
|
||||
let saveResult = getAudioPickerSelectResult(modalSelectResult);
|
||||
return sendResult(args, saveResult);
|
||||
} catch (error) {
|
||||
@ -633,12 +645,26 @@ function AudioSaveOptions() {
|
||||
|
||||
function ParseContext(args)
|
||||
{
|
||||
if (args.length > ARGS_ONE || args.length < ARGS_ZERO || typeof args[ARGS_ZERO] !== 'object') {
|
||||
if (args.length > ARGS_TWO || args.length < ARGS_ZERO || typeof args[ARGS_ZERO] !== 'object') {
|
||||
return undefined;
|
||||
}
|
||||
return args[ARGS_ZERO];
|
||||
}
|
||||
|
||||
function parseWindow(args)
|
||||
{
|
||||
if (args.length !== ARGS_TWO) {
|
||||
console.log('[picker] ParseWindow: not window mode.');
|
||||
return undefined;
|
||||
}
|
||||
if (args.length === ARGS_TWO && typeof args[ARGS_ONE] !== 'object') {
|
||||
console.log('[picker] ParseWindow: not window mode or type err.');
|
||||
return undefined;
|
||||
}
|
||||
console.log('[picker] ParseWindow: window mode.');
|
||||
return args[ARGS_ONE];
|
||||
}
|
||||
|
||||
function PhotoViewPicker(...args) {
|
||||
this.select = photoPickerSelect;
|
||||
this.save = documentPickerSave;
|
||||
@ -649,6 +675,7 @@ function DocumentViewPicker(...args) {
|
||||
this.select = documentPickerSelect;
|
||||
this.save = documentPickerSave;
|
||||
this.context = ParseContext(args);
|
||||
this.window = parseWindow(args);
|
||||
this.getSelectedIndex = getSelectedSuffixIndex;
|
||||
this.suffixIndex = -1;
|
||||
}
|
||||
|
@ -33,21 +33,21 @@ void ModalUICallback::SetSessionId(int32_t sessionId)
|
||||
|
||||
void ModalUICallback::OnRelease(int32_t releaseCode)
|
||||
{
|
||||
HILOG_INFO("modal picker: OnRelease enter. release code is %{public}d", releaseCode);
|
||||
HILOG_INFO("[picker] OnRelease enter. release code is %{public}d", releaseCode);
|
||||
this->uiContent->CloseModalUIExtension(this->sessionId_);
|
||||
pickerCallBack_->ready = true;
|
||||
}
|
||||
|
||||
void ModalUICallback::OnError(int32_t code, const std::string& name, const std::string& message)
|
||||
{
|
||||
HILOG_ERROR("modal picker: OnError enter. errorCode=%{public}d, name=%{public}s, message=%{public}s",
|
||||
HILOG_ERROR("[picker] OnError enter. errorCode=%{public}d, name=%{public}s, message=%{public}s",
|
||||
code, name.c_str(), message.c_str());
|
||||
this->uiContent->CloseModalUIExtension(this->sessionId_);
|
||||
}
|
||||
|
||||
void ModalUICallback::OnResultForModal(int32_t resultCode, const OHOS::AAFwk::Want &result)
|
||||
{
|
||||
HILOG_INFO("modal picker: OnResultForModal enter. resultCode is %{public}d,", resultCode);
|
||||
HILOG_INFO("[picker] OnResultForModal enter. resultCode is %{public}d,", resultCode);
|
||||
pickerCallBack_->resultCode = resultCode;
|
||||
pickerCallBack_->want = result;
|
||||
pickerCallBack_->ready = true;
|
||||
@ -56,12 +56,12 @@ void ModalUICallback::OnResultForModal(int32_t resultCode, const OHOS::AAFwk::Wa
|
||||
|
||||
void ModalUICallback::OnReceive(const OHOS::AAFwk::WantParams &request)
|
||||
{
|
||||
HILOG_INFO("modal picker: OnReceive enter.");
|
||||
HILOG_INFO("[picker] OnReceive enter.");
|
||||
}
|
||||
|
||||
void ModalUICallback::OnDestroy()
|
||||
{
|
||||
HILOG_INFO("modal picker: OnDestroy enter.");
|
||||
HILOG_INFO("[picker] OnDestroy enter.");
|
||||
}
|
||||
} // namespace Picker
|
||||
} // namespace OHOS
|
@ -47,12 +47,12 @@ string PickerNExporter::GetClassName()
|
||||
|
||||
static void StartModalPickerExecute(napi_env env, void *data)
|
||||
{
|
||||
HILOG_INFO("modal picker: StartModalPickerExecute begin");
|
||||
HILOG_INFO("[picker]: StartModalPickerExecute begin");
|
||||
auto *context = static_cast<PickerAsyncContext*>(data);
|
||||
while (!context->pickerCallBack->ready) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_TIME_MS));
|
||||
}
|
||||
HILOG_INFO("modal picker: StartModalPickerExecute is ready.");
|
||||
HILOG_INFO("[picker]: StartModalPickerExecute is ready.");
|
||||
}
|
||||
|
||||
static void MakeResultWithArr(napi_env env, std::string key, napi_value &result,
|
||||
@ -63,7 +63,7 @@ static void MakeResultWithArr(napi_env env, std::string key, napi_value &result,
|
||||
napi_status status = napi_generic_failure;
|
||||
if (pickerCallBack->want.GetParams().HasParam(key.c_str())) {
|
||||
std::vector<std::string> list = pickerCallBack->want.GetStringArrayParam(key.c_str());
|
||||
HILOG_INFO("modal picker: %{public}s size. %{public}zu ", key.c_str(), list.size());
|
||||
HILOG_INFO("[picker]: %{public}s size. %{public}zu ", key.c_str(), list.size());
|
||||
for (size_t i = 0; i < list.size(); i++) {
|
||||
napi_value uri = nullptr;
|
||||
napi_create_string_utf8(env, list[i].c_str(), NAPI_AUTO_LENGTH, &uri);
|
||||
@ -74,7 +74,7 @@ static void MakeResultWithArr(napi_env env, std::string key, napi_value &result,
|
||||
}
|
||||
status = napi_set_named_property(env, result, key.c_str(), array);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("modal picker: napi_set_named_property uri failed");
|
||||
HILOG_ERROR("[picker]: napi_set_named_property uri failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -85,12 +85,12 @@ static void MakeResultWithInt(napi_env env, std::string key, napi_value &result,
|
||||
napi_status status = napi_generic_failure;
|
||||
if (pickerCallBack->want.GetParams().HasParam(key.c_str())) {
|
||||
const int32_t suffixindex = pickerCallBack->want.GetIntParam(key.c_str(), -1);
|
||||
HILOG_INFO("Modal picker: %{public}s is %{public}d ", key.c_str(), suffixindex);
|
||||
HILOG_INFO("[picker]: %{public}s is %{public}d ", key.c_str(), suffixindex);
|
||||
napi_value suffix = nullptr;
|
||||
napi_create_int32(env, suffixindex, &suffix);
|
||||
status = napi_set_named_property(env, result, key.c_str(), suffix);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("Modal picker: napi_set_named_property suffix failed");
|
||||
HILOG_ERROR("[picker]: napi_set_named_property suffix failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -106,12 +106,12 @@ static napi_value MakeResultWithPickerCallBack(napi_env env, std::shared_ptr<Pic
|
||||
napi_create_object(env, &result);
|
||||
|
||||
const int32_t resCode = pickerCallBack->resultCode;
|
||||
HILOG_INFO("modal picker: resCode is %{public}d.", resCode);
|
||||
HILOG_INFO("[picker]: resCode is %{public}d.", resCode);
|
||||
napi_value resultCode = nullptr;
|
||||
napi_create_int32(env, resCode, &resultCode);
|
||||
status = napi_set_named_property(env, result, "resultCode", resultCode);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("modal picker: napi_set_named_property resultCode failed");
|
||||
HILOG_ERROR("[picker]: napi_set_named_property resultCode failed");
|
||||
}
|
||||
MakeResultWithArr(env, "ability.params.stream", result, pickerCallBack);
|
||||
MakeResultWithArr(env, "uriArr", result, pickerCallBack);
|
||||
@ -121,7 +121,7 @@ static napi_value MakeResultWithPickerCallBack(napi_env env, std::shared_ptr<Pic
|
||||
|
||||
static void StartModalPickerAsyncCallbackComplete(napi_env env, napi_status status, void *data)
|
||||
{
|
||||
HILOG_INFO("modal picker: StartModalPickerAsyncCallbackComplete begin.");
|
||||
HILOG_INFO("[picker]: StartModalPickerAsyncCallbackComplete begin.");
|
||||
auto *context = static_cast<PickerAsyncContext*>(data);
|
||||
if (context == nullptr) {
|
||||
HILOG_ERROR("Async context is null");
|
||||
@ -131,11 +131,11 @@ static void StartModalPickerAsyncCallbackComplete(napi_env env, napi_status stat
|
||||
jsContext->status = false;
|
||||
status = napi_get_undefined(env, &jsContext->data);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("modal picker: napi_get_undefined jsContext->data failed");
|
||||
HILOG_ERROR("[picker]: napi_get_undefined jsContext->data failed");
|
||||
}
|
||||
status = napi_get_undefined(env, &jsContext->error);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("modal picker: napi_get_undefined jsContext->error failed");
|
||||
HILOG_ERROR("[picker]: napi_get_undefined jsContext->error failed");
|
||||
}
|
||||
napi_value result = MakeResultWithPickerCallBack(env, context->pickerCallBack);
|
||||
if (result != nullptr) {
|
||||
@ -150,6 +150,83 @@ static void StartModalPickerAsyncCallbackComplete(napi_env env, napi_status stat
|
||||
context->work, *jsContext);
|
||||
}
|
||||
delete context;
|
||||
if (window_) {
|
||||
window_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
static bool IsTypeRight(napi_env env, napi_value val, napi_valuetype type)
|
||||
{
|
||||
napi_valuetype valueType;
|
||||
napi_status status = napi_typeof(env, val, &valueType);
|
||||
if (status != napi_ok || valueType != type) {
|
||||
HILOG_ERROR("[picker] Type is not right, type: %{public}d", valueType);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static ErrCode GetWindowName(napi_env env, napi_value properties, sptr<Rosen::Window> &window)
|
||||
{
|
||||
HILOG_INFO("[picker] Begin GetWindowName.");
|
||||
napi_value name;
|
||||
napi_status status = napi_get_named_property(env, properties, "name", &name);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("Get name from properties fail.");
|
||||
return ERR_INV;
|
||||
}
|
||||
size_t nameLen;
|
||||
status = napi_get_value_string_utf8(env, name, NULL, 0, &nameLen);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("[picker] Get window name length fail.");
|
||||
return ERR_INV;
|
||||
}
|
||||
char *nameBuf = new char[nameLen + 1];
|
||||
status = napi_get_value_string_utf8(env, name, nameBuf, nameLen + 1, &nameLen);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("[picker] Get value string UTF8 fail.");
|
||||
return ERR_INV;
|
||||
}
|
||||
HILOG_INFO("[picker] Get window name: %{public}s", nameBuf);
|
||||
auto customWindow = Rosen::Window::Find(nameBuf);
|
||||
if (!customWindow) {
|
||||
HILOG_ERROR("[picker] Window find fail.");
|
||||
return ERR_INV;
|
||||
}
|
||||
window = customWindow;
|
||||
HILOG_INFO("[picker] Window found: %{public}s", nameBuf);
|
||||
delete[] nameBuf;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
template <class AsyncContext>
|
||||
static ErrCode GetCustomShowingWindow(napi_env env, AsyncContext &asyncContext,
|
||||
const napi_callback_info info, sptr<Rosen::Window> &window)
|
||||
{
|
||||
HILOG_INFO("[picker] GetCustomShowingWindow enter.");
|
||||
napi_status status;
|
||||
if (!IsTypeRight(env, asyncContext->argv[ARGS_TWO], napi_object)) {
|
||||
HILOG_ERROR("[picker] The type of the parameter transferred to the window is not object.");
|
||||
return ERR_INV;
|
||||
}
|
||||
auto windowObj = asyncContext->argv[ARGS_TWO];
|
||||
napi_value getPropertiesFunc;
|
||||
status = napi_get_named_property(env, windowObj, "getWindowProperties", &getPropertiesFunc);
|
||||
if (status != napi_ok || !getPropertiesFunc) {
|
||||
HILOG_ERROR("[picker] getWindowProperties fail.");
|
||||
return ERR_INV;
|
||||
}
|
||||
if (!IsTypeRight(env, getPropertiesFunc, napi_function)) {
|
||||
HILOG_ERROR("[picker] The type of the parameter transferred to the getPropertiesFunc is not function.");
|
||||
return ERR_INV;
|
||||
}
|
||||
napi_value properties;
|
||||
status = napi_call_function(env, windowObj, getPropertiesFunc, 0, nullptr, &properties);
|
||||
if (status != napi_ok || !properties) {
|
||||
HILOG_INFO("[picker] Call getPropertiesFunc fail.");
|
||||
return ERR_INV;
|
||||
}
|
||||
return GetWindowName(env, properties, window);
|
||||
}
|
||||
|
||||
Ace::UIContent *GetUIContent(napi_env env, napi_callback_info info,
|
||||
@ -158,19 +235,19 @@ Ace::UIContent *GetUIContent(napi_env env, napi_callback_info info,
|
||||
bool isStageMode = false;
|
||||
napi_status status = AbilityRuntime::IsStageContext(env, AsyncContext->argv[ARGS_ZERO], isStageMode);
|
||||
if (status != napi_ok || !isStageMode) {
|
||||
HILOG_ERROR("modal picker: is not StageMode context");
|
||||
HILOG_ERROR("[picker]: is not StageMode context");
|
||||
return nullptr;
|
||||
}
|
||||
auto context = AbilityRuntime::GetStageModeContext(env, AsyncContext->argv[ARGS_ZERO]);
|
||||
if (context == nullptr) {
|
||||
HILOG_ERROR("modal picker: Failed to get native stage context instance");
|
||||
HILOG_ERROR("[picker]: Failed to get native stage context instance");
|
||||
return nullptr;
|
||||
}
|
||||
auto abilityContext = AbilityRuntime::Context::ConvertTo<AbilityRuntime::AbilityContext>(context);
|
||||
if (abilityContext == nullptr) {
|
||||
auto uiExtensionContext = AbilityRuntime::Context::ConvertTo<AbilityRuntime::UIExtensionContext>(context);
|
||||
if (uiExtensionContext == nullptr) {
|
||||
HILOG_ERROR("modal picker: Fail to convert to abilityContext or uiExtensionContext");
|
||||
HILOG_ERROR("[picker]: Fail to convert to abilityContext or uiExtensionContext");
|
||||
return nullptr;
|
||||
}
|
||||
return uiExtensionContext->GetUIContent();
|
||||
@ -179,16 +256,24 @@ Ace::UIContent *GetUIContent(napi_env env, napi_callback_info info,
|
||||
}
|
||||
|
||||
static napi_value StartPickerExtension(napi_env env, napi_callback_info info,
|
||||
unique_ptr<PickerAsyncContext> &AsyncContext)
|
||||
unique_ptr<PickerAsyncContext> &asyncContext)
|
||||
{
|
||||
HILOG_INFO("modal picker: StartPickerExtension begin.");
|
||||
Ace::UIContent *uiContent = GetUIContent(env, info, AsyncContext);
|
||||
HILOG_INFO("[picker]: StartPickerExtension begin.");
|
||||
Ace::UIContent *uiContent;
|
||||
if (asyncContext->argc == ARGS_THREE && window_) {
|
||||
HILOG_INFO("[picker] Will get uiContent by window.");
|
||||
uiContent = window_->GetUIContent();
|
||||
} else {
|
||||
HILOG_INFO("[picker] Will get uiContent by context.");
|
||||
uiContent= GetUIContent(env, info, asyncContext);
|
||||
}
|
||||
|
||||
if (uiContent == nullptr) {
|
||||
HILOG_ERROR("modal picker: get uiContent failed");
|
||||
HILOG_ERROR("[picker]: get uiContent failed");
|
||||
return nullptr;
|
||||
}
|
||||
AAFwk::Want request;
|
||||
AppExecFwk::UnwrapWant(env, AsyncContext->argv[ARGS_ONE], request);
|
||||
AppExecFwk::UnwrapWant(env, asyncContext->argv[ARGS_ONE], request);
|
||||
|
||||
std::string targetType = request.GetStringParam("extType");
|
||||
std::string pickerType;
|
||||
@ -196,8 +281,8 @@ static napi_value StartPickerExtension(napi_env env, napi_callback_info info,
|
||||
pickerType = request.GetStringParam("pickerType");
|
||||
}
|
||||
request.SetParam(ABILITY_WANT_PARAMS_UIEXTENSIONTARGETTYPE, targetType);
|
||||
AsyncContext->pickerCallBack = make_shared<PickerCallBack>();
|
||||
auto callback = std::make_shared<ModalUICallback>(uiContent, AsyncContext->pickerCallBack);
|
||||
asyncContext->pickerCallBack = make_shared<PickerCallBack>();
|
||||
auto callback = std::make_shared<ModalUICallback>(uiContent, asyncContext->pickerCallBack);
|
||||
Ace::ModalUIExtensionCallbacks extensionCallback = {
|
||||
.onRelease = std::bind(&ModalUICallback::OnRelease, callback, std::placeholders::_1),
|
||||
.onResult = std::bind(&ModalUICallback::OnResultForModal, callback, std::placeholders::_1,
|
||||
@ -208,11 +293,11 @@ static napi_value StartPickerExtension(napi_env env, napi_callback_info info,
|
||||
.onDestroy = std::bind(&ModalUICallback::OnDestroy, callback),
|
||||
};
|
||||
Ace::ModalUIExtensionConfig config;
|
||||
HILOG_INFO("modal picker: will CreateModalUIExtension by extType: %{public}s, pickerType: %{public}s",
|
||||
HILOG_INFO("[picker]: will CreateModalUIExtension by extType: %{public}s, pickerType: %{public}s",
|
||||
targetType.c_str(), pickerType.c_str());
|
||||
int sessionId = uiContent->CreateModalUIExtension(request, extensionCallback, config);
|
||||
if (sessionId == 0) {
|
||||
HILOG_ERROR("modal picker: create modalUIExtension failed");
|
||||
HILOG_ERROR("[picker]: create modalUIExtension failed");
|
||||
return nullptr;
|
||||
}
|
||||
callback->SetSessionId(sessionId);
|
||||
@ -225,22 +310,29 @@ template <class AsyncContext>
|
||||
static napi_status AsyncContextSetStaticObjectInfo(napi_env env, napi_callback_info info,
|
||||
AsyncContext &asyncContext, const size_t minArgs, const size_t maxArgs)
|
||||
{
|
||||
HILOG_INFO("modal picker: AsyncContextSetStaticObjectInfo begin.");
|
||||
HILOG_INFO("[picker]: AsyncContextSetStaticObjectInfo begin.");
|
||||
napi_value thisVar = nullptr;
|
||||
asyncContext->argc = maxArgs;
|
||||
napi_status ret = napi_get_cb_info(env, info, &asyncContext->argc, &(asyncContext->argv[ARGS_ZERO]),
|
||||
&thisVar, nullptr);
|
||||
if (ret != napi_ok) {
|
||||
HILOG_ERROR("modal picker: Failed to get cb info");
|
||||
HILOG_ERROR("[picker]: Failed to get cb info");
|
||||
return ret;
|
||||
}
|
||||
if (asyncContext->argc == ARGS_THREE) {
|
||||
int res = GetCustomShowingWindow(env, asyncContext, info, window_);
|
||||
if (res != ERR_OK) {
|
||||
HILOG_ERROR("[picker] Failed to get cb window_ info.");
|
||||
return napi_invalid_arg;
|
||||
}
|
||||
}
|
||||
if (!((asyncContext->argc >= minArgs) && (asyncContext->argc <= maxArgs))) {
|
||||
HILOG_ERROR("modal picker: Number of args is invalid");
|
||||
HILOG_ERROR("[picker]: Number of args is invalid");
|
||||
return napi_invalid_arg;
|
||||
}
|
||||
if (minArgs > 0) {
|
||||
if (asyncContext->argv[ARGS_ZERO] == nullptr) {
|
||||
HILOG_ERROR("modal picker: Argument list is empty");
|
||||
HILOG_ERROR("[picker]: Argument list is empty");
|
||||
return napi_invalid_arg;
|
||||
}
|
||||
}
|
||||
@ -250,12 +342,13 @@ static napi_status AsyncContextSetStaticObjectInfo(napi_env env, napi_callback_i
|
||||
static napi_value ParseArgsStartModalPicker(napi_env env, napi_callback_info info,
|
||||
unique_ptr<PickerAsyncContext> &context)
|
||||
{
|
||||
HILOG_INFO("modal picker: ParseArgsStartModalPicker begin.");
|
||||
HILOG_INFO("[picker]: ParseArgsStartModalPicker begin.");
|
||||
constexpr size_t minArgs = ARGS_TWO;
|
||||
constexpr size_t maxArgs = ARGS_THREE;
|
||||
napi_status status = AsyncContextSetStaticObjectInfo(env, info, context, minArgs, maxArgs);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("modal picker: AsyncContextSetStaticObjectInfo faild");
|
||||
HILOG_ERROR("[picker]: AsyncContextSetStaticObjectInfo faild");
|
||||
return nullptr;
|
||||
}
|
||||
napi_value result = nullptr;
|
||||
napi_value ret = StartPickerExtension(env, info, context);
|
||||
@ -268,7 +361,7 @@ static napi_value ParseArgsStartModalPicker(napi_env env, napi_callback_info inf
|
||||
|
||||
napi_value PickerNExporter::StartModalPicker(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_INFO("modal picker: StartModalPicker begin.");
|
||||
HILOG_INFO("[picker]: StartModalPicker begin.");
|
||||
unique_ptr<PickerAsyncContext> asyncContext = make_unique<PickerAsyncContext>();
|
||||
napi_value ret = ParseArgsStartModalPicker(env, info, asyncContext);
|
||||
if (ret == nullptr) {
|
||||
|
Loading…
Reference in New Issue
Block a user