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 #include "napi_preferences_error.h"
22
23 namespace OHOS {
24 namespace PreferencesJsKit {
IsStageContext(napi_env env,napi_value value,bool & isStageMode)25 napi_status JSAbility::IsStageContext(napi_env env, napi_value value, bool &isStageMode)
26 {
27 isStageMode = true;
28 return napi_ok;
29 }
30
GetContextInfo(napi_env env,napi_value value,const std::string & dataGroupId,const bool & isStageMode,ContextInfo & contextInfo)31 int JSAbility::GetContextInfo(napi_env env, napi_value value, const std::string &dataGroupId, const bool &isStageMode,
32 ContextInfo &contextInfo)
33 {
34 if (!dataGroupId.empty()) {
35 return NativePreferences::E_NOT_SUPPORTED;
36 }
37 std::string baseDir = "";
38 #ifdef WINDOWS_PLATFORM
39 baseDir = getenv("TEMP");
40 if (!baseDir.empty()) {
41 contextInfo.preferencesDir = baseDir + "\\HuaweiDevEcoStudioPreferences";
42 }
43 #endif
44
45 #ifdef MAC_PLATFORM
46 baseDir = getenv("LOGNAME");
47 if (!baseDir.empty()) {
48 baseDir = "/Users/" + baseDir + "/Library/Caches";
49 contextInfo.preferencesDir = baseDir + "/HuaweiDevEcoStudioPreferences";
50 }
51 #endif
52 return OK;
53 }
54 } // namespace PreferencesJsKit
55 } // namespace OHOS
56