@react-native-ohos/react-native-background-timer 2.4.2-rc.1

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 (45) hide show
  1. package/.circleci/config.yml +37 -0
  2. package/.eslintignore +1 -0
  3. package/.eslintrc.js +8 -0
  4. package/.prettierrc +4 -0
  5. package/COMMITTERS.md +10 -0
  6. package/LICENSE +21 -0
  7. package/OAT.xml +58 -0
  8. package/README.OpenSource +11 -0
  9. package/README.md +13 -0
  10. package/android/build.gradle +20 -0
  11. package/android/src/main/AndroidManifest.xml +3 -0
  12. package/android/src/main/java/com/ocetnik/timer/BackgroundTimerModule.java +97 -0
  13. package/android/src/main/java/com/ocetnik/timer/BackgroundTimerPackage.java +34 -0
  14. package/harmony/background_timer/Index.ets +9 -0
  15. package/harmony/background_timer/build-profile.json5 +12 -0
  16. package/harmony/background_timer/hvigorfile.ts +6 -0
  17. package/harmony/background_timer/oh-package.json5 +11 -0
  18. package/harmony/background_timer/src/main/cpp/CMakeLists.txt +13 -0
  19. package/harmony/background_timer/src/main/cpp/ReactNativeOhosReactNativeBackgroundTimerPackage.h +15 -0
  20. package/harmony/background_timer/src/main/cpp/generated/RNOH/generated/BaseReactNativeBackgroundTimerPackage.h +75 -0
  21. package/harmony/background_timer/src/main/cpp/generated/RNOH/generated/turbo_modules/BackgroundTimerTurboModule.cpp +21 -0
  22. package/harmony/background_timer/src/main/cpp/generated/RNOH/generated/turbo_modules/BackgroundTimerTurboModule.h +16 -0
  23. package/harmony/background_timer/src/main/ets/BackgroundTimerPackage.ts +30 -0
  24. package/harmony/background_timer/src/main/ets/BackgroundTimerTurboModule.ts +36 -0
  25. package/harmony/background_timer/src/main/ets/BackgroundTimerWorker.ts +17 -0
  26. package/harmony/background_timer/src/main/ets/generated/components/ts.ts +5 -0
  27. package/harmony/background_timer/src/main/ets/generated/index.ets +5 -0
  28. package/harmony/background_timer/src/main/ets/generated/ts.ts +6 -0
  29. package/harmony/background_timer/src/main/ets/generated/turboModules/BackgroundTimerTurboModule.ts +18 -0
  30. package/harmony/background_timer/src/main/ets/generated/turboModules/ts.ts +5 -0
  31. package/harmony/background_timer/src/main/ets/ts.ts +12 -0
  32. package/harmony/background_timer/src/main/module.json5 +11 -0
  33. package/harmony/background_timer/src/main/resources/base/element/string.json +8 -0
  34. package/harmony/background_timer/src/main/resources/en_US/element/string.json +8 -0
  35. package/harmony/background_timer/src/main/resources/zh_CN/element/string.json +8 -0
  36. package/harmony/background_timer/ts.ts +10 -0
  37. package/harmony/background_timer.har +0 -0
  38. package/index.js +111 -0
  39. package/ios/RNBackgroundTimer.h +21 -0
  40. package/ios/RNBackgroundTimer.m +90 -0
  41. package/ios/RNBackgroundTimer.xcodeproj/project.pbxproj +347 -0
  42. package/ios/RNBackgroundTimer.xcodeproj/xcuserdata/jlexyc.xcuserdatad/xcschemes/xcschememanagement.plist +19 -0
  43. package/package.json +65 -0
  44. package/react-native-background-timer.podspec +24 -0
  45. package/src/RNBackgroundTimerSpec.ts +18 -0
@@ -0,0 +1,37 @@
1
+ # Javascript Node CircleCI 2.0 configuration file
2
+ #
3
+ # Check https://circleci.com/docs/2.0/language-javascript/ for more details
4
+ #
5
+ version: 2
6
+ jobs:
7
+ build:
8
+ docker:
9
+ # specify the version you desire here
10
+ - image: circleci/node:10.16
11
+
12
+ # Specify service dependencies here if necessary
13
+ # CircleCI maintains a library of pre-built images
14
+ # documented at https://circleci.com/docs/2.0/circleci-images/
15
+ # - image: circleci/mongo:3.4.4
16
+
17
+ working_directory: ~/repo
18
+
19
+ steps:
20
+ - checkout
21
+
22
+ # Download and cache dependencies
23
+ - restore_cache:
24
+ keys:
25
+ - v1-dependencies-{{ checksum "package.json" }}
26
+ # fallback to using the latest cache if no exact match is found
27
+ - v1-dependencies-
28
+
29
+ - run: yarn install
30
+
31
+ - save_cache:
32
+ paths:
33
+ - node_modules
34
+ key: v1-dependencies-{{ checksum "package.json" }}
35
+
36
+ # run eslint
37
+ - run: yarn eslint
package/.eslintignore ADDED
@@ -0,0 +1 @@
1
+ node_modules
package/.eslintrc.js ADDED
@@ -0,0 +1,8 @@
1
+ module.exports = {
2
+ extends: ['airbnb', 'prettier'],
3
+ plugins: ['import', 'jsx-a11y', 'prettier', 'react', 'react-hooks'],
4
+ rules: {
5
+ 'class-methods-use-this': ['error', { exceptMethods: ['start', 'stop'] }],
6
+ 'prettier/prettier': ['error'],
7
+ },
8
+ };
package/.prettierrc ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "singleQuote": true,
3
+ "trailingComma": "all"
4
+ }
package/COMMITTERS.md ADDED
@@ -0,0 +1,10 @@
1
+ ## Committers列表
2
+
3
+ ### 以下是此项目的committer人员
4
+ 不区分先后顺序
5
+
6
+ - [MaDiXin](https://gitee.com/MaDiXin)
7
+ - [xiafeng_xf_admin](https://gitee.com/xiafeng_xf_admin)
8
+ - [ChenLixi](https://gitee.com/Louis-C7)
9
+ - [LinJiacheng](https://gitee.com/LLLLLLin)
10
+ - [ZhengJinshou](https://gitee.com/longziz)
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Dávid Ocetník
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/OAT.xml ADDED
@@ -0,0 +1,58 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <configuration>
3
+ <oatconfig>
4
+ <licensefile>LICENSE</licensefile>
5
+ <policylist>
6
+ <policy name="projectPolicy" desc="">
7
+ <policyitem type="license" name="MIT" path=".*" desc="license under the MIT"/>
8
+ </policy>
9
+ <policy name="projectPolicy" desc="">
10
+ <policyitem type="compatibility" name="GPL-2.0+" path=".*" desc="Process that runs independently, invoked by the X process."/>
11
+ <policyitem type="compatibility" name="Apache-2.0" path=".*" desc="不影响兼容性"/>
12
+ <policyitem type="compatibility" name="BSDStyleLicense" path=".*" desc="不影响兼容性" />
13
+ <policyitem type="compatibility" name="MIT" path=".*" desc="不影响兼容性" />
14
+ <policyitem type="compatibility" name="GPLStyleLicense" path=".*" desc="不影响兼容性" />
15
+ </policy>
16
+ </policylist>
17
+ <filefilterlist>
18
+ <filefilter name="copyrightPolicyFilter" desc="Filters for compatibility,license header policies">
19
+ <filteritem type="filepath" name="harmony/background_timer/hvigorfile.ts" desc="hvigor构建脚本,DevEco Studio自动生成,不手动修改"/>
20
+ <filteritem type="filepath" name="harmony/background_timer/src/main/cpp/generated/.*" desc="codegen自动生成,不手动修改"/>
21
+ <filteritem type="filepath" name="harmony/background_timer/src/main/ets/generated/.*" desc="codegen自动生成,不手动修改"/>
22
+ <filteritem type="filename" name="*.json5" desc="hvigor配置文件,DevEco Studio自动生成,不手动修改"/>
23
+ <filteritem type="filename" name="*/*.json5" desc="hvigor配置文件,DevEco Studio自动生成,不手动修改"/>
24
+ <filteritem type="filename" name="LICENSE" desc="版权文件,不添加版权头"/>
25
+ <filteritem type="filename" name="NOTICE" desc="NOTICE文件,不添加版权头"/>
26
+ <filteritem type="filepath" name="hvigorw" desc="工程模板,不修改版权头,以防有修改版权风险"/>
27
+ <filteritem type="filepath" name="hvigorw.bat" desc="工程模板,不修改版权头,以防有修改版权风险"/>
28
+ <filteritem type="filepath" name="src/*.js" desc="第三方开源软件源码,不修改版权头,以防有修改版权风险"/>
29
+ <filteritem type="filepath" name="index.*" desc="第三方开源软件源码,不修改版权头,以防有修改版权风险"/>
30
+ <filteritem type="filepath" name="hvigor/hvigor-wrapper.js" desc="工程模板,不修改版权头,以防有修改版权风险"/>
31
+ <filteritem type="filepath" name="hvigor/hvigor-config.json5" desc="工程模板,不修改版权头,以防有修改版权风险"/>
32
+ <filteritem type="filepath" name="README.OpenSource" desc="第三方开源软件源码,不修改版权头,以防有修改版权风险"/>
33
+ </filefilter>
34
+ <filefilter name="defaultPolicyFilter" desc="Filters for compatibility,license header policies">
35
+ <filteritem type="filepath" name="harmony/background_timer/hvigorfile.ts" desc="hvigor构建脚本,DevEco Studio自动生成,不手动修改"/>
36
+ <filteritem type="filepath" name="harmony/background_timer/src/main/cpp/generated/.*" desc="codegen自动生成,不手动修改"/>
37
+ <filteritem type="filepath" name="harmony/background_timer/src/main/ets/generated/.*" desc="codegen自动生成,不手动修改"/>
38
+ <filteritem type="filename" name="*.json5" desc="hvigor配置文件,DevEco Studio自动生成,不手动修改"/>
39
+ <filteritem type="filename" name="*/*.json5" desc="hvigor配置文件,DevEco Studio自动生成,不手动修改"/>
40
+ <filteritem type="filename" name="LICENSE" desc="版权文件,不添加许可证头"/>
41
+ <filteritem type="filename" name="NOTICE" desc="NOTICE文件,不添加许可证头"/>
42
+ <filteritem type="filepath" name="hvigorw" desc="工程模板,不添加许可证头"/>
43
+ <filteritem type="filepath" name="hvigorw.bat" desc="工程模板,不添加许可证头"/>
44
+ <filteritem type="filepath" name="src/*.js" desc="第三方开源软件源码,不修改版权头,以防有修改版权风险"/>
45
+ <filteritem type="filepath" name="index.*" desc="第三方开源软件源码,不修改版权头,以防有修改版权风险"/>
46
+ <filteritem type="filepath" name="hvigor/hvigor-wrapper.js" desc="工程模板,不添加许可证头"/>
47
+ <filteritem type="filepath" name="hvigor/hvigor-config.json5" desc="工程模板,不修改版权头,以防有修改版权风险"/>
48
+ <filteritem type="filepath" name="README.OpenSource" desc="第三方开源软件源码,不修改版权头,以防有修改版权风险"/>
49
+ </filefilter>
50
+
51
+ <filefilter name="binaryFileTypePolicyFilter" desc="Filters for copyright header policies">
52
+ <filteritem type="filename" name="icon.png" desc="项目工程默认图片文件"/>
53
+ <filteritem type="filepath" name="AppScope/resources/base/media/app_icon.png" desc="项目工程默认图片文件"/>
54
+ <filteritem type="filepath" name="harmony/background_timer.har" desc="项目打包文件"/>
55
+ </filefilter>
56
+ </filefilterlist>
57
+ </oatconfig>
58
+ </configuration>
@@ -0,0 +1,11 @@
1
+ [
2
+ {
3
+ "Name": "react-native-background-timer",
4
+ "License": "MIT",
5
+ "License File": "LICENSE",
6
+ "Version Number": "2.4.1",
7
+ "Owner": "xiafeng@huawei.com",
8
+ "Upstream URL": "https://github.com/ocetnik/react-native-background-timer/blob/master/package.json",
9
+ "Description": "Emit event periodically (even when app is in the background).",
10
+ }
11
+ ]
package/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # @react-native-ohos/react-native-background-timer
2
+
3
+ This project is based on [react-native-background-timer](https://github.com/ocetnik/react-native-background-timer)
4
+
5
+ ## Documentation
6
+
7
+ - [中文](https://gitee.com/react-native-oh-library/usage-docs/blob/master/zh-cn/react-native-background-timer.md)
8
+
9
+ - [English](https://gitee.com/react-native-oh-library/usage-docs/blob/master/en/react-native-background-timer.md)
10
+
11
+ ## License
12
+
13
+ This library is licensed under [The MIT License (MIT)](https://gitee.com/openharmony-sig/rntpc_react-native-background-timer/blob/master/LICENSE)
@@ -0,0 +1,20 @@
1
+ apply plugin: 'com.android.library'
2
+
3
+ def safeExtGet(prop, fallback) {
4
+ rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
5
+ }
6
+
7
+ android {
8
+ compileSdkVersion safeExtGet('compileSdkVersion', 28)
9
+
10
+ defaultConfig {
11
+ minSdkVersion safeExtGet('minSdkVersion', 16)
12
+ targetSdkVersion safeExtGet('targetSdkVersion', 28)
13
+ versionCode 1
14
+ versionName "1.0"
15
+ }
16
+ }
17
+
18
+ dependencies {
19
+ implementation 'com.facebook.react:react-native:+'
20
+ }
@@ -0,0 +1,3 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.ocetnik.timer">
2
+ <uses-permission android:name="android.permission.WAKE_LOCK" />
3
+ </manifest>
@@ -0,0 +1,97 @@
1
+ package com.ocetnik.timer;
2
+
3
+ import android.os.Handler;
4
+ import android.os.PowerManager;
5
+
6
+ import com.facebook.react.bridge.LifecycleEventListener;
7
+ import com.facebook.react.bridge.ReactApplicationContext;
8
+ import com.facebook.react.bridge.ReactContext;
9
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
10
+ import com.facebook.react.bridge.ReactMethod;
11
+ import com.facebook.react.modules.core.DeviceEventManagerModule;
12
+
13
+ import java.lang.Runnable;
14
+
15
+ public class BackgroundTimerModule extends ReactContextBaseJavaModule {
16
+
17
+ private Handler handler;
18
+ private ReactContext reactContext;
19
+ private Runnable runnable;
20
+ private PowerManager powerManager;
21
+ private PowerManager.WakeLock wakeLock;
22
+ private final LifecycleEventListener listener = new LifecycleEventListener(){
23
+ @Override
24
+ public void onHostResume() {}
25
+
26
+ @Override
27
+ public void onHostPause() {}
28
+
29
+ @Override
30
+ public void onHostDestroy() {
31
+ if (wakeLock.isHeld()) wakeLock.release();
32
+ }
33
+ };
34
+
35
+ public BackgroundTimerModule(ReactApplicationContext reactContext) {
36
+ super(reactContext);
37
+ this.reactContext = reactContext;
38
+ this.powerManager = (PowerManager) getReactApplicationContext().getSystemService(reactContext.POWER_SERVICE);
39
+ this.wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "rohit_bg_wakelock");
40
+ reactContext.addLifecycleEventListener(listener);
41
+ }
42
+
43
+ @Override
44
+ public String getName() {
45
+ return "RNBackgroundTimer";
46
+ }
47
+
48
+ @ReactMethod
49
+ public void start(final int delay) {
50
+ if (!wakeLock.isHeld()) wakeLock.acquire();
51
+
52
+ handler = new Handler();
53
+ runnable = new Runnable() {
54
+ @Override
55
+ public void run() {
56
+ sendEvent(reactContext, "backgroundTimer");
57
+ }
58
+ };
59
+
60
+ handler.post(runnable);
61
+ }
62
+
63
+ @ReactMethod
64
+ public void stop() {
65
+ if (wakeLock.isHeld()) wakeLock.release();
66
+
67
+ // avoid null pointer exceptio when stop is called without start
68
+ if (handler != null) handler.removeCallbacks(runnable);
69
+ }
70
+
71
+ private void sendEvent(ReactContext reactContext, String eventName) {
72
+ reactContext
73
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
74
+ .emit(eventName, null);
75
+ }
76
+
77
+ @ReactMethod
78
+ public void setTimeout(final int id, final double timeout) {
79
+ Handler handler = new Handler();
80
+ handler.postDelayed(new Runnable(){
81
+ @Override
82
+ public void run(){
83
+ if (getReactApplicationContext().hasActiveCatalystInstance()) {
84
+ getReactApplicationContext()
85
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
86
+ .emit("backgroundTimer.timeout", id);
87
+ }
88
+ }
89
+ }, (long) timeout);
90
+ }
91
+
92
+ /*@ReactMethod
93
+ public void clearTimeout(final int id) {
94
+ // todo one day..
95
+ // not really neccessary to have
96
+ }*/
97
+ }
@@ -0,0 +1,34 @@
1
+ package com.ocetnik.timer;
2
+
3
+ import com.facebook.react.ReactPackage;
4
+ import com.facebook.react.bridge.JavaScriptModule;
5
+ import com.facebook.react.bridge.NativeModule;
6
+ import com.facebook.react.bridge.ReactApplicationContext;
7
+ import com.facebook.react.uimanager.ViewManager;
8
+
9
+ import java.util.ArrayList;
10
+ import java.util.Collections;
11
+ import java.util.List;
12
+
13
+ public class BackgroundTimerPackage implements ReactPackage {
14
+
15
+ public BackgroundTimerPackage() {
16
+ }
17
+
18
+ @Override
19
+ public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
20
+ List<NativeModule> modules = new ArrayList<>();
21
+ modules.add(new BackgroundTimerModule(reactContext));
22
+
23
+ return modules;
24
+ }
25
+
26
+ public List<Class<? extends JavaScriptModule>> createJSModules() {
27
+ return Collections.emptyList();
28
+ }
29
+
30
+ @Override
31
+ public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
32
+ return Collections.emptyList();
33
+ }
34
+ }
@@ -0,0 +1,9 @@
1
+ /*
2
+ *
3
+ * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
4
+ * Use of this source code is governed by a MIT license that can be
5
+ * found in the LICENSE file
6
+ *
7
+ */
8
+
9
+ export * from "./ts";
@@ -0,0 +1,12 @@
1
+ {
2
+ "apiType": "stageMode",
3
+ "buildOption": {
4
+ },
5
+ "buildOptionSet": [
6
+ ],
7
+ "targets": [
8
+ {
9
+ "name": "default"
10
+ }
11
+ ]
12
+ }
@@ -0,0 +1,6 @@
1
+ import { harTasks } from '@ohos/hvigor-ohos-plugin';
2
+
3
+ export default {
4
+ system: harTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
5
+ plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
6
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "@react-native-ohos/react-native-background-timer",
3
+ "version": "2.4.2-rc.1",
4
+ "description": "Please describe the basic information.",
5
+ "main": "Index.ets",
6
+ "author": "",
7
+ "license": "MIT",
8
+ "dependencies": {
9
+ "@rnoh/react-native-openharmony": '^0.72.38'
10
+ }
11
+ }
@@ -0,0 +1,13 @@
1
+ cmake_minimum_required(VERSION 3.13)
2
+ set(CMAKE_VERBOSE_MAKEFILE on)
3
+
4
+ set(rnoh_background_timer_generated_dir "${CMAKE_CURRENT_SOURCE_DIR}/generated")
5
+
6
+ file(GLOB_RECURSE rnoh_background_timer_generated_SRC "${rnoh_background_timer_generated_dir}/**/*.cpp")
7
+ file(GLOB rnoh_background_timer_SRC CONFIGURE_DEPENDS *.cpp)
8
+
9
+ add_library(rnoh_background_timer SHARED ${rnoh_background_timer_SRC} ${rnoh_background_timer_generated_SRC})
10
+
11
+ target_include_directories(rnoh_background_timer PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${rnoh_background_timer_generated_dir})
12
+
13
+ target_link_libraries(rnoh_background_timer PUBLIC rnoh)
@@ -0,0 +1,15 @@
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
+ * Use of this source code is governed by a MIT license that can be
4
+ * found in the LICENSE file
5
+ */
6
+
7
+ #include "generated/RNOH/generated/BaseReactNativeBackgroundTimerPackage.h"
8
+ #pragma once
9
+
10
+ namespace rnoh {
11
+ class BackgroundTimerPackage : public BaseReactNativeBackgroundTimerPackage {
12
+ using Super = BaseReactNativeBackgroundTimerPackage;
13
+ using Super::Super;
14
+ };
15
+ } // namespace rnoh
@@ -0,0 +1,75 @@
1
+
2
+ /**
3
+ * This code was generated by "react-native codegen-lib-harmony"
4
+ */
5
+
6
+ #pragma once
7
+
8
+ #include "RNOH/Package.h"
9
+ #include "RNOH/ArkTSTurboModule.h"
10
+ #include "RNOH/generated/turbo_modules/BackgroundTimerTurboModule.h"
11
+
12
+ namespace rnoh {
13
+
14
+ class BaseReactNativeBackgroundTimerPackageTurboModuleFactoryDelegate : public TurboModuleFactoryDelegate {
15
+ public:
16
+ SharedTurboModule createTurboModule(Context ctx, const std::string &name) const override
17
+ {
18
+ if (name == "BackgroundTimerTurboModule") {
19
+ return std::make_shared<BackgroundTimerTurboModule>(ctx, name);
20
+ }
21
+ return nullptr;
22
+ };
23
+ };
24
+
25
+ class BaseReactNativeBackgroundTimerPackageEventEmitRequestHandler : public EventEmitRequestHandler {
26
+ public:
27
+ void handleEvent(Context const &ctx) override
28
+ {
29
+ auto eventEmitter = ctx.shadowViewRegistry->getEventEmitter<facebook::react::EventEmitter>(ctx.tag);
30
+ if (eventEmitter == nullptr) {
31
+ return;
32
+ }
33
+
34
+ std::vector<std::string> supportedEventNames = {
35
+ // 添加支持的事件名称
36
+ };
37
+ if (std::find(supportedEventNames.begin(),
38
+ supportedEventNames.end(),
39
+ ctx.eventName) != supportedEventNames.end()) {
40
+ eventEmitter->dispatchEvent(ctx.eventName, ArkJS(ctx.env).getDynamic(ctx.payload));
41
+ }
42
+ }
43
+ };
44
+
45
+
46
+ class BaseReactNativeBackgroundTimerPackage : public Package {
47
+ public:
48
+ BaseReactNativeBackgroundTimerPackage(Package::Context ctx) : Package(ctx){};
49
+
50
+ std::unique_ptr<TurboModuleFactoryDelegate> createTurboModuleFactoryDelegate() override
51
+ {
52
+ return std::make_unique<BaseReactNativeBackgroundTimerPackageTurboModuleFactoryDelegate>();
53
+ }
54
+
55
+ std::vector<facebook::react::ComponentDescriptorProvider> createComponentDescriptorProviders() override
56
+ {
57
+ return {
58
+ };
59
+ }
60
+
61
+ ComponentJSIBinderByString createComponentJSIBinderByName() override
62
+ {
63
+ return {
64
+ };
65
+ };
66
+
67
+ EventEmitRequestHandlers createEventEmitRequestHandlers() override
68
+ {
69
+ return {
70
+ std::make_shared<BaseReactNativeBackgroundTimerPackageEventEmitRequestHandler>(),
71
+ };
72
+ }
73
+ };
74
+
75
+ } // namespace rnoh
@@ -0,0 +1,21 @@
1
+ /**
2
+ * This code was generated by "react-native codegen-lib-harmony"
3
+ */
4
+
5
+ #include "BackgroundTimerTurboModule.h"
6
+
7
+ namespace rnoh {
8
+ using namespace facebook;
9
+
10
+ BackgroundTimerTurboModule::BackgroundTimerTurboModule(
11
+ const ArkTSTurboModule::Context ctx, const std::string name
12
+ ) : ArkTSTurboModule(ctx, name)
13
+ {
14
+ methodMap_ = {
15
+ ARK_METHOD_METADATA(start, 1),
16
+ ARK_METHOD_METADATA(stop, 0),
17
+ ARK_METHOD_METADATA(setTimeout, 2),
18
+ };
19
+ }
20
+
21
+ } // namespace rnoh
@@ -0,0 +1,16 @@
1
+ /**
2
+ * This code was generated by "react-native codegen-lib-harmony"
3
+ */
4
+
5
+ #pragma once
6
+
7
+ #include "RNOH/ArkTSTurboModule.h"
8
+
9
+ namespace rnoh {
10
+
11
+ class JSI_EXPORT BackgroundTimerTurboModule : public ArkTSTurboModule {
12
+ public:
13
+ BackgroundTimerTurboModule(const ArkTSTurboModule::Context ctx, const std::string name);
14
+ };
15
+
16
+ } // namespace rnoh
@@ -0,0 +1,30 @@
1
+ /*
2
+ *
3
+ * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
4
+ * Use of this source code is governed by a MIT license that can be
5
+ * found in the LICENSE file
6
+ *
7
+ */
8
+
9
+ import { RNPackage, WorkerTurboModuleFactory } from '@rnoh/react-native-openharmony/ts';
10
+ import type { WorkerTurboModule, WorkerTurboModuleContext } from '@rnoh/react-native-openharmony/ts';
11
+ import { BackgroundTimerTurboModule } from './BackgroundTimerTurboModule';
12
+
13
+ class BackgroundTimerTurboModuleFactory extends WorkerTurboModuleFactory {
14
+ createTurboModule(name: string): WorkerTurboModule | null {
15
+ if (name === 'BackgroundTimerTurboModule') {
16
+ return new BackgroundTimerTurboModule(this.ctx);
17
+ }
18
+ return null;
19
+ }
20
+
21
+ hasTurboModule(name: string): boolean {
22
+ return name === 'BackgroundTimerTurboModule';
23
+ }
24
+ }
25
+
26
+ export class BackgroundTimerTurboModulePackage extends RNPackage {
27
+ createWorkerTurboModuleFactory(ctx: WorkerTurboModuleContext): WorkerTurboModuleFactory {
28
+ return new BackgroundTimerTurboModuleFactory(ctx);
29
+ }
30
+ }
@@ -0,0 +1,36 @@
1
+ /*
2
+ *
3
+ * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
4
+ * Use of this source code is governed by a MIT license that can be
5
+ * found in the LICENSE file
6
+ *
7
+ */
8
+
9
+ import { WorkerTurboModule, RNOHError, Tag } from '@rnoh/react-native-openharmony/ts';
10
+ import { TM } from "./generated/ts"
11
+ import worker from '@ohos.worker';
12
+ import type { WorkerTurboModuleContext } from '@rnoh/react-native-openharmony/ts';
13
+
14
+ // import { BackgroundTimer } from './BackgroundTimerWorker'
15
+
16
+ export class BackgroundTimerTurboModule extends WorkerTurboModule implements TM.BackgroundTimerTurboModule.Spec {
17
+ constructor(ctx: WorkerTurboModuleContext) {
18
+ super(ctx);
19
+ }
20
+
21
+
22
+ start(arg: number) {
23
+ //开个线程
24
+ this.ctx.rnInstance.emitDeviceEvent("backgroundTimer", null)
25
+ }
26
+
27
+ stop() {
28
+ //移除线程
29
+ }
30
+
31
+ setTimeout(id: number, timeout: number) {
32
+ setTimeout(() => {
33
+ this.ctx.rnInstance.emitDeviceEvent("backgroundTimer.timeout", id)
34
+ }, timeout)
35
+ }
36
+ }
@@ -0,0 +1,17 @@
1
+ /*
2
+ *
3
+ * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
4
+ * Use of this source code is governed by a MIT license that can be
5
+ * found in the LICENSE file
6
+ *
7
+ */
8
+
9
+ import worker, { MessageEvents } from '@ohos.worker';
10
+
11
+ const workerPort = worker.workerPort;
12
+
13
+ workerPort.onmessage = (e: MessageEvents): void => {
14
+ // e : MessageEvents, 用法如下:
15
+ let data = e.data;
16
+ data.rnInstance.emitDeviceEvent("backgroundTimer.timeout", null)
17
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * This code was generated by "react-native codegen-lib-harmony"
3
+ */
4
+
5
+ export * from "./ts"
@@ -0,0 +1,6 @@
1
+ /**
2
+ * This code was generated by "react-native codegen-lib-harmony"
3
+ */
4
+
5
+ export * as RNC from "./components/ts"
6
+ export * as TM from "./turboModules/ts"
@@ -0,0 +1,18 @@
1
+ /**
2
+ * This code was generated by "react-native codegen-lib-harmony"
3
+ */
4
+
5
+ import { Tag } from "@rnoh/react-native-openharmony/ts"
6
+
7
+ export namespace BackgroundTimerTurboModule {
8
+ export const NAME = 'BackgroundTimerTurboModule' as const
9
+
10
+ export interface Spec {
11
+ start(delay: number): void;
12
+
13
+ stop(): void;
14
+
15
+ setTimeout(timeoutId: number, timeout: number): void;
16
+
17
+ }
18
+ }