Skip to content

Commit 5e0f1db

Browse files
authored
feat:适配harmony平台 (#2)
1 parent b11ba88 commit 5e0f1db

13 files changed

+140
-74
lines changed

README.md

+8-69
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,17 @@
11
# react-native-exit-app
2-
Exit / Close / Kill / shutdown your react native app. Does not invoke a crash notification.
32

4-
NOTICE:
5-
- for React Native < 0.47 use react-native-exit-app <1.x.x
6-
- for React Native > 0.47 use react-native-exit-app >=1.x.x
7-
- React Native with **new architecture** enabled use react-native-exit-app >=2.x.x (**compatible with old architecture**)
3+
本项目基于 [react-native-exit-app](https://github.com/wumke/react-native-exit-app)
84

9-
## Setup
5+
## 文档地址 / Documentation URL
106

11-
NOTICE:
12-
Installation steps can be skipped in new architecture and newer React Native versions, just
13-
```bash
14-
npm install react-native-exit-app --save
15-
```
7+
[中文 / Chinese](https://gitee.com/react-native-oh-library/usage-docs/blob/master/zh-cn/react-native-exit-app.md)
168

17-
Fast and easy:
18-
```bash
19-
npm install react-native-exit-app --save
20-
react-native link react-native-exit-app
21-
```
9+
## Codegen
2210

23-
Or manual: add the latest version as dependeny to your package.json.
11+
该库已接入 codegen,具体请查阅文档。
2412

25-
```javascript
26-
{
27-
"name": "YourProject",
28-
...
29-
},
30-
"dependencies": {
31-
...
32-
"react-native-exit-app": "0.1.0",
33-
...
34-
}
35-
```
13+
The library has been integrated with codegen. Please refer to the documentation for details.
3614

37-
#### iOS
38-
* Add RNExitApp.xcoderproj into your project in the Libraries folder.
39-
* Add the .a file on the General tab of your target under Linked Frameworks And Libraries
40-
* Add the .a file on the Build Phases tab of your target under Link Binary With Libraries
15+
## 请悉知 / Acknowledgements
4116

42-
#### Android
43-
* In the settings.gradle
44-
```
45-
include ':react-native-exit-app', ':app'
46-
project(':react-native-exit-app').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-exit-app/android')
47-
```
48-
* In the build.gradle
49-
```
50-
compile project(':react-native-exit-app')
51-
```
52-
* In MainApplication.java
53-
```
54-
import com.github.wumke.RNExitApp.RNExitAppPackage;
55-
...
56-
@Override
57-
protected List<ReactPackage> getPackages() {
58-
return Arrays.<ReactPackage>asList(
59-
...
60-
new RNExitAppPackage(),
61-
...
62-
);
63-
}
64-
...
65-
```
66-
## Usage
67-
68-
```javascript
69-
import RNExitApp from 'react-native-exit-app';
70-
...
71-
RNExitApp.exitApp();
72-
...
73-
```
74-
75-
## Versioning
76-
77-
This project uses semantic versioning: MAJOR.MINOR.PATCH.
78-
This means that releases within the same MAJOR version are always backwards compatible. For more info see [semver.org](http://semver.org/).
17+
本项目基于 [The MIT License (MIT)](https://github.com/wumke/react-native-exit-app/blob/master/LICENSE) ,请自由地享受和参与开源。

harmony/exit_app.har

1.39 KB
Binary file not shown.

harmony/exit_app/Index.ets

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./ts";

harmony/exit_app/build-profile.json5

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"apiType": "stageMode",
3+
"buildOption": {
4+
},
5+
"buildOptionSet": [
6+
{
7+
"name": "release",
8+
"arkOptions": {
9+
"obfuscation": {
10+
"ruleOptions": {
11+
"enable": true,
12+
"files": [
13+
"./obfuscation-rules.txt"
14+
]
15+
},
16+
},
17+
},
18+
},
19+
],
20+
"targets": [
21+
{
22+
"name": "default"
23+
},
24+
{
25+
"name": "ohosTest"
26+
}
27+
]
28+
}

harmony/exit_app/hvigorfile.ts

+6
Original file line numberDiff line numberDiff line change
@@ -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+
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Define project specific obfuscation rules here.
2+
# You can include the obfuscation configuration files in the current module's build-profile.json5.
3+
#
4+
# For more details, see
5+
# https://gitee.com/openharmony/arkcompiler_ets_frontend/blob/master/arkguard/README.md
6+
7+
# Obfuscation options:
8+
# -disable-obfuscation: disable all obfuscations
9+
# -enable-property-obfuscation: obfuscate the property names
10+
# -enable-toplevel-obfuscation: obfuscate the names in the global scope
11+
# -compact: remove unnecessary blank spaces and all line feeds
12+
# -remove-log: remove all console.* statements
13+
# -print-namecache: print the name cache that contains the mapping from the old names to new names
14+
# -apply-namecache: reuse the given cache file
15+
16+
# Keep options:
17+
# -keep-property-name: specifies property names that you want to keep
18+
# -keep-global-name: specifies names that you want to keep in the global scope

harmony/exit_app/oh-package.json5

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "@react-native-oh-tpl/react-native-exit-app",
3+
"version": "2.0.0-0.0.1",
4+
"description": "",
5+
"main": "Index.ets",
6+
"author": "",
7+
"license": "Apache-2.0",
8+
"dependencies": {
9+
"@rnoh/react-native-openharmony": "file:../react_native_openharmony"
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { TurboModule } from '@rnoh/react-native-openharmony/ts';
2+
import { TM } from "@rnoh/react-native-openharmony/generated/ts"
3+
import { process } from '@kit.ArkTS'
4+
export class ExitAppModule extends TurboModule implements TM.RNExitApp.Spec {
5+
public exitApp(): void {
6+
let pro = new process.ProcessManager()
7+
pro.exit(0);
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {
2+
RNPackage,
3+
TurboModulesFactory,
4+
} from "@rnoh/react-native-openharmony/ts";
5+
import type {
6+
TurboModule,
7+
TurboModuleContext,
8+
} from "@rnoh/react-native-openharmony/ts";
9+
import { TM } from "@rnoh/react-native-openharmony/generated/ts";
10+
import { ExitAppModule } from './ExitAppModule';
11+
12+
class ExitAppModulesFactory extends TurboModulesFactory {
13+
createTurboModule(name: string): TurboModule | null {
14+
if (name === TM.RNExitApp.NAME) {
15+
return new ExitAppModule(this.ctx);
16+
}
17+
return null;
18+
}
19+
20+
hasTurboModule(name: string): boolean {
21+
return name === TM.RNExitApp.NAME;
22+
}
23+
}
24+
25+
export class ExitAppPackage extends RNPackage {
26+
createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory {
27+
return new ExitAppModulesFactory(ctx);
28+
}
29+
}
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"module": {
3+
"name": 'exit_app',
4+
"type": 'har',
5+
"deviceTypes": ['default'],
6+
},
7+
}

harmony/exit_app/ts.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./src/main/ets/ExitAppPackage";
2+
export * from "./src/main/ets/ExitAppModule";

package.json

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
{
2-
"name": "react-native-exit-app",
3-
"version": "2.0.0",
4-
"description": "Exit,close,kill,shutdown app completely for React Native on iOS and Android.",
2+
"name": "@react-native-oh-tpl/react-native-exit-app",
3+
"version": "2.0.0-0.0.1",
4+
"description": "Exit,close,kill,shutdown app completely for React Native on iOS Android and harmony.",
55
"main": "index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1"
88
},
99
"repository": {
1010
"type": "git",
11-
"url": "https://github.com/wumke/react-native-exit-app"
11+
"url": "https://github.com/react-native-oh-library/react-native-exit-app.git"
12+
},
13+
"harmony": {
14+
"alias": "react-native-exit-app",
15+
"codegenConfig": {
16+
"specPaths": [
17+
"./src"
18+
]
19+
}
1220
},
1321
"types": "index.d.ts",
1422
"keywords": [
@@ -19,7 +27,8 @@
1927
"shutdown",
2028
"kill",
2129
"android",
22-
"ios"
30+
"ios",
31+
"harmony"
2332
],
2433
"author": "Wumke",
2534
"license": "MIT",

src/NativeExitApp.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport';
2+
import { TurboModuleRegistry } from 'react-native';
3+
export interface Spec extends TurboModule {
4+
exitApp: () => void;
5+
}
6+
7+
export default TurboModuleRegistry.get<Spec>('RNExitApp') as Spec | null;

0 commit comments

Comments
 (0)