1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "js_ability.h"
17
18 #include <cstdlib>
19
20 #include "log_print.h"
21
22 namespace OHOS {
23 namespace PreferencesJsKit {
24 namespace JSAbility {
GetContextMode(napi_env env,napi_value value)25 CONTEXT_MODE GetContextMode(napi_env env, napi_value value)
26 {
27 return STAGE;
28 }
29
GetContextInfo(napi_env env,napi_value value,const std::string & dataGroupId,ContextInfo & contextInfo)30 std::shared_ptr<JSError> GetContextInfo(napi_env env, napi_value value,
31 const std::string &dataGroupId, ContextInfo &contextInfo)
32 {
33 if (!dataGroupId.empty()) {
34 return std::make_shared<InnerError>(E_NOT_SUPPORTED);
35 }
36 std::string baseDir = "";
37 #ifdef WINDOWS_PLATFORM
38 baseDir = getenv("TEMP");
39 if (!baseDir.empty()) {
40 contextInfo.preferencesDir = baseDir + "\\HuaweiDevEcoStudioPreferences";
41 }
42 #endif
43
44 #ifdef MAC_PLATFORM
45 baseDir = getenv("LOGNAME");
46 if (!baseDir.empty()) {
47 baseDir = "/Users/" + baseDir + "/Library/Caches";
48 contextInfo.preferencesDir = baseDir + "/HuaweiDevEcoStudioPreferences";
49 }
50 #endif
51 return nullptr;
52 }
53 } // namespace JSAbility
54 } // namespace PreferencesJsKit
55 } // namespace OHOS
56