@tarojs/plugin-platform-harmony-cpp 4.1.0 → 4.1.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (223) hide show
  1. package/dist/index.js +1237 -0
  2. package/dist/runtime/apis/apis.ts +20 -0
  3. package/dist/runtime/apis/base/crypto.ts +4 -0
  4. package/dist/runtime/apis/base/debug.ts +5 -0
  5. package/dist/runtime/apis/base/index.ts +13 -0
  6. package/dist/runtime/apis/base/performance.ts +8 -0
  7. package/dist/runtime/apis/base/system.ts +181 -0
  8. package/dist/runtime/apis/base/update.ts +5 -0
  9. package/dist/runtime/apis/base/weapp/app-event.ts +75 -0
  10. package/dist/runtime/apis/base/weapp/life-cycle.ts +21 -0
  11. package/dist/runtime/apis/canvas/index.ts +27 -0
  12. package/dist/runtime/apis/data-analysis/index.ts +6 -0
  13. package/dist/runtime/apis/device/accelerometer.ts +79 -0
  14. package/dist/runtime/apis/device/accessibility.ts +4 -0
  15. package/dist/runtime/apis/device/battery.ts +24 -0
  16. package/dist/runtime/apis/device/bluetooth-ble.ts +19 -0
  17. package/dist/runtime/apis/device/bluetooth-peripheral.ts +6 -0
  18. package/dist/runtime/apis/device/bluetooth.ts +16 -0
  19. package/dist/runtime/apis/device/calendar.ts +5 -0
  20. package/dist/runtime/apis/device/clipboard.ts +85 -0
  21. package/dist/runtime/apis/device/compass.ts +21 -0
  22. package/dist/runtime/apis/device/contact.ts +5 -0
  23. package/dist/runtime/apis/device/crypto.ts +4 -0
  24. package/dist/runtime/apis/device/gyroscope.ts +77 -0
  25. package/dist/runtime/apis/device/iBeacon.ts +10 -0
  26. package/dist/runtime/apis/device/index.ts +24 -0
  27. package/dist/runtime/apis/device/keyboard.ts +63 -0
  28. package/dist/runtime/apis/device/memory.ts +11 -0
  29. package/dist/runtime/apis/device/motion.ts +6 -0
  30. package/dist/runtime/apis/device/network.ts +123 -0
  31. package/dist/runtime/apis/device/nfc.ts +10 -0
  32. package/dist/runtime/apis/device/phone.ts +44 -0
  33. package/dist/runtime/apis/device/scan.ts +4 -0
  34. package/dist/runtime/apis/device/screen.ts +80 -0
  35. package/dist/runtime/apis/device/sms.ts +4 -0
  36. package/dist/runtime/apis/device/vibrate.ts +32 -0
  37. package/dist/runtime/apis/device/wifi.ts +15 -0
  38. package/dist/runtime/apis/ext/index.ts +5 -0
  39. package/dist/runtime/apis/files/index.ts +136 -0
  40. package/dist/runtime/apis/files/manager.ts +942 -0
  41. package/dist/runtime/apis/framework/index.ts +48 -0
  42. package/dist/runtime/apis/harmony/task-pool.ts +39 -0
  43. package/dist/runtime/apis/index.ts +61 -0
  44. package/dist/runtime/apis/location/index.ts +133 -0
  45. package/dist/runtime/apis/media/EditorContext.ts +32 -0
  46. package/dist/runtime/apis/media/audio/index.ts +36 -0
  47. package/dist/runtime/apis/media/background-audio/index.ts +16 -0
  48. package/dist/runtime/apis/media/camera.ts +16 -0
  49. package/dist/runtime/apis/media/common.ts +58 -0
  50. package/dist/runtime/apis/media/image/index.ts +291 -0
  51. package/dist/runtime/apis/media/index.ts +13 -0
  52. package/dist/runtime/apis/media/live.ts +5 -0
  53. package/dist/runtime/apis/media/map.ts +4 -0
  54. package/dist/runtime/apis/media/media-recorder.ts +4 -0
  55. package/dist/runtime/apis/media/recorder.ts +6 -0
  56. package/dist/runtime/apis/media/video/VideoContext.ts +67 -0
  57. package/dist/runtime/apis/media/video/index.ts +45 -0
  58. package/dist/runtime/apis/media/video-decoder.ts +4 -0
  59. package/dist/runtime/apis/media/video-processing.ts +4 -0
  60. package/dist/runtime/apis/media/voip.ts +19 -0
  61. package/dist/runtime/apis/navigate/index.ts +8 -0
  62. package/dist/runtime/apis/network/downloadFile.ts +85 -0
  63. package/dist/runtime/apis/network/index.ts +7 -0
  64. package/dist/runtime/apis/network/mdns.ts +13 -0
  65. package/dist/runtime/apis/network/request.ts +140 -0
  66. package/dist/runtime/apis/network/tcp.ts +4 -0
  67. package/dist/runtime/apis/network/udp.ts +4 -0
  68. package/dist/runtime/apis/network/uploadFile.ts +105 -0
  69. package/dist/runtime/apis/network/webSocket.ts +126 -0
  70. package/dist/runtime/apis/open-api/account.ts +4 -0
  71. package/dist/runtime/apis/open-api/address.ts +4 -0
  72. package/dist/runtime/apis/open-api/authorize.ts +5 -0
  73. package/dist/runtime/apis/open-api/card.ts +5 -0
  74. package/dist/runtime/apis/open-api/channels-live.ts +11 -0
  75. package/dist/runtime/apis/open-api/customer-service.ts +4 -0
  76. package/dist/runtime/apis/open-api/device-voip.ts +5 -0
  77. package/dist/runtime/apis/open-api/facial.ts +7 -0
  78. package/dist/runtime/apis/open-api/favorites.ts +5 -0
  79. package/dist/runtime/apis/open-api/group.ts +4 -0
  80. package/dist/runtime/apis/open-api/index.ts +21 -0
  81. package/dist/runtime/apis/open-api/invoice.ts +5 -0
  82. package/dist/runtime/apis/open-api/license-plate.ts +4 -0
  83. package/dist/runtime/apis/open-api/login.ts +6 -0
  84. package/dist/runtime/apis/open-api/my-miniprogram.ts +4 -0
  85. package/dist/runtime/apis/open-api/privacy.ts +7 -0
  86. package/dist/runtime/apis/open-api/red-package.ts +4 -0
  87. package/dist/runtime/apis/open-api/settings.ts +5 -0
  88. package/dist/runtime/apis/open-api/soter.ts +6 -0
  89. package/dist/runtime/apis/open-api/subscribe-message.ts +6 -0
  90. package/dist/runtime/apis/open-api/user-info.ts +70 -0
  91. package/dist/runtime/apis/open-api/werun.ts +5 -0
  92. package/dist/runtime/apis/payment/index.ts +6 -0
  93. package/dist/runtime/apis/route/index.ts +88 -0
  94. package/dist/runtime/apis/share/index.ts +33 -0
  95. package/dist/runtime/apis/storage/background-fetch.ts +7 -0
  96. package/dist/runtime/apis/storage/cache-manager.ts +4 -0
  97. package/dist/runtime/apis/storage/index.ts +203 -0
  98. package/dist/runtime/apis/ui/animation/animation.ts +264 -0
  99. package/dist/runtime/apis/ui/animation/index.ts +7 -0
  100. package/dist/runtime/apis/ui/background.ts +20 -0
  101. package/dist/runtime/apis/ui/custom-component.ts +1 -0
  102. package/dist/runtime/apis/ui/fonts.ts +4 -0
  103. package/dist/runtime/apis/ui/index.ts +12 -0
  104. package/dist/runtime/apis/ui/interaction/index.ts +198 -0
  105. package/dist/runtime/apis/ui/menu.ts +4 -0
  106. package/dist/runtime/apis/ui/navigation-bar/index.ts +72 -0
  107. package/dist/runtime/apis/ui/pull-down-refresh.ts +47 -0
  108. package/dist/runtime/apis/ui/scroll/index.ts +82 -0
  109. package/dist/runtime/apis/ui/sticky.ts +4 -0
  110. package/dist/runtime/apis/ui/tab-bar.ts +144 -0
  111. package/dist/runtime/apis/ui/window.ts +20 -0
  112. package/dist/runtime/apis/utils/constant.ts +1 -0
  113. package/dist/runtime/apis/utils/handler.ts +117 -0
  114. package/dist/runtime/apis/utils/index.ts +105 -0
  115. package/dist/runtime/apis/utils/permissions.ts +6 -0
  116. package/dist/runtime/apis/utils/types.ts +12 -0
  117. package/dist/runtime/apis/utils/unit.ts +104 -0
  118. package/dist/runtime/apis/utils/validate.ts +87 -0
  119. package/dist/runtime/apis/worker/index.ts +4 -0
  120. package/dist/runtime/apis/wxml/index.ts +17 -0
  121. package/dist/runtime/apis/wxml/intersectionObserver.ts +100 -0
  122. package/dist/runtime/apis/wxml/nodesRef.ts +58 -0
  123. package/dist/runtime/apis/wxml/selectorQuery.ts +221 -0
  124. package/dist/runtime/apischunk/index.d.ts +802 -0
  125. package/dist/runtime/apischunk/index.js +5054 -0
  126. package/dist/runtime/components/deprecated.ets +43 -0
  127. package/dist/runtime/components/index.ets +49 -0
  128. package/dist/runtime/components/innerHtml.ets +16 -0
  129. package/dist/runtime/components/navigationBar.ets +65 -0
  130. package/dist/runtime/components/pageMeta.ets +94 -0
  131. package/dist/runtime/components/richText.ets +24 -0
  132. package/dist/runtime/components/slider.ets +119 -0
  133. package/dist/runtime/components/style.ets +286 -0
  134. package/dist/runtime/components/switch.ets +73 -0
  135. package/dist/runtime/components/tag.ts +58 -0
  136. package/dist/runtime/components/utils/AttributeManager.ets +252 -0
  137. package/dist/runtime/components/utils/DynamicCenter.ts +41 -0
  138. package/dist/runtime/components/utils/constant/event.ets +25 -0
  139. package/dist/runtime/components/utils/constant/style.ets +91 -0
  140. package/dist/runtime/components/utils/events.ts +26 -0
  141. package/dist/runtime/components/utils/flexManager.ets +49 -0
  142. package/dist/runtime/components/utils/helper.ets +51 -0
  143. package/dist/runtime/components/utils/htmlParser/HarmonyHTMLParser.ts +100 -0
  144. package/dist/runtime/components/utils/htmlParser/index.ts +58 -0
  145. package/dist/runtime/components/utils/index.ts +77 -0
  146. package/dist/runtime/components/utils/styles.ets +41 -0
  147. package/dist/runtime/components/video.ets +119 -0
  148. package/dist/runtime/components/webView.ets +55 -0
  149. package/dist/runtime/components/xComponent.ets +89 -0
  150. package/dist/runtime/framework/app.ts +248 -0
  151. package/dist/runtime/framework/connect.ts +24 -0
  152. package/dist/runtime/framework/constant.ts +3 -0
  153. package/dist/runtime/framework/hooks.ts +99 -0
  154. package/dist/runtime/framework/index.ts +15 -0
  155. package/dist/runtime/framework/native-page.ts +511 -0
  156. package/dist/runtime/framework/page.ts +256 -0
  157. package/dist/runtime/framework/utils/index.ts +17 -0
  158. package/dist/runtime/framework/utils/is.ts +26 -0
  159. package/dist/runtime/framework-reconciler/componentTree.ts +81 -0
  160. package/dist/runtime/framework-reconciler/constant.ts +86 -0
  161. package/dist/runtime/framework-reconciler/domInput.ts +90 -0
  162. package/dist/runtime/framework-reconciler/event.ts +108 -0
  163. package/dist/runtime/framework-reconciler/index.ts +99 -0
  164. package/dist/runtime/framework-reconciler/inputValueTracking.ts +106 -0
  165. package/dist/runtime/framework-reconciler/props.ts +132 -0
  166. package/dist/runtime/framework-reconciler/reconciler.ts +202 -0
  167. package/dist/runtime/framework-reconciler/render.ts +139 -0
  168. package/dist/runtime/framework-reconciler/workTags.ts +53 -0
  169. package/dist/runtime/runtime-cpp/bom/URL.ts +2 -0
  170. package/dist/runtime/runtime-cpp/bom/document.ts +45 -0
  171. package/dist/runtime/runtime-cpp/bom/history.ts +1 -0
  172. package/dist/runtime/runtime-cpp/bom/location.ts +1 -0
  173. package/dist/runtime/runtime-cpp/bom/navigator.ts +1 -0
  174. package/dist/runtime/runtime-cpp/bom/raf.ts +1 -0
  175. package/dist/runtime/runtime-cpp/bom/window.ts +57 -0
  176. package/dist/runtime/runtime-cpp/constant.ts +29 -0
  177. package/dist/runtime/runtime-cpp/current.ts +48 -0
  178. package/dist/runtime/runtime-cpp/dom/class-list.ts +41 -0
  179. package/dist/runtime/runtime-cpp/dom/comment.ts +9 -0
  180. package/dist/runtime/runtime-cpp/dom/dataSource.ts +87 -0
  181. package/dist/runtime/runtime-cpp/dom/document.ts +113 -0
  182. package/dist/runtime/runtime-cpp/dom/element/canvas.ts +285 -0
  183. package/dist/runtime/runtime-cpp/dom/element/element.ts +262 -0
  184. package/dist/runtime/runtime-cpp/dom/element/form.ts +371 -0
  185. package/dist/runtime/runtime-cpp/dom/element/index.ts +129 -0
  186. package/dist/runtime/runtime-cpp/dom/element/movable.ts +250 -0
  187. package/dist/runtime/runtime-cpp/dom/element/normal.ts +123 -0
  188. package/dist/runtime/runtime-cpp/dom/element/scroll_view.ts +32 -0
  189. package/dist/runtime/runtime-cpp/dom/element/text.ts +9 -0
  190. package/dist/runtime/runtime-cpp/dom/element/video.ts +66 -0
  191. package/dist/runtime/runtime-cpp/dom/element/web_view.ts +72 -0
  192. package/dist/runtime/runtime-cpp/dom/event-source.ts +1 -0
  193. package/dist/runtime/runtime-cpp/dom/event.ts +187 -0
  194. package/dist/runtime/runtime-cpp/dom/eventTarget.ts +81 -0
  195. package/dist/runtime/runtime-cpp/dom/node.ts +307 -0
  196. package/dist/runtime/runtime-cpp/dom/style.ts +44 -0
  197. package/dist/runtime/runtime-cpp/dom/stylesheet/index.ts +379 -0
  198. package/dist/runtime/runtime-cpp/dom/stylesheet/type.ts +212 -0
  199. package/dist/runtime/runtime-cpp/dom/stylesheet/util.ts +186 -0
  200. package/dist/runtime/runtime-cpp/emitter/emitter.ts +29 -0
  201. package/dist/runtime/runtime-cpp/env.ts +1 -0
  202. package/dist/runtime/runtime-cpp/harmony-library.ts +1 -0
  203. package/dist/runtime/runtime-cpp/index.ts +79 -0
  204. package/dist/runtime/runtime-cpp/interface/event.ts +10 -0
  205. package/dist/runtime/runtime-cpp/interface/index.ts +7 -0
  206. package/dist/runtime/runtime-cpp/next-tick.ts +14 -0
  207. package/dist/runtime/runtime-cpp/system.ts +213 -0
  208. package/dist/runtime/runtime-cpp/utils/index.ts +63 -0
  209. package/dist/runtime/runtime-cpp/utils/info.ts +123 -0
  210. package/dist/runtime/runtime-cpp/utils/page.ts +12 -0
  211. package/dist/runtime/runtime-cpp/utils/router.ts +1 -0
  212. package/dist/runtime/runtime-harmony/apis/helper.ets +33 -0
  213. package/dist/runtime/runtime-harmony/apis/network/common.ets +41 -0
  214. package/dist/runtime/runtime-harmony/apis/network/downloadFile.ets +327 -0
  215. package/dist/runtime/runtime-harmony/apis/network/index.ets +58 -0
  216. package/dist/runtime/runtime-harmony/apis/network/request.ets +206 -0
  217. package/dist/runtime/runtime-harmony/apis/network/uploadFile.ets +190 -0
  218. package/dist/runtime/runtime-harmony/apis/route.ets +110 -0
  219. package/dist/runtime/runtime-harmony/apis/taskpool.ets +149 -0
  220. package/dist/runtime/runtime-harmony/index.ets +41 -0
  221. package/dist/runtime/runtime-harmony/utils.ts +53 -0
  222. package/package.json +24 -23
  223. package/LICENSE +0 -174
@@ -0,0 +1,77 @@
1
+ import sensor from '@ohos.sensor'
2
+
3
+ import { CallbackManager, MethodHandler } from '../utils/handler'
4
+
5
+ import type Taro from '@tarojs/taro/types'
6
+
7
+ const callbackManager = new CallbackManager()
8
+ let devicemotionListener
9
+
10
+ /**
11
+ * 停止监听加速度数据。
12
+ */
13
+ export const stopGyroscope: typeof Taro.stopGyroscope = ({ success, fail, complete } = {}) => {
14
+ const res: Partial<TaroGeneral.CallbackResult> = {}
15
+ const handle = new MethodHandler({ name: 'stopGyroscope', success, fail, complete })
16
+ try {
17
+ sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, devicemotionListener)
18
+ return handle.success(res)
19
+ } catch (e) {
20
+ res.errMsg = e.message
21
+ return handle.fail(res)
22
+ }
23
+ }
24
+
25
+ const INTERVAL_MAP = {
26
+ game: {
27
+ interval: 20 * 1000 * 1000,
28
+ frequency: 50
29
+ },
30
+ ui: {
31
+ interval: 60 * 1000 * 1000,
32
+ frequency: 16.67
33
+ },
34
+ normal: {
35
+ interval: 200 * 1000 * 1000,
36
+ frequency: 5
37
+ }
38
+ }
39
+
40
+ /**
41
+ * 开始监听加速度数据。
42
+ */
43
+ export const startGyroscope: typeof Taro.startGyroscope = ({ interval = 'normal', success, fail, complete } = {}) => {
44
+ const handle = new MethodHandler({ name: 'startGyroscope', success, fail, complete })
45
+ try {
46
+ const intervalObj = INTERVAL_MAP[interval]
47
+ if (devicemotionListener) {
48
+ stopGyroscope()
49
+ }
50
+ sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, (data) => {
51
+ callbackManager.trigger({
52
+ x: data?.x || 0,
53
+ y: data?.y || 0,
54
+ z: data?.z || 0
55
+ })
56
+ }, {
57
+ interval: intervalObj.interval,
58
+ })
59
+ return handle.success()
60
+ } catch (e) {
61
+ return handle.fail({ errMsg: e.message })
62
+ }
63
+ }
64
+
65
+ /**
66
+ * 监听加速度数据事件。频率根据 Taro.startGyroscope() 的 interval 参数。可使用 Taro.stopGyroscope() 停止监听。
67
+ */
68
+ export const onGyroscopeChange: typeof Taro.onGyroscopeChange = callback => {
69
+ callbackManager.add(callback)
70
+ }
71
+
72
+ /**
73
+ * 取消监听加速度数据事件,参数为空,则取消所有的事件监听
74
+ */
75
+ export const offGyroscopeChange: typeof Taro.offGyroscopeChange = callback => {
76
+ callbackManager.remove(callback)
77
+ }
@@ -0,0 +1,10 @@
1
+ import { temporarilyNotSupport } from '../utils'
2
+
3
+ // 蓝牙-信标(Beacon)
4
+ export const stopBeaconDiscovery = /* @__PURE__ */ temporarilyNotSupport('stopBeaconDiscovery')
5
+ export const startBeaconDiscovery = /* @__PURE__ */ temporarilyNotSupport('startBeaconDiscovery')
6
+ export const onBeaconUpdate = /* @__PURE__ */ temporarilyNotSupport('onBeaconUpdate')
7
+ export const onBeaconServiceChange = /* @__PURE__ */ temporarilyNotSupport('onBeaconServiceChange')
8
+ export const offBeaconUpdate = /* @__PURE__ */ temporarilyNotSupport('offBeaconUpdate')
9
+ export const offBeaconServiceChange = /* @__PURE__ */ temporarilyNotSupport('offBeaconServiceChange')
10
+ export const getBeacons = /* @__PURE__ */ temporarilyNotSupport('getBeacons')
@@ -0,0 +1,24 @@
1
+ export * from './accelerometer'
2
+ export * from './accessibility'
3
+ export * from './battery'
4
+ export * from './bluetooth'
5
+ export * from './bluetooth-ble'
6
+ export * from './bluetooth-peripheral'
7
+ export * from './calendar'
8
+ export * from './clipboard'
9
+ export * from './compass'
10
+ export * from './contact'
11
+ export * from './crypto'
12
+ export * from './gyroscope'
13
+ export * from './iBeacon'
14
+ export * from './keyboard'
15
+ export * from './memory'
16
+ export * from './motion'
17
+ export * from './network'
18
+ export * from './nfc'
19
+ export * from './phone'
20
+ export * from './scan'
21
+ export * from './screen'
22
+ export * from './sms'
23
+ export * from './vibrate'
24
+ export * from './wifi'
@@ -0,0 +1,63 @@
1
+ import inputMethodEngine from '@ohos.inputMethodEngine'
2
+ import { Current, window } from '@tarojs/runtime'
3
+
4
+ import { temporarilyNotSupport } from '../utils'
5
+ import { CallbackManager, MethodHandler } from '../utils/handler'
6
+
7
+ import type Taro from '@tarojs/taro/types'
8
+
9
+ const callbackManager = new CallbackManager()
10
+
11
+ const resizeListener = (height) => {
12
+ callbackManager.trigger({
13
+ height: px2vp(height)
14
+ })
15
+ }
16
+
17
+ let topWindow: ReturnType<typeof window.__ohos.getLastWindow>
18
+
19
+ export const onKeyboardHeightChange: typeof Taro.onKeyboardHeightChange = callback => {
20
+ callbackManager.add(callback)
21
+ if (callbackManager.count() === 1) {
22
+ Current.contextPromise
23
+ .then(context => {
24
+ const win = window.__ohos.getLastWindow(context)
25
+ win.then(mainWindow => {
26
+ topWindow = mainWindow
27
+ topWindow.on('keyboardHeightChange', resizeListener)
28
+ })
29
+ })
30
+ }
31
+ }
32
+
33
+ export const offKeyboardHeightChange: typeof Taro.offKeyboardHeightChange = callback => {
34
+ callbackManager.remove(callback)
35
+ if (callbackManager.count() === 0) {
36
+ topWindow?.off('keyboardHeightChange', resizeListener)
37
+ }
38
+ }
39
+
40
+ // @ts-ignore
41
+ let keyboardController: inputMethodEngine.KeyboardController
42
+ inputMethodEngine.getInputMethodAbility()
43
+ // FIXME 当前事件无效,等待鸿蒙方面沟通
44
+ .on('inputStart', (kbController) => {
45
+ keyboardController = kbController
46
+ })
47
+
48
+ export const hideKeyboard: typeof Taro.hideKeyboard = function (options) {
49
+ const { success, fail, complete } = options || {}
50
+ const handle = new MethodHandler({ name: 'hideKeyboard', success, fail, complete })
51
+ return new Promise((resolve, reject) => {
52
+ keyboardController?.hide((err) => {
53
+ if (err) {
54
+ return handle.fail({
55
+ errMsg: err,
56
+ }, { resolve, reject })
57
+ }
58
+ return handle.success({}, { resolve, reject })
59
+ })
60
+ })
61
+ }
62
+
63
+ export const getSelectedTextRange = /* @__PURE__ */ temporarilyNotSupport('getSelectedTextRange')
@@ -0,0 +1,11 @@
1
+ import { hooks } from '@tarojs/runtime'
2
+
3
+ export const onMemoryWarning = (listener) => {
4
+ hooks.tap('getMemoryLevel', (res) => {
5
+ listener(res)
6
+ })
7
+ }
8
+
9
+ export const offMemoryWarning = (listener) => {
10
+ hooks.off('getMemoryLevel', listener)
11
+ }
@@ -0,0 +1,6 @@
1
+ import { temporarilyNotSupport } from '../utils'
2
+
3
+ export const stopDeviceMotionListening = temporarilyNotSupport('stopDeviceMotionListening')
4
+ export const startDeviceMotionListening = temporarilyNotSupport('startDeviceMotionListening')
5
+ export const onDeviceMotionChange = temporarilyNotSupport('onDeviceMotionChange')
6
+ export const offDeviceMotionChange = temporarilyNotSupport('offDeviceMotionChange')
@@ -0,0 +1,123 @@
1
+ import connection from '@ohos.net.connection'
2
+
3
+ import { temporarilyNotSupport } from '../utils'
4
+ import { CallbackManager, MethodHandler } from '../utils/handler'
5
+
6
+ import type Taro from '@tarojs/taro/types'
7
+
8
+ const netCon = connection.createNetConnection()
9
+
10
+ function getNetworkValue () {
11
+ let networkType = 'unknown'
12
+ let metered = false
13
+ const netHandle = connection.getDefaultNetSync()
14
+ const getNetCapabilitiesSync = connection.getNetCapabilitiesSync(netHandle)
15
+ if (getNetCapabilitiesSync) {
16
+ const { networkCap = [], bearerTypes = [] } = getNetCapabilitiesSync
17
+
18
+ switch (bearerTypes[0]) {
19
+ case connection.NetBearType.BEARER_CELLULAR:
20
+ networkType = '4g'
21
+ break
22
+ case connection.NetBearType.BEARER_WIFI:
23
+ networkType = 'WiFi'
24
+ break
25
+ case connection.NetBearType.BEARER_ETHERNET:
26
+ networkType = '4g'
27
+ break
28
+ case connection.NetBearType.BEARER_VPN:
29
+ networkType = 'VPN'
30
+ break
31
+ default:
32
+ networkType = 'unknown'
33
+ break
34
+ }
35
+ metered = !networkCap.find(item => item === connection.NetCap.NET_CAPABILITY_NOT_METERED)
36
+ }
37
+
38
+ return { networkType, metered }
39
+ }
40
+
41
+ export const getNetworkType: typeof Taro.getNetworkType = (options = {}) => {
42
+ const { success, fail, complete } = options
43
+ const handle = new MethodHandler<Taro.getNetworkType.SuccessCallbackResult & { code: unknown, metered: boolean }>({ name: 'getNetworkType', success, fail, complete })
44
+
45
+ return new Promise((resolve, reject) => {
46
+ connection.getDefaultNet().then((netHandle) => {
47
+ let networkType: any = 'none'
48
+ let metered = false
49
+ if (netHandle.netId !== 0) {
50
+ const res = getNetworkValue()
51
+ networkType = res.networkType
52
+ metered = res.metered
53
+ }
54
+
55
+ return handle.success({
56
+ networkType: networkType || 'unknown',
57
+ metered: metered
58
+ }, { resolve, reject })
59
+ }).catch((error) => {
60
+ return handle.fail({
61
+ errMsg: error || '',
62
+ code: -1
63
+ }, { resolve, reject })
64
+ })
65
+ })
66
+ }
67
+
68
+ const networkStatusManager = new CallbackManager()
69
+
70
+ const networkStatusListener = (error: any) => {
71
+ if (error) {
72
+ return networkStatusManager.trigger({ isConnected: false, networkType: 'none' })
73
+ }
74
+ const res = getNetworkValue()
75
+ const networkType = res.networkType || 'unknown'
76
+ const isConnected = networkType !== 'none'
77
+ const metered = res.metered
78
+ const obj = { isConnected, networkType, metered }
79
+ networkStatusManager.trigger(obj)
80
+ }
81
+
82
+ /**
83
+ * 在最近的八次网络请求中, 出现下列三个现象之一则判定弱网。
84
+ * - 出现三次以上连接超时
85
+ * - 出现三次 rtt 超过 400
86
+ * - 出现三次以上的丢包
87
+ * > 弱网事件通知规则是: 弱网状态变化时立即通知, 状态不变时 30s 内最多通知一次。
88
+ */
89
+ export const onNetworkWeakChange = /* @__PURE__ */ temporarilyNotSupport('onNetworkWeakChange')
90
+
91
+ export const onNetworkStatusChange: typeof Taro.onNetworkStatusChange = callback => {
92
+ const name = 'onNetworkStatusChange'
93
+ const handle = new MethodHandler<Partial<Taro.onNetworkStatusChange.CallbackResult>>({ name, complete: callback })
94
+ try {
95
+ networkStatusManager.add(callback)
96
+ if (networkStatusManager.count() === 1) {
97
+ netCon.register(networkStatusListener)
98
+ }
99
+ } catch (error) {
100
+ handle.fail({
101
+ errMsg: error
102
+ })
103
+ }
104
+ }
105
+
106
+ export const offNetworkWeakChange = /* @__PURE__ */ temporarilyNotSupport('offNetworkWeakChange')
107
+
108
+ export const offNetworkStatusChange: typeof Taro.offNetworkStatusChange = callback => {
109
+ const name = 'offNetworkStatusChange'
110
+ const handle = new MethodHandler<Partial<Taro.onNetworkStatusChange.CallbackResult>>({ name, complete: callback })
111
+ try {
112
+ networkStatusManager.remove(callback)
113
+ if (networkStatusManager.count() === 0) {
114
+ netCon.unregister(networkStatusListener)
115
+ }
116
+ } catch (error) {
117
+ handle.fail({
118
+ errMsg: error
119
+ })
120
+ }
121
+ }
122
+
123
+ export const getLocalIPAddress = /* @__PURE__ */ temporarilyNotSupport('getLocalIPAddress')
@@ -0,0 +1,10 @@
1
+ import { temporarilyNotSupport } from '../utils'
2
+
3
+ // NFC
4
+ export const stopHCE = /* @__PURE__ */ temporarilyNotSupport('stopHCE')
5
+ export const startHCE = /* @__PURE__ */ temporarilyNotSupport('startHCE')
6
+ export const sendHCEMessage = /* @__PURE__ */ temporarilyNotSupport('sendHCEMessage')
7
+ export const onHCEMessage = /* @__PURE__ */ temporarilyNotSupport('onHCEMessage')
8
+ export const offHCEMessage = /* @__PURE__ */ temporarilyNotSupport('offHCEMessage')
9
+ export const getNFCAdapter = /* @__PURE__ */ temporarilyNotSupport('getNFCAdapter')
10
+ export const getHCEState = /* @__PURE__ */ temporarilyNotSupport('getHCEState')
@@ -0,0 +1,44 @@
1
+ // 从 API Version 7 开始支持。
2
+ import call from '@ohos.telephony.call'
3
+ import { isString } from '@tarojs/shared'
4
+
5
+ import { getParameterError, object2String, shouldBeObject } from '../utils'
6
+ import { MethodHandler } from '../utils/handler'
7
+
8
+ import type Taro from '@tarojs/taro/types'
9
+
10
+ export const makePhoneCall: typeof Taro.makePhoneCall = (options) => {
11
+ // options must be an Object
12
+ const isObject = shouldBeObject(options)
13
+ if (!isObject.flag) {
14
+ const res = { errMsg: `makePhoneCall:fail ${isObject.msg}` }
15
+ console.error(res.errMsg)
16
+ return Promise.reject(res)
17
+ }
18
+
19
+ const { phoneNumber, success, fail, complete } = options
20
+ const handle = new MethodHandler({ name: 'makePhoneCall', success, fail, complete })
21
+
22
+ if (!isString(phoneNumber)) {
23
+ return handle.fail({
24
+ errMsg: getParameterError({
25
+ para: 'phoneNumber',
26
+ correct: 'String',
27
+ wrong: phoneNumber
28
+ })
29
+ })
30
+ }
31
+
32
+ return new Promise((resolve, reject) => {
33
+ call.makeCall(phoneNumber, err => {
34
+ if (err) {
35
+ console.error('Failed to makePhoneCall. Cause: ' + JSON.stringify(err))
36
+ return handle.fail({
37
+ errMsg: object2String(err)
38
+ }, { resolve, reject })
39
+ } else {
40
+ return handle.success({}, { resolve, reject })
41
+ }
42
+ })
43
+ })
44
+ }
@@ -0,0 +1,4 @@
1
+ import { temporarilyNotSupport } from '../utils'
2
+
3
+ // 扫码
4
+ export const scanCode = /* @__PURE__ */ temporarilyNotSupport('scanCode')
@@ -0,0 +1,80 @@
1
+ // 从API Version 7 开始,该接口不再维护,推荐使用新接口'@ohos.brightness'
2
+ // 但是 新接口 @ohos.brightness 没有 getValue
3
+ import brightness from '@system.brightness'
4
+ import { isNumber } from '@tarojs/shared'
5
+
6
+ import { getParameterError, shouldBeObject, temporarilyNotSupport } from '../utils'
7
+ import { MethodHandler } from '../utils/handler'
8
+
9
+ import type Taro from '@tarojs/taro/types'
10
+
11
+ // 屏幕
12
+ export const setVisualEffectOnCapture = /* @__PURE__ */ temporarilyNotSupport('setVisualEffectOnCapture')
13
+
14
+ export const setScreenBrightness: typeof Taro.setScreenBrightness = function (options) {
15
+ // options must be an Object
16
+ const isObject = shouldBeObject(options)
17
+ if (!isObject.flag) {
18
+ const res = { errMsg: `setScreenBrightness:fail ${isObject.msg}` }
19
+ console.error(res.errMsg)
20
+ return Promise.reject(res)
21
+ }
22
+
23
+ const { value, success, fail, complete } = options
24
+ const handle = new MethodHandler<{ code: unknown }>({ name: 'setScreenBrightness', success, fail, complete })
25
+
26
+ if (!isNumber(value)) {
27
+ return handle.fail({
28
+ errMsg: getParameterError({
29
+ para: 'value',
30
+ correct: 'Number',
31
+ wrong: value
32
+ })
33
+ })
34
+ }
35
+
36
+ return new Promise((resolve, reject) => {
37
+ brightness.setValue({
38
+ // FIXME 不生效
39
+ value: value >= 0 && value <= 1 ? value * 255 : value,
40
+ success: function () {
41
+ return handle.success({}, { resolve, reject })
42
+ },
43
+ fail: function (data, code) {
44
+ return handle.fail({
45
+ errMsg: data || '',
46
+ code
47
+ }, { resolve, reject })
48
+ }
49
+ })
50
+ })
51
+ }
52
+
53
+ export const setKeepScreenOn = /* @__PURE__ */ temporarilyNotSupport('setKeepScreenOn')
54
+ export const onUserCaptureScreen = /* @__PURE__ */ temporarilyNotSupport('onUserCaptureScreen')
55
+ export const offUserCaptureScreen = /* @__PURE__ */ temporarilyNotSupport('offUserCaptureScreen')
56
+
57
+ export const getScreenBrightness: typeof Taro.getScreenBrightness = function (options) {
58
+ const { success, fail, complete } = options || {}
59
+ const handle = new MethodHandler<Taro.getScreenBrightness.SuccessCallbackOption & { code: unknown }>({ name: 'getScreenBrightness', success, fail, complete })
60
+
61
+ return new Promise((resolve, reject) => {
62
+ brightness.getValue({
63
+ success: function (data) {
64
+ return handle.success({
65
+ value: data.value
66
+ }, { resolve, reject })
67
+ },
68
+ fail: function (data, code) {
69
+ return handle.fail({
70
+ errMsg: data || '',
71
+ code
72
+ }, { resolve, reject })
73
+ }
74
+ })
75
+ })
76
+ }
77
+
78
+ export const onScreenRecordingStateChanged = /* @__PURE__ */ temporarilyNotSupport('onScreenRecordingStateChanged')
79
+ export const offScreenRecordingStateChanged = /* @__PURE__ */ temporarilyNotSupport('offScreenRecordingStateChanged')
80
+ export const getScreenRecordingState = /* @__PURE__ */ temporarilyNotSupport('getScreenRecordingState')
@@ -0,0 +1,4 @@
1
+ import { temporarilyNotSupport } from '../utils'
2
+
3
+ // 短信
4
+ export const sendSms = /* @__PURE__ */ temporarilyNotSupport('sendSms')
@@ -0,0 +1,32 @@
1
+ import vibrator from '@ohos.vibrator'
2
+
3
+ import { MethodHandler } from '../utils/handler'
4
+
5
+ import type Taro from '@tarojs/taro/types'
6
+
7
+ const VIBRATOR_LONG_TIME = 400
8
+ const VIBRATOR_SHORT_TIME = 15
9
+
10
+ function vibrateBaseGenerator (duration: number, name = '') {
11
+ return ({ success, fail, complete }: Taro.vibrateLong.Option = {}) => {
12
+ const handle = new MethodHandler({ name, success, fail, complete })
13
+ return new Promise((resolve, reject) => {
14
+ vibrator.startVibration({
15
+ type: 'time',
16
+ duration,
17
+ }, {
18
+ usage: 'unknown'
19
+ }, (error) => {
20
+ if (error) {
21
+ return handle.fail({
22
+ errMsg: `vibrate fail, error.code: ${error.code}; error.message: ${error.message}`
23
+ }, { resolve, reject })
24
+ }
25
+ return handle.success({}, { resolve, reject })
26
+ })
27
+ })
28
+ }
29
+ }
30
+
31
+ export const vibrateLong = vibrateBaseGenerator(VIBRATOR_LONG_TIME, 'vibrateLong')
32
+ export const vibrateShort = vibrateBaseGenerator(VIBRATOR_SHORT_TIME, 'vibrateShort')
@@ -0,0 +1,15 @@
1
+ import { temporarilyNotSupport } from '../utils'
2
+
3
+ // Wi-Fi
4
+ export const stopWifi = /* @__PURE__ */ temporarilyNotSupport('stopWifi')
5
+ export const startWifi = /* @__PURE__ */ temporarilyNotSupport('startWifi')
6
+ export const setWifiList = /* @__PURE__ */ temporarilyNotSupport('setWifiList')
7
+ export const onWifiConnectedWithPartialInfo = /* @__PURE__ */ temporarilyNotSupport('onWifiConnectedWithPartialInfo')
8
+ export const onWifiConnected = /* @__PURE__ */ temporarilyNotSupport('onWifiConnected')
9
+ export const onGetWifiList = /* @__PURE__ */ temporarilyNotSupport('onGetWifiList')
10
+ export const offWifiConnectedWithPartialInfo = /* @__PURE__ */ temporarilyNotSupport('offWifiConnectedWithPartialInfo')
11
+ export const offWifiConnected = /* @__PURE__ */ temporarilyNotSupport('offWifiConnected')
12
+ export const offGetWifiList = /* @__PURE__ */ temporarilyNotSupport('offGetWifiList')
13
+ export const getWifiList = /* @__PURE__ */ temporarilyNotSupport('getWifiList')
14
+ export const getConnectedWifi = /* @__PURE__ */ temporarilyNotSupport('getConnectedWifi')
15
+ export const connectWifi = /* @__PURE__ */ temporarilyNotSupport('connectWifi')
@@ -0,0 +1,5 @@
1
+ import { temporarilyNotSupport } from '../utils'
2
+
3
+ // 第三方平台
4
+ export const getExtConfigSync = /* @__PURE__ */ temporarilyNotSupport('getExtConfigSync')
5
+ export const getExtConfig = /* @__PURE__ */ temporarilyNotSupport('getExtConfig')
@@ -0,0 +1,136 @@
1
+ /**
2
+ * HarmonyOS 文档:
3
+ * https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-fileio-0000001168366687
4
+ *
5
+ * WX 文档:
6
+ * https://developers.weixin.qq.com/miniprogram/dev/api/file/wx.saveFileToDisk.html
7
+ *
8
+ * Taro.js 文档
9
+ * https://taro-docs.jd.com/taro/docs/apis/files/saveFileToDisk
10
+ *
11
+ * HarmonyOS 不支持接口:
12
+ * saveFileToDisk
13
+ *
14
+ * HarmonyOS 差异性接口:
15
+ * openDocument:showMenu、type 选项无效
16
+ * getSavedFileList:返回值 fileList 中的每一项不包含 createTime 属性
17
+ * getSavedFileInfo:返回值不包含 createTime 属性
18
+ */
19
+
20
+ import document from '@ohos.document'
21
+ import fileio from '@ohos.fileio'
22
+
23
+ import { callAsyncFail, callAsyncSuccess, temporarilyNotSupport, validateParams } from '../utils'
24
+ import { getFileSystemManager, validateSavedFilePath } from './manager'
25
+
26
+ import type Taro from '@tarojs/taro/types'
27
+
28
+ const filePathSchema = {
29
+ filePath: 'String'
30
+ }
31
+
32
+ export const saveFileToDisk = temporarilyNotSupport('saveFileToDisk')
33
+
34
+ /**
35
+ * HarmonyOS 不支持 showMenu 选项,并且 type 目前仅支持 *,详情参见:
36
+ * https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-document-0000001168936589#section9616125953711
37
+ */
38
+ export function openDocument (option: Taro.openDocument.Option): Promise<any> {
39
+ return new Promise((resolve, reject) => {
40
+ try {
41
+ validateParams('access', option, filePathSchema)
42
+ } catch (error) {
43
+ const res = { errMsg: error.message }
44
+ return callAsyncFail(reject, res, option)
45
+ }
46
+ document.show(option.filePath, '*', (error) => {
47
+ if (error) {
48
+ const res = { errMsg: error.message ? error.message : error }
49
+ return callAsyncFail(reject, res, option)
50
+ } else {
51
+ callAsyncSuccess(resolve, undefined, option)
52
+ }
53
+ })
54
+ })
55
+ }
56
+
57
+ export function saveFile (option: Taro.saveFile.Option): Promise<any> {
58
+ return new Promise((resolve, reject) => {
59
+ const fileSystemManager = getFileSystemManager()
60
+ fileSystemManager.saveFile({
61
+ tempFilePath: option.tempFilePath,
62
+ filePath: option.filePath,
63
+ success: (res) => {
64
+ callAsyncSuccess(resolve, res, option)
65
+ },
66
+ fail: (res) => {
67
+ callAsyncFail(reject, res, option)
68
+ }
69
+ })
70
+ })
71
+ }
72
+
73
+ export function removeSavedFile (option: Taro.removeSavedFile.Option): Promise<any> {
74
+ return new Promise((resolve, reject) => {
75
+ const fileSystemManager = getFileSystemManager()
76
+ fileSystemManager.removeSavedFile({
77
+ filePath: option.filePath,
78
+ success: (res) => {
79
+ callAsyncSuccess(resolve, res, option)
80
+ },
81
+ fail: (res) => {
82
+ callAsyncFail(reject, res, option)
83
+ }
84
+ })
85
+ })
86
+ }
87
+
88
+ export function getFileInfo (option: Taro.getFileInfo.Option): Promise<Taro.getFileInfo.SuccessCallbackResult | Taro.getFileInfo.FailCallbackResult> {
89
+ return new Promise((resolve, reject) => {
90
+ const fileSystemManager = getFileSystemManager()
91
+ fileSystemManager.getFileInfo({
92
+ filePath: option.filePath,
93
+ success: ({ size }) => {
94
+ fileio.hash(option.filePath, option.digestAlgorithm ?? 'md5').then((digest) => {
95
+ callAsyncSuccess(resolve, { size, digest }, option)
96
+ }).catch((error) => {
97
+ const res = { errMsg: error.message ? error.message : error }
98
+ callAsyncFail(reject, res, option)
99
+ })
100
+ },
101
+ fail: (res) => {
102
+ callAsyncFail(reject, res, option)
103
+ }
104
+ })
105
+ })
106
+ }
107
+
108
+ export function getSavedFileList (option?: Taro.getSavedFileList.Option): Promise<Taro.getSavedFileList.SuccessCallbackResult> {
109
+ return new Promise((resolve, reject) => {
110
+ const fileSystemManager = getFileSystemManager()
111
+ fileSystemManager.getSavedFileList({
112
+ success: (res) => callAsyncSuccess(resolve, res, option),
113
+ fail: (res) => callAsyncFail(reject, res, option)
114
+ })
115
+ })
116
+ }
117
+
118
+ export function getSavedFileInfo (option: Taro.getSavedFileInfo.Option): Promise<Taro.getSavedFileInfo.SuccessCallbackResult> {
119
+ return new Promise((resolve, reject) => {
120
+ try {
121
+ validateParams('getSavedFileInfo', option, filePathSchema)
122
+ validateSavedFilePath(option.filePath)
123
+ } catch (error) {
124
+ const res = { errMsg: error.message }
125
+ return callAsyncFail(reject, res, option)
126
+ }
127
+ const fileSystemManager = getFileSystemManager()
128
+ fileSystemManager.getFileInfo({
129
+ filePath: option.filePath,
130
+ success: ({ size }) => callAsyncSuccess(resolve, { size }, option),
131
+ fail: (res) => callAsyncFail(reject, res, option)
132
+ })
133
+ })
134
+ }
135
+
136
+ export { getFileSystemManager }