deveco-harness 0.1.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 (135) hide show
  1. package/README.en.md +71 -0
  2. package/README.md +71 -0
  3. package/deveco-harness.example.jsonc +32 -0
  4. package/dist/index.js +758 -0
  5. package/package.json +48 -0
  6. package/prompts/build.txt +164 -0
  7. package/prompts/plan.txt +118 -0
  8. package/skills/arkts-error-fixes/README.md +151 -0
  9. package/skills/arkts-error-fixes/SKILL.md +150 -0
  10. package/skills/arkts-error-fixes/assets/AnyTypeError.ets +269 -0
  11. package/skills/arkts-error-fixes/assets/AppStorageError.ets +22 -0
  12. package/skills/arkts-error-fixes/assets/ArrowFunctionConversionError.ets +42 -0
  13. package/skills/arkts-error-fixes/assets/AvoidAreaTypeError.ets +43 -0
  14. package/skills/arkts-error-fixes/assets/BreakpointTypeError.ets +71 -0
  15. package/skills/arkts-error-fixes/assets/CatchClauseTypeError.ets +54 -0
  16. package/skills/arkts-error-fixes/assets/ColorConsistencyError.ets +88 -0
  17. package/skills/arkts-error-fixes/assets/ColorPropertyError.ets +39 -0
  18. package/skills/arkts-error-fixes/assets/ContextTypeError.ets +105 -0
  19. package/skills/arkts-error-fixes/assets/DecoratorStateError.ets +64 -0
  20. package/skills/arkts-error-fixes/assets/DisplayListenerTypeError.ets +129 -0
  21. package/skills/arkts-error-fixes/assets/DuplicateEntryError.ets +35 -0
  22. package/skills/arkts-error-fixes/assets/ESObjectTypeError.ets +137 -0
  23. package/skills/arkts-error-fixes/assets/FontColorPropertyError.ets +42 -0
  24. package/skills/arkts-error-fixes/assets/FunctionReturnTypeError.ets +41 -0
  25. package/skills/arkts-error-fixes/assets/IDataSourceError.ets +79 -0
  26. package/skills/arkts-error-fixes/assets/ImplementationNotAllowedError.ets +38 -0
  27. package/skills/arkts-error-fixes/assets/InterfaceMethodSignatureError.ets +43 -0
  28. package/skills/arkts-error-fixes/assets/NotificationError.ets +34 -0
  29. package/skills/arkts-error-fixes/assets/ObjectLiteralInterfaceError.ets +49 -0
  30. package/skills/arkts-error-fixes/assets/ObjectLiteralTypeError.ets +54 -0
  31. package/skills/arkts-error-fixes/assets/ObjectSpreadError.ets +29 -0
  32. package/skills/arkts-error-fixes/assets/PossiblyNullError.ets +32 -0
  33. package/skills/arkts-error-fixes/assets/ResourceConversionError.ets +159 -0
  34. package/skills/arkts-error-fixes/assets/StandaloneFunctionContext.ets +116 -0
  35. package/skills/arkts-error-fixes/assets/StandaloneFunctionError.ets +85 -0
  36. package/skills/arkts-error-fixes/assets/StorageLinkDefaultError.ets +41 -0
  37. package/skills/arkts-error-fixes/assets/TitleButtonRectTypeError.ets +86 -0
  38. package/skills/arkts-error-fixes/assets/UnusedVariableWarning.ets +102 -0
  39. package/skills/arkts-error-fixes/assets/UtilityTypeError.ets +176 -0
  40. package/skills/arkts-error-fixes/assets/WindowRectSizeError.ets +65 -0
  41. package/skills/arkts-error-fixes/assets/WindowTypeError.ets +37 -0
  42. package/skills/arkts-error-fixes/reference/any_type_errors.md +433 -0
  43. package/skills/arkts-error-fixes/reference/appstorage_errors.md +95 -0
  44. package/skills/arkts-error-fixes/reference/arrow_function_conversion_errors.md +163 -0
  45. package/skills/arkts-error-fixes/reference/avoid_area_type_errors.md +59 -0
  46. package/skills/arkts-error-fixes/reference/breakpoint_type_errors.md +122 -0
  47. package/skills/arkts-error-fixes/reference/catch_clause_type_errors.md +89 -0
  48. package/skills/arkts-error-fixes/reference/color_consistency_errors.md +209 -0
  49. package/skills/arkts-error-fixes/reference/color_property_errors.md +136 -0
  50. package/skills/arkts-error-fixes/reference/context_type_errors.md +260 -0
  51. package/skills/arkts-error-fixes/reference/decorator_state_errors.md +109 -0
  52. package/skills/arkts-error-fixes/reference/display_listener_type_errors.md +149 -0
  53. package/skills/arkts-error-fixes/reference/duplicate_entry_errors.md +193 -0
  54. package/skills/arkts-error-fixes/reference/esobject_type_errors.md +110 -0
  55. package/skills/arkts-error-fixes/reference/fontcolor_property_errors.md +104 -0
  56. package/skills/arkts-error-fixes/reference/function_return_type_errors.md +194 -0
  57. package/skills/arkts-error-fixes/reference/idata_source_errors.md +77 -0
  58. package/skills/arkts-error-fixes/reference/implementation_not_allowed_errors.md +191 -0
  59. package/skills/arkts-error-fixes/reference/interface_method_signature_errors.md +143 -0
  60. package/skills/arkts-error-fixes/reference/notification_errors.md +110 -0
  61. package/skills/arkts-error-fixes/reference/object_literal_interface_errors.md +156 -0
  62. package/skills/arkts-error-fixes/reference/object_literal_type_errors.md +110 -0
  63. package/skills/arkts-error-fixes/reference/object_spread_errors.md +105 -0
  64. package/skills/arkts-error-fixes/reference/possibly_null_errors.md +156 -0
  65. package/skills/arkts-error-fixes/reference/resource_conversion_errors.md +154 -0
  66. package/skills/arkts-error-fixes/reference/standalone_function_errors.md +68 -0
  67. package/skills/arkts-error-fixes/reference/storage_link_default_errors.md +124 -0
  68. package/skills/arkts-error-fixes/reference/title_button_rect_type_errors.md +167 -0
  69. package/skills/arkts-error-fixes/reference/unused_variable_warnings.md +295 -0
  70. package/skills/arkts-error-fixes/reference/utility_type_errors.md +290 -0
  71. package/skills/arkts-error-fixes/reference/window_rect_size_errors.md +70 -0
  72. package/skills/arkts-error-fixes/reference/window_type_errors.md +95 -0
  73. package/skills/arkts-grammar-standards/SKILL.md +71 -0
  74. package/skills/arkts-grammar-standards/references/basic-syntax.md +103 -0
  75. package/skills/arkts-grammar-standards/references/restrictions.md +100 -0
  76. package/skills/arkts-grammar-standards/references/topic-aliases.json +93 -0
  77. package/skills/arkts-grammar-standards/references/ts-diff.md +108 -0
  78. package/skills/arkts-runtime-fix/SKILL.md +152 -0
  79. package/skills/arkts-runtime-fix/SKILL_CN.md +123 -0
  80. package/skills/arkts-runtime-fix/evals/evals.json +17 -0
  81. package/skills/arkts-runtime-fix/scripts/collect-hilog.mjs +116 -0
  82. package/skills/arkts-runtime-fix/scripts/collect-hilog.ts +115 -0
  83. package/skills/arkts-runtime-fix/scripts/fetch-faultlog.mjs +117 -0
  84. package/skills/arkts-runtime-fix/scripts/fetch-faultlog.ts +116 -0
  85. package/skills/arkts-runtime-fix/scripts/jscrash-report.mjs +149 -0
  86. package/skills/arkts-runtime-fix/scripts/parse-jscrash-log.mjs +126 -0
  87. package/skills/arkts-runtime-fix/scripts/parse-jscrash-log.ts +126 -0
  88. package/skills/arkts-runtime-fix/scripts/probe-faultlogger.mjs +160 -0
  89. package/skills/arkts-runtime-fix/scripts/probe-faultlogger.ts +160 -0
  90. package/skills/arkts-runtime-fix/scripts/shared/hdc.mjs +107 -0
  91. package/skills/arkts-runtime-fix/scripts/shared/hdc.ts +58 -0
  92. package/skills/arkts-runtime-fix/scripts/shared/jscrash-faultlogger.mjs +143 -0
  93. package/skills/arkts-runtime-fix/scripts/shared/jscrash-faultlogger.ts +148 -0
  94. package/skills/arkts-runtime-fix/scripts/shared/jscrash-parse.mjs +389 -0
  95. package/skills/arkts-runtime-fix/scripts/shared/jscrash-parse.ts +409 -0
  96. package/skills/arkts-runtime-fix/scripts/shared/utils.mjs +27 -0
  97. package/skills/arkts-runtime-fix/scripts/shared/utils.ts +27 -0
  98. package/skills/arkui-knowledge/SKILL.md +90 -0
  99. package/skills/arkui-knowledge/references/api-guardrails.md +60 -0
  100. package/skills/arkui-knowledge/references/common-mistakes.md +119 -0
  101. package/skills/arkui-knowledge/references/component-cookbook.md +135 -0
  102. package/skills/arkui-knowledge/references/ui-quality-checklist.md +36 -0
  103. package/skills/deveco-create-project/SKILL.md +144 -0
  104. package/skills/deveco-create-project/application/AppScope/app.json5 +10 -0
  105. package/skills/deveco-create-project/application/AppScope/resources/base/element/string.json +8 -0
  106. package/skills/deveco-create-project/application/AppScope/resources/base/media/background.png +0 -0
  107. package/skills/deveco-create-project/application/AppScope/resources/base/media/foreground.png +0 -0
  108. package/skills/deveco-create-project/application/AppScope/resources/base/media/layered_image.json +7 -0
  109. package/skills/deveco-create-project/application/build-profile.json5 +42 -0
  110. package/skills/deveco-create-project/application/code-linter.json5 +32 -0
  111. package/skills/deveco-create-project/application/entry/build-profile.json5 +33 -0
  112. package/skills/deveco-create-project/application/entry/hvigorfile.ts +7 -0
  113. package/skills/deveco-create-project/application/entry/obfuscation-rules.txt +23 -0
  114. package/skills/deveco-create-project/application/entry/oh-package.json5 +10 -0
  115. package/skills/deveco-create-project/application/entry/src/main/ets/entryability/EntryAbility.ets +63 -0
  116. package/skills/deveco-create-project/application/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +31 -0
  117. package/skills/deveco-create-project/application/entry/src/main/ets/pages/Index.ets +38 -0
  118. package/skills/deveco-create-project/application/entry/src/main/module.json5 +50 -0
  119. package/skills/deveco-create-project/application/entry/src/main/resources/base/element/color.json +8 -0
  120. package/skills/deveco-create-project/application/entry/src/main/resources/base/element/float.json +8 -0
  121. package/skills/deveco-create-project/application/entry/src/main/resources/base/element/string.json +16 -0
  122. package/skills/deveco-create-project/application/entry/src/main/resources/base/media/background.png +0 -0
  123. package/skills/deveco-create-project/application/entry/src/main/resources/base/media/foreground.png +0 -0
  124. package/skills/deveco-create-project/application/entry/src/main/resources/base/media/layered_image.json +7 -0
  125. package/skills/deveco-create-project/application/entry/src/main/resources/base/media/startIcon.png +0 -0
  126. package/skills/deveco-create-project/application/entry/src/main/resources/base/profile/backup_config.json +3 -0
  127. package/skills/deveco-create-project/application/entry/src/main/resources/base/profile/main_pages.json +5 -0
  128. package/skills/deveco-create-project/application/entry/src/main/resources/dark/element/color.json +8 -0
  129. package/skills/deveco-create-project/application/hvigor/hvigor-config.json5 +23 -0
  130. package/skills/deveco-create-project/application/hvigorfile.ts +7 -0
  131. package/skills/deveco-create-project/application/oh-package.json5 +10 -0
  132. package/skills/deveco-create-project/scripts/copy-template.mjs +216 -0
  133. package/skills/deveco-create-project/scripts/copy-template.ts +214 -0
  134. package/skills/deveco-create-project/scripts/detect-sdk.mjs +82 -0
  135. package/skills/deveco-create-project/scripts/detect-sdk.ts +95 -0
@@ -0,0 +1,43 @@
1
+ interface WindowUtilDensity {
2
+ onDensityUpdate: () => void;
3
+ updateWindowInfo: () => void;
4
+ destroy: () => void;
5
+ }
6
+
7
+ export const windowUtilDensityExample: WindowUtilDensity = {
8
+ onDensityUpdate: () => {
9
+ console.log('Density updated');
10
+ },
11
+
12
+ updateWindowInfo: () => {
13
+ console.log('Window info updated');
14
+ },
15
+
16
+ destroy: () => {
17
+ console.log('Window util destroyed');
18
+ }
19
+ };
20
+
21
+ @Entry
22
+ @Component
23
+ struct InterfaceMethodSignatureError {
24
+ @State windowWidth: number = 0;
25
+ @State windowHeight: number = 0;
26
+
27
+ aboutToAppear() {
28
+ windowUtilDensityExample.updateWindowInfo();
29
+ }
30
+
31
+ build() {
32
+ Column() {
33
+ Text(`Window: ${this.windowWidth} x ${this.windowHeight}`)
34
+ .fontSize(20)
35
+ .margin({ bottom: 20 })
36
+
37
+ Button('Update Info')
38
+ .onClick(() => {
39
+ windowUtilDensityExample.updateWindowInfo();
40
+ })
41
+ }
42
+ }
43
+ }
@@ -0,0 +1,34 @@
1
+ import { notificationManager } from '@kit.NotificationKit';
2
+ import { BusinessError } from '@kit.BasicServicesKit';
3
+ import { hilog } from '@kit.PerformanceAnalysisKit';
4
+
5
+ @Entry
6
+ @Component
7
+ struct NotificationError {
8
+ publishNotification() {
9
+ let notificationRequest: notificationManager.NotificationRequest = {
10
+ id: 1,
11
+ content: {
12
+ contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT as number,
13
+ normal: {
14
+ title: 'Test Notification',
15
+ text: 'This is a test notification',
16
+ additionalText: 'Additional text'
17
+ }
18
+ }
19
+ };
20
+
21
+ notificationManager.publish(notificationRequest).then(() => {
22
+ hilog.info(0x0000, 'testTag', 'Publish notification success');
23
+ }).catch((err: BusinessError) => {
24
+ hilog.error(0x0000, 'testTag', 'Publish notification failed: %{public}s', JSON.stringify(err));
25
+ });
26
+ }
27
+
28
+ build() {
29
+ Column() {
30
+ Button('Publish Notification')
31
+ .onClick(() => this.publishNotification())
32
+ }
33
+ }
34
+ }
@@ -0,0 +1,49 @@
1
+ interface Article {
2
+ title: string;
3
+ desc: string;
4
+ image: Resource;
5
+ }
6
+
7
+ @Entry
8
+ @Component
9
+ struct ObjectLiteralInterfaceError {
10
+ private articles: Article[] = [
11
+ { title: '文章1', desc: '这是文章1的描述', image: $r('app.media.article1') },
12
+ { title: '文章2', desc: '这是文章2的描述', image: $r('app.media.article2') },
13
+ { title: '文章3', desc: '这是文章3的描述', image: $r('app.media.article3') }
14
+ ];
15
+
16
+ build() {
17
+ Scroll() {
18
+ Column() {
19
+ ForEach(this.articles, (article: Article, index: number) => {
20
+ Column() {
21
+ Image(article.image)
22
+ .width('100%')
23
+ .height(200)
24
+ .objectFit(ImageFit.Cover)
25
+ .borderRadius(8)
26
+
27
+ Text(article.title)
28
+ .fontSize('20fp')
29
+ .fontWeight(FontWeight.Bold)
30
+ .margin({ top: 8 })
31
+
32
+ Text(article.desc)
33
+ .fontSize('14fp')
34
+ .fontColor('#666666')
35
+ .margin({ top: 4 })
36
+ }
37
+ .padding(16)
38
+ .backgroundColor('#FFFFFF')
39
+ .borderRadius(8)
40
+ .margin({ bottom: 16 })
41
+ })
42
+ }
43
+ .padding({ left: 16, right: 16, top: 16, bottom: 16 })
44
+ }
45
+ .width('100%')
46
+ .height('100%')
47
+ .backgroundColor('#F5F5F5')
48
+ }
49
+ }
@@ -0,0 +1,54 @@
1
+ import { common } from '@kit.AbilityKit';
2
+
3
+ interface WindowSize {
4
+ width: number;
5
+ height: number;
6
+ }
7
+
8
+ @Entry
9
+ @Component
10
+ struct ObjectLiteralTypeError {
11
+ @State windowSize: WindowSize = { width: 0, height: 0 };
12
+
13
+ aboutToAppear() {
14
+ this.windowSize = this.getWindowSize();
15
+ }
16
+
17
+ private getWindowSize(): WindowSize {
18
+ const context = this.getUIContext().getHostContext() as common.UIAbilityContext;
19
+ const windowStage = context.windowStage;
20
+ if (!windowStage) {
21
+ return { width: 0, height: 0 };
22
+ }
23
+ const windowClass = windowStage.getMainWindowSync();
24
+ const windowProperties = windowClass.getWindowProperties();
25
+ return {
26
+ width: windowProperties.windowRect.width,
27
+ height: windowProperties.windowRect.height
28
+ };
29
+ }
30
+
31
+ build() {
32
+ Column() {
33
+ Text('Object Literal Type Error Example')
34
+ .fontSize(20)
35
+ .margin(20)
36
+
37
+ Text(`窗口宽度: ${this.windowSize.width}`)
38
+ .fontSize(16)
39
+ .margin(10)
40
+
41
+ Text(`窗口高度: ${this.windowSize.height}`)
42
+ .fontSize(16)
43
+ .margin(10)
44
+
45
+ Button('刷新窗口尺寸')
46
+ .onClick(() => {
47
+ this.windowSize = this.getWindowSize();
48
+ })
49
+ .margin(20)
50
+ }
51
+ .width('100%')
52
+ .height('100%')
53
+ }
54
+ }
@@ -0,0 +1,29 @@
1
+ interface Config {
2
+ width: number;
3
+ height: number;
4
+ color?: string;
5
+ }
6
+
7
+ @Entry
8
+ @Component
9
+ struct ObjectSpreadError {
10
+ @State config: Config = { width: 100, height: 100 };
11
+
12
+ build() {
13
+ Column() {
14
+ Text(`Width: ${this.config.width}, Height: ${this.config.height}`)
15
+ .fontSize(20)
16
+ .margin({ bottom: 20 })
17
+
18
+ Button('Update Config')
19
+ .onClick(() => {
20
+ const newConfig: Config = {
21
+ width: this.config.width,
22
+ height: this.config.height,
23
+ color: 'red'
24
+ };
25
+ this.config = newConfig;
26
+ })
27
+ }
28
+ }
29
+ }
@@ -0,0 +1,32 @@
1
+ import { display } from '@kit.ArkUI';
2
+
3
+ @Entry
4
+ @Component
5
+ struct PossiblyNullError {
6
+ private myDisplay: display.Display | null = null;
7
+
8
+ aboutToAppear() {
9
+ this.myDisplay = display.getDefaultDisplaySync();
10
+ }
11
+
12
+ build() {
13
+ Column() {
14
+ if (this.myDisplay !== null) {
15
+ Text(`Width: ${this.myDisplay.width}`)
16
+ .fontSize(24)
17
+ } else {
18
+ Text('Display not available')
19
+ .fontSize(24)
20
+ }
21
+
22
+ Button('Check Display')
23
+ .onClick(() => {
24
+ if (this.myDisplay !== null) {
25
+ console.log(`Display: ${this.myDisplay.width}x${this.myDisplay.height}`);
26
+ }
27
+ })
28
+ }
29
+ .width('100%')
30
+ .height('100%')
31
+ }
32
+ }
@@ -0,0 +1,159 @@
1
+ import { hilog } from '@kit.PerformanceAnalysisKit';
2
+
3
+ const DOMAIN = 0xFF00;
4
+ const TAG = 'ResourceConversionError';
5
+
6
+ @Entry
7
+ @Component
8
+ struct ResourceConversionError {
9
+ @State displayText: string = '';
10
+ @State fontSize: number = 16;
11
+ @State paddingValue: number = 10;
12
+
13
+ loadStringResource() {
14
+ try {
15
+ const context = this.getUIContext().getHostContext();
16
+ if (!context) {
17
+ hilog.error(DOMAIN, TAG, 'Context is null or undefined');
18
+ this.displayText = '加载失败';
19
+ return;
20
+ }
21
+ const manager = context.resourceManager;
22
+ const resourceId = $r('app.string.hello').id;
23
+ this.displayText = manager.getString(resourceId);
24
+ hilog.info(DOMAIN, TAG, 'String resource loaded: %{public}s', this.displayText);
25
+ } catch (err) {
26
+ hilog.error(DOMAIN, TAG, 'Failed to load string resource: %{public}s',
27
+ JSON.stringify(err));
28
+ this.displayText = '加载失败';
29
+ }
30
+ }
31
+
32
+ loadNumberResource() {
33
+ try {
34
+ const context = this.getUIContext().getHostContext();
35
+ if (!context) {
36
+ hilog.error(DOMAIN, TAG, 'Context is null or undefined');
37
+ this.fontSize = 16;
38
+ return;
39
+ }
40
+ const manager = context.resourceManager;
41
+ const resourceId = $r('app.float.title_font_size').id;
42
+ this.fontSize = manager.getNumber(resourceId);
43
+ hilog.info(DOMAIN, TAG, 'Number resource loaded: %{public}d', this.fontSize);
44
+ } catch (err) {
45
+ hilog.error(DOMAIN, TAG, 'Failed to load number resource: %{public}s',
46
+ JSON.stringify(err));
47
+ this.fontSize = 16;
48
+ }
49
+ }
50
+
51
+ build() {
52
+ Column() {
53
+ Text('Resource 类型转换错误示例')
54
+ .fontSize($r('app.float.title_font_size'))
55
+ .fontWeight(FontWeight.Bold)
56
+ .margin({ top: 20, bottom: 20 })
57
+
58
+ Text('错误写法(不推荐):')
59
+ .fontSize(14)
60
+ .fontWeight(FontWeight.Bold)
61
+ .margin({ bottom: 10 })
62
+
63
+ Text(`const message: string = $r('app.string.hello');`)
64
+ .fontSize(12)
65
+ .fontColor('#FF0000')
66
+ .fontFamily('monospace')
67
+ .padding(10)
68
+ .backgroundColor('#FFF0F0')
69
+ .borderRadius(4)
70
+ .margin({ bottom: 20 })
71
+
72
+ Text('正确写法(推荐):')
73
+ .fontSize(14)
74
+ .fontWeight(FontWeight.Bold)
75
+ .margin({ bottom: 10 })
76
+
77
+ Text('直接在 UI 组件中使用 Resource 类型')
78
+ .fontSize(12)
79
+ .fontColor('#666666')
80
+ .margin({ bottom: 10 })
81
+
82
+ Text($r('app.string.hello'))
83
+ .fontSize($r('app.float.content_font_size'))
84
+ .width($r('app.float.layout_width'))
85
+ .padding($r('app.float.padding'))
86
+ .backgroundColor($r('app.color.background_color'))
87
+ .borderRadius($r('app.float.border_radius'))
88
+ .margin({ bottom: 20 })
89
+
90
+ Text('方案1:直接在 UI 组件中使用(推荐)')
91
+ .fontSize(14)
92
+ .fontWeight(FontWeight.Bold)
93
+ .margin({ bottom: 10 })
94
+
95
+ Text('Resource 类型可以直接作为属性值传递给 UI 组件')
96
+ .fontSize(12)
97
+ .fontColor('#666666')
98
+ .margin({ bottom: 10 })
99
+
100
+ Text('方案2:使用 ResourceManager 获取实际值')
101
+ .fontSize(14)
102
+ .fontWeight(FontWeight.Bold)
103
+ .margin({ bottom: 10 })
104
+
105
+ Row() {
106
+ Button('加载字符串资源')
107
+ .onClick(() => {
108
+ this.loadStringResource();
109
+ })
110
+ .margin({ right: 10 })
111
+
112
+ Button('加载数值资源')
113
+ .onClick(() => {
114
+ this.loadNumberResource();
115
+ })
116
+ }
117
+ .margin({ bottom: 20 })
118
+
119
+ if (this.displayText) {
120
+ Text(`加载的字符串: ${this.displayText}`)
121
+ .fontSize(14)
122
+ .margin(20)
123
+ }
124
+
125
+ if (this.fontSize !== 16) {
126
+ Text(`加载的字体大小: ${this.fontSize}`)
127
+ .fontSize(14)
128
+ .margin(20)
129
+ }
130
+
131
+ Text('说明:')
132
+ .fontSize(14)
133
+ .fontWeight(FontWeight.Bold)
134
+ .margin({ top: 20, bottom: 10 })
135
+
136
+ Text('• Resource 类型不能直接转换为 string 或 number')
137
+ .fontSize(12)
138
+ .fontColor('#666666')
139
+ .margin({ bottom: 5 })
140
+
141
+ Text('• 直接在 UI 组件中使用 Resource 类型')
142
+ .fontSize(12)
143
+ .fontColor('#666666')
144
+ .margin({ bottom: 5 })
145
+
146
+ Text('• 使用 ResourceManager 获取实际值')
147
+ .fontSize(12)
148
+ .fontColor('#666666')
149
+ .margin({ bottom: 5 })
150
+
151
+ Text('• Resource 支持多语言和主题适配')
152
+ .fontSize(12)
153
+ .fontColor('#666666')
154
+ }
155
+ .width('100%')
156
+ .height('100%')
157
+ .padding(20)
158
+ }
159
+ }
@@ -0,0 +1,116 @@
1
+ import { window } from '@kit.ArkUI';
2
+ import { common } from '@kit.AbilityKit';
3
+
4
+ async function getAvoidArea(context: common.UIAbilityContext): Promise<window.AvoidArea> {
5
+ return new Promise((resolve, reject) => {
6
+ window.getLastWindow(context, (err, win) => {
7
+ if (err.code !== 0) {
8
+ reject(new Error(err.message));
9
+ return;
10
+ }
11
+ const avoidArea = win.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM);
12
+ resolve(avoidArea);
13
+ });
14
+ });
15
+ }
16
+
17
+ async function setImmersiveWindow(context: common.UIAbilityContext): Promise<void> {
18
+ return new Promise((resolve, reject) => {
19
+ window.getLastWindow(context, (err, win) => {
20
+ if (err.code !== 0) {
21
+ reject(new Error(err.message));
22
+ return;
23
+ }
24
+ win.setWindowLayoutFullScreen(true).then(() => {
25
+ resolve();
26
+ }).catch((error: Error) => {
27
+ reject(new Error(error.message));
28
+ });
29
+ });
30
+ });
31
+ }
32
+
33
+ async function getTitleButtonRect(context: common.UIAbilityContext): Promise<window.TitleButtonRect> {
34
+ return new Promise((resolve, reject) => {
35
+ window.getLastWindow(context, (err, win) => {
36
+ if (err.code !== 0) {
37
+ reject(new Error(err.message));
38
+ return;
39
+ }
40
+ const titleButtonRect = win.getTitleButtonRect();
41
+ resolve(titleButtonRect);
42
+ });
43
+ });
44
+ }
45
+
46
+ async function getWindowProperties(context: common.UIAbilityContext): Promise<window.WindowProperties> {
47
+ return new Promise((resolve, reject) => {
48
+ window.getLastWindow(context, (err, win) => {
49
+ if (err.code !== 0) {
50
+ reject(new Error(err.message));
51
+ return;
52
+ }
53
+ const properties = win.getWindowProperties();
54
+ resolve(properties);
55
+ });
56
+ });
57
+ }
58
+
59
+ @Entry
60
+ @Component
61
+ struct StandaloneFunctionExample {
62
+ @State avoidAreaHeight: number = 0;
63
+ @State isImmersive: boolean = false;
64
+ @State titleBarHeight: number = 0;
65
+ @State windowWidth: number = 0;
66
+ @State windowHeight: number = 0;
67
+
68
+ async aboutToAppear() {
69
+ const context = this.getUIContext().getHostContext() as common.UIAbilityContext;
70
+
71
+ try {
72
+ const avoidArea = await getAvoidArea(context);
73
+ this.avoidAreaHeight = avoidArea.topRect.height;
74
+ } catch (err) {
75
+ console.error('获取避让区域失败:', err instanceof Error ? err.message : String(err));
76
+ }
77
+
78
+ try {
79
+ await setImmersiveWindow(context);
80
+ this.isImmersive = true;
81
+ } catch (err) {
82
+ console.error('设置沉浸式窗口失败:', err instanceof Error ? err.message : String(err));
83
+ }
84
+
85
+ try {
86
+ const titleButtonRect = await getTitleButtonRect(context);
87
+ this.titleBarHeight = titleButtonRect.height;
88
+ } catch (err) {
89
+ console.error('获取标题栏按钮区域失败:', err instanceof Error ? err.message : String(err));
90
+ }
91
+
92
+ try {
93
+ const properties = await getWindowProperties(context);
94
+ this.windowWidth = properties.windowRect.width;
95
+ this.windowHeight = properties.windowRect.height;
96
+ } catch (err) {
97
+ console.error('获取窗口属性失败:', err instanceof Error ? err.message : String(err));
98
+ }
99
+ }
100
+
101
+ build() {
102
+ Column() {
103
+ Text('独立函数上下文传递示例')
104
+ .fontSize(20)
105
+ .fontWeight(FontWeight.Bold)
106
+ .margin({ bottom: 20 })
107
+
108
+ Text(`避让区域高度: ${this.avoidAreaHeight}`)
109
+ Text(`沉浸式状态: ${this.isImmersive}`)
110
+ Text(`标题栏高度: ${this.titleBarHeight}`)
111
+ Text(`窗口宽度: ${this.windowWidth}`)
112
+ Text(`窗口高度: ${this.windowHeight}`)
113
+ }
114
+ .padding(20)
115
+ }
116
+ }
@@ -0,0 +1,85 @@
1
+ import { window } from '@kit.ArkUI';
2
+ import { common } from '@kit.AbilityKit';
3
+
4
+ async function getAvoidArea(context: common.UIAbilityContext): Promise<window.AvoidArea> {
5
+ return new Promise((resolve, reject) => {
6
+ window.getLastWindow(context, (err, win) => {
7
+ if (err.code !== 0) {
8
+ reject(new Error(err.message));
9
+ return;
10
+ }
11
+ const avoidArea = win.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM);
12
+ resolve(avoidArea);
13
+ });
14
+ });
15
+ }
16
+
17
+ async function setImmersiveWindow(context: common.UIAbilityContext): Promise<void> {
18
+ return new Promise((resolve, reject) => {
19
+ window.getLastWindow(context, (err, win) => {
20
+ if (err.code !== 0) {
21
+ reject(new Error(err.message));
22
+ return;
23
+ }
24
+ win.setWindowLayoutFullScreen(true).then(() => {
25
+ resolve();
26
+ }).catch((error: Error) => {
27
+ reject(new Error(error.message));
28
+ });
29
+ });
30
+ });
31
+ }
32
+
33
+ async function getTitleButtonRect(context: common.UIAbilityContext): Promise<window.TitleButtonRect> {
34
+ return new Promise((resolve, reject) => {
35
+ window.getLastWindow(context, (err, win) => {
36
+ if (err.code !== 0) {
37
+ reject(new Error(err.message));
38
+ return;
39
+ }
40
+ const titleButtonRect = win.getTitleButtonRect();
41
+ resolve(titleButtonRect);
42
+ });
43
+ });
44
+ }
45
+
46
+ @Entry
47
+ @Component
48
+ struct StandaloneFunctionError {
49
+ @State avoidAreaHeight: number = 0;
50
+ @State isImmersive: boolean = false;
51
+ @State titleBarHeight: number = 0;
52
+
53
+ async aboutToAppear() {
54
+ const context = this.getUIContext().getHostContext() as common.UIAbilityContext;
55
+
56
+ try {
57
+ const avoidArea = await getAvoidArea(context);
58
+ this.avoidAreaHeight = avoidArea.topRect.height;
59
+ } catch (err) {
60
+ console.error('获取避让区域失败:', err instanceof Error ? err.message : String(err));
61
+ }
62
+
63
+ try {
64
+ await setImmersiveWindow(context);
65
+ this.isImmersive = true;
66
+ } catch (err) {
67
+ console.error('设置沉浸式窗口失败:', err instanceof Error ? err.message : String(err));
68
+ }
69
+
70
+ try {
71
+ const titleButtonRect = await getTitleButtonRect(context);
72
+ this.titleBarHeight = titleButtonRect.height;
73
+ } catch (err) {
74
+ console.error('获取标题栏按钮区域失败:', err instanceof Error ? err.message : String(err));
75
+ }
76
+ }
77
+
78
+ build() {
79
+ Column() {
80
+ Text(`避让区域高度: ${this.avoidAreaHeight}`)
81
+ Text(`沉浸式状态: ${this.isImmersive}`)
82
+ Text(`标题栏高度: ${this.titleBarHeight}`)
83
+ }
84
+ }
85
+ }
@@ -0,0 +1,41 @@
1
+ import { window } from '@kit.ArkUI';
2
+ import { common } from '@kit.AbilityKit';
3
+
4
+ @Entry
5
+ @Component
6
+ struct StorageLinkDefaultError {
7
+ @StorageLink('windowUtil') windowUtil?: WindowUtil = undefined;
8
+
9
+ aboutToAppear() {
10
+ AppStorage.setOrCreate('windowUtil', {
11
+ width: 0,
12
+ height: 0,
13
+ density: 1.0,
14
+ updateWindowInfo: () => {},
15
+ destroy: () => {}
16
+ });
17
+ }
18
+
19
+ build() {
20
+ Column() {
21
+ Text(`Window Util: ${this.windowUtil?.width || 0}`)
22
+ .fontSize(20)
23
+ .margin({ bottom: 20 })
24
+
25
+ Button('Update Window')
26
+ .onClick(() => {
27
+ if (this.windowUtil) {
28
+ this.windowUtil.width = 100;
29
+ }
30
+ })
31
+ }
32
+ }
33
+ }
34
+
35
+ interface WindowUtil {
36
+ width: number;
37
+ height: number;
38
+ density: number;
39
+ updateWindowInfo: () => void;
40
+ destroy: () => void;
41
+ }