Skip to content

Commit 2548201

Browse files
committed
配置修改
1 parent ff6e6e1 commit 2548201

24 files changed

+519
-3
lines changed

harmony/exception_handler.har

14 Bytes
Binary file not shown.

harmony/exception_handler/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/node_modules
2+
/oh_modules
3+
/.preview
4+
/build
5+
/.cxx
6+
/.test

harmony/exception_handler/Index.ets

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (C) 2023 Huawei Device Co., Ltd.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
export * from './ts'
26+
export * from "./src/main/ets/ExceptionComponent"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"apiType": "stageMode",
3+
"targets": [
4+
{
5+
"name": "default"
6+
}
7+
]
8+
}
Lines changed: 6 additions & 0 deletions
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+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"license": "ISC",
3+
"types": "",
4+
"devDependencies": {
5+
"rnoh": "file:../rnoh"
6+
},
7+
"name": "rnoh-exception-handler",
8+
"description": "",
9+
"main": "index.ets",
10+
"version": "1.0.0",
11+
"dependencies": {}
12+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
set(CMAKE_VERBOSE_MAKEFILE on)
3+
4+
file(GLOB rnoh_exception_handler_SRC CONFIGURE_DEPENDS *.cpp)
5+
add_library(rnoh_exception_handler SHARED ${rnoh_exception_handler_SRC})
6+
target_include_directories(rnoh_exception_handler PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
7+
target_link_libraries(rnoh_exception_handler PUBLIC rnoh)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (C) 2023 Huawei Device Co., Ltd.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
#ifndef EXCEPTIONHANDLERPACKAGE_H
26+
#define EXCEPTIONHANDLERPACKAGE_H
27+
28+
#include "ExceptionHandlerTurboModule.h"
29+
#include "RNOH/Package.h"
30+
31+
using namespace rnoh;
32+
using namespace facebook;
33+
34+
class ExceptionHandlerTurboModuleFactoryDelegate : public TurboModuleFactoryDelegate
35+
{
36+
public:
37+
SharedTurboModule createTurboModule(Context ctx, const std::string &name) const override
38+
{
39+
if (name == "ExceptionHandlerTurboModule")
40+
{
41+
return std::make_shared<ExceptionHandlerTurboModuleSpecJSI>(ctx, name);
42+
}
43+
return nullptr;
44+
}
45+
}
46+
47+
namespace rnoh
48+
{
49+
class ExceptionHandlerPackage : public Package
50+
{
51+
public:
52+
ExceptionHandlerPackage(Package::Context ctx) :Package(ctx) {}
53+
std::unique_ptr<TurboModuleFactoryDelegate> createTurboModuleFactoryDelegate()
54+
{
55+
return std::make_unique<ExceptionHandlerTurboModuleFactoryDelegate>();
56+
}
57+
}
58+
}
59+
#endif
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (C) 2023 Huawei Device Co., Ltd.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
#include "ExceptionHandlerTurboModule.h"
26+
27+
using namespace rnoh;
28+
using namespace facebook;
29+
30+
static jsi::Value _hostFunction_ExceptionHandlerTurboModuleSpecJSI_setHandlerforNativeException(
31+
jsi::Runtime &rt,
32+
react::TurboModule &turboModule,
33+
const jsi::Value *args,
34+
size_t count)
35+
{
36+
return static_cast<ArkTSTurboModule &>(turboModule).call(rt, "setHandlerforNativeException", args, count);
37+
}
38+
39+
ExceptionHandlerTurboModuleSpecJSI::ExceptionHandlerTurboModuleSpecJSI(
40+
const ArkTSTurboModule::Context ctx,
41+
const std::string name): ArkTSTurboModule(ctx, name)
42+
{
43+
methodMap_["setHandlerforNativeException"] =
44+
MethodMetadata{3, _hostFunction_ExceptionHandlerTurboModuleSpecJSI_setHandlerforNativeException};
45+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (C) 2023 Huawei Device Co., Ltd.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
#ifndef EXCEPTIONHANDLERTURBOMODULE_H
26+
#define EXCEPTIONHANDLERTURBOMODULE_H
27+
28+
#include <ReactCommon/TurboModule.h>
29+
#include "RNOH/ArkTSTurboModule.h"
30+
31+
namespace rnoh {
32+
class JSI_EXPORT ExceptionHandlerTurboModuleSpecJSI : public ArkTSTurboModule
33+
{
34+
public:
35+
ExceptionHandlerTurboModuleSpecJSI(const ArkTSTurboModule::Context ctx, const std::string name);
36+
}
37+
}
38+
#endif
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (C) 2023 Huawei Device Co., Ltd.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
import common from '@ohos.app.ability.common';
26+
import appRecovery from '@ohos.app.ability.appRecovery';
27+
28+
@Component
29+
export struct ExceptionComponent {
30+
private errMsg: string;
31+
@State message: string = 'SHOW DETAILS'
32+
@State visible: boolean = false
33+
34+
@Builder ButtonBuilder(text: string, click: () => void) {
35+
Button(text, { type: ButtonType.Normal, stateEffect: true })
36+
.fontColor('#000')
37+
.fontWeight(FontWeight.Bolder)
38+
.layoutWeight(1)
39+
.borderRadius(8)
40+
.backgroundColor('#CFCFCF')
41+
.onClick(click)
42+
}
43+
44+
relaunch() {
45+
console.info(`relaunch`)
46+
appRecovery.restartApp()
47+
}
48+
49+
quit() {
50+
console.info(`quit`)
51+
let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
52+
context.terminateSelf((error) => {
53+
if (error.code) {
54+
// 处理业务逻辑错误
55+
console.error(`terminateSelf failed, error.code: ${error.code}, error.message: ${error.message}`);
56+
return;
57+
}
58+
59+
// 执行正常业务
60+
console.log('terminateSelf succeed');
61+
});
62+
}
63+
64+
build() {
65+
Column() {
66+
Text('Critical Error Occurred !')
67+
.fontSize(20)
68+
.fontWeight(FontWeight.Bolder)
69+
.padding({ top: 50, bottom: 20 })
70+
Image($r("app.media.ic_public_error"))
71+
.width(50)
72+
.height(50)
73+
Text('This is embarrassing. We sincerely apologize for this.')
74+
.fontSize(14)
75+
.fontWeight(FontWeight.Bold)
76+
.textAlign(TextAlign.Center)
77+
.padding({ left: 40, top: 20, right: 40 })
78+
Row({ space: 10 }) {
79+
this.ButtonBuilder('RELAUNCH', this.relaunch)
80+
this.ButtonBuilder('QUIT', this.quit)
81+
}.padding({ left: 20, top: 20, right: 20 })
82+
83+
Button(this.message, { stateEffect: false })
84+
.fontSize(10)
85+
.fontColor('#000')
86+
.fontWeight(FontWeight.Bolder)
87+
.backgroundColor('#FFF')
88+
.onClick(() => {
89+
this.message = this.visible ? 'SHOW DETAILS' : 'HIDE DETAILS'
90+
this.visible = !this.visible
91+
})
92+
Text(this.errMsg)
93+
.backgroundColor('#ECECEC')
94+
.visibility(this.visible ? Visibility.Visible : Visibility.Hidden)
95+
.width(330)
96+
.height(500)
97+
}
98+
.width('100%')
99+
.height('100%')
100+
}
101+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (C) 2023 Huawei Device Co., Ltd.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
import {RNPackage, TurboModulesFactory} from 'rnoh/ts';
26+
import type {TurboModule, TurboModuleContext} from 'rnoh/ts';
27+
import {ExceptionHandlerTurboModule} from './ExceptionHandlerTurboModule';
28+
29+
class ExceptionHandlerTurboModulesFactory extends TurboModulesFactory {
30+
createTurboModule(name: string): TurboModule | null {
31+
if (name === 'ExceptionHandlerTurboModule') {
32+
globalThis.uiAbilityContext = this.ctx.uiAbilityContext;
33+
return new ExceptionHandlerTurboModule(this.ctx);
34+
}
35+
return null;
36+
}
37+
38+
hasTurboModule(name: string): boolean {
39+
return name === 'ExceptionHandlerTurboModule';
40+
}
41+
}
42+
43+
export class ExceptionHandlerPackage extends RNPackage {
44+
createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory {
45+
return new ExceptionHandlerTurboModulesFactory(ctx);
46+
}
47+
}

0 commit comments

Comments
 (0)