• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1//@ts-nocheck
2/*
3 * Copyright (c) 2022 Huawei Device Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import { Log } from '../utils/Log';
18import { DataAbilityHelper } from 'ability/dataAbilityHelper';
19import settings from '@ohos.settings';
20import dataShare from '@ohos.data.dataShare';
21
22const TAG = 'SettingsDataManager'
23/**
24 * Wrapper class for settings interfaces.
25 */
26class SettingsDataManager {
27  private readonly uriShare: string = 'datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=';
28  private dataShareHelper;
29  private constructor() {
30  }
31
32  /**
33   * settingsData manager instance
34   *
35   * @return settingsDataManager instance
36   */
37  static getInstance(): SettingsDataManager {
38    if (globalThis.SettingsDataManagerInstance == null) {
39      globalThis.SettingsDataManagerInstance = new SettingsDataManager();
40    }
41    return globalThis.SettingsDataManagerInstance;
42  }
43
44  public createDataShareHelper() {
45    Log.showInfo(TAG, "createDataShareHelper context:" + globalThis.desktopContext);
46    dataShare.createDataShareHelper(globalThis.desktopContext, this.uriShare)
47      .then((dataHelper) => {
48        Log.showInfo(TAG, "then dataHelper:" + dataHelper);
49        this.dataShareHelper = dataHelper;
50        globalThis.sGestureNavigationManager.getGestureNavigationStatus();
51      })
52  }
53
54  /**
55   * Update settingData by settingDataKey.
56   */
57  setValue(helper: any, settingDataKey: string, value: string): void {
58    Log.showInfo(TAG, "setValue:" + value)
59    settings.setValueSync(globalThis.desktopContext, settingDataKey, value);
60  }
61
62  /**
63   * get settingDataValue by settingDataKey.
64   *
65   * @return settingsDataValue by settingDataKey.
66   */
67  getValue(helper: any, settingDataKey: string, defaultValue: string): string {
68    let value: string = settings.getValueSync(globalThis.desktopContext, settingDataKey, defaultValue);
69    Log.showInfo(TAG, "getValue:" + value);
70    return value;
71  }
72
73  /**
74   * get settingDataUri by settingDataKey.
75   *
76   * @return settingDataUri by settingDataKey.
77   */
78  getUri(settingDataKey: string): string {
79    return this.uriShare + settingDataKey;
80  }
81
82  /**
83   * get settingDataHelper by settingDataKey.
84   *
85   * @return settingDataHelper by settingDataUri.
86   */
87  getHelper(context: any, uri: string): any{
88    // @ts-ignore api8 d.ts
89    return this.dataShareHelper;
90  }
91}
92
93export const settingsDataManager = SettingsDataManager.getInstance();