Skip to content

Commit 6d82c28

Browse files
committed
docs: merge some future to migrate docs
1 parent 5939e1d commit 6d82c28

File tree

5 files changed

+323
-94
lines changed

5 files changed

+323
-94
lines changed

docs-source/src/.vuepress/configs/template.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const navigationLinks = {
1616
'/config/api-exception',
1717
'/config/xposed-using',
1818
'/config/api-using',
19+
'/config/move-to-api-1-2-x',
1920
'/config/r8-proguard'
2021
],
2122
tools: '/tools/yukihookapi-projectbuilder',
@@ -143,7 +144,8 @@ export const navBarItems = {
143144
{ text: 'API Exception Handling', link: i18n.string(navigationLinks.config[1], 'en') },
144145
{ text: 'Use as Xposed Module Configs', link: i18n.string(navigationLinks.config[2], 'en') },
145146
{ text: 'Use as Hook API Configs', link: i18n.string(navigationLinks.config[3], 'en') },
146-
{ text: 'R8 & Proguard Obfuscate', link: i18n.string(navigationLinks.config[4], 'en') }
147+
{ text: 'Migrate to YukiHookAPI 1.2.x', link: i18n.string(navigationLinks.config[4], 'en') },
148+
{ text: 'R8 & Proguard Obfuscate', link: i18n.string(navigationLinks.config[5], 'en') }
147149
]
148150
}, {
149151
text: 'Tools',
@@ -193,7 +195,8 @@ export const navBarItems = {
193195
{ text: 'API 异常处理', link: i18n.string(navigationLinks.config[1], 'zh-cn') },
194196
{ text: '作为 Xposed 模块使用的相关配置', link: i18n.string(navigationLinks.config[2], 'zh-cn') },
195197
{ text: '作为 Hook API 使用的相关配置', link: i18n.string(navigationLinks.config[3], 'zh-cn') },
196-
{ text: 'R8 与 Proguard 混淆', link: i18n.string(navigationLinks.config[4], 'zh-cn') }
198+
{ text: '迁移到 YukiHookAPI 1.2.x', link: i18n.string(navigationLinks.config[4], 'zh-cn') },
199+
{ text: 'R8 与 Proguard 混淆', link: i18n.string(navigationLinks.config[5], 'zh-cn') }
197200
]
198201
}, {
199202
text: '工具',

docs-source/src/en/about/future.md

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -58,50 +58,4 @@ All functions are expected to be completed in `2.0.0` version, so stay tuned.
5858

5959
- [New Xposed Module Config Plan](https://github.com/fankes/YukiHookAPI/issues/49)
6060
- [New Hook Entry Class](https://github.com/fankes/YukiHookAPI/issues/48)
61-
- [New Hook Code Style](https://github.com/fankes/YukiHookAPI/issues/33)
62-
63-
#### New Hook Code Style (Preview)
64-
65-
`YukiHookAPI` introduced the `New Hook Code Style` (New API) of `2.0.0` in the `1.2.0` version, it is now in the experimental stage.
66-
67-
You can before the `2.0.0` version is officially released, start migrating and experience the New API.
68-
69-
For example, we want to Hook the `test` method in the `com.example.Test` class.
70-
71-
> Legacy API
72-
73-
```kotlin
74-
findClass("com.example.Test").hook {
75-
injectMember {
76-
method {
77-
name = "test"
78-
}
79-
beforeHook {
80-
// Your code here.
81-
}
82-
afterHook {
83-
// Your code here.
84-
}
85-
}
86-
}
87-
```
88-
89-
> New API
90-
91-
```kotlin
92-
"com.example.Test".toClass()
93-
.method {
94-
name = "test"
95-
}.hook {
96-
before {
97-
// Your code here.
98-
}
99-
after {
100-
// Your code here.
101-
}
102-
}
103-
```
104-
105-
The Hook object of the New API has been migrated from `Class` to `Member`, which will be more intuitive.
106-
107-
All legacy APIs have been marked `LegacyHookApi`, you can use `@OptIn(LegacyHookApi::class)` to eliminate the warning and continue to use the legacy API.
61+
- [New Hook Code Style](https://github.com/fankes/YukiHookAPI/issues/33)
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# Migrate to YukiHookAPI 1.2.x
2+
3+
`YukiHookAPI` has undergone a lot of adjustments since version `1.2.0`, you can read on to see what are the notes and new features.
4+
5+
## Default Behavior Changes
6+
7+
Since version `1.2.0`, the `isUsingResourcesHook` function in `@InjectYukiHookWithXposed` is no longer enabled by default, please enable it manually if necessary.
8+
9+
::: warning
10+
11+
Resources Hook will be removed in version **2.0.0** and is now marked **LegacyResourcesHook**.
12+
13+
You can use **@OptIn(LegacyResourcesHook::class)** to eliminate the warning, continue to use version **1.x.x**.
14+
15+
:::
16+
17+
## New API
18+
19+
`YukiHookAPI` introduced the [New Hook Code Style](https://github.com/fankes/YukiHookAPI/issues/33) (New API) of `2.0.0` in the `1.2.0` version, it is now in the experimental stage.
20+
21+
You can before the `2.0.0` version is officially released, start migrating and experience the New API.
22+
23+
::: warning
24+
25+
All legacy APIs have been marked **LegacyHookApi**, you can use **@OptIn(LegacyHookApi::class)** to eliminate the warning and continue to use the legacy API.
26+
27+
:::
28+
29+
For example, we want to Hook the `test` method in the `com.example.Test` class.
30+
31+
> Legacy API
32+
33+
```kotlin
34+
findClass("com.example.Test").hook {
35+
injectMember {
36+
method {
37+
name = "test"
38+
}
39+
beforeHook {
40+
// Your code here.
41+
}
42+
afterHook {
43+
// Your code here.
44+
}
45+
}
46+
}
47+
```
48+
49+
> New API
50+
51+
```kotlin
52+
"com.example.Test".toClass()
53+
.method {
54+
name = "test"
55+
}.hook {
56+
before {
57+
// Your code here.
58+
}
59+
after {
60+
// Your code here.
61+
}
62+
}
63+
```
64+
65+
The Hook object of the New API has been migrated from `Class` to `Member`, which will be more intuitive.
66+
67+
## Differential Functions
68+
69+
The following are some of the different functions of connecting to the new version of the API.
70+
71+
### New Multi-Hook Usage
72+
73+
Previously we needed to hook all methods that match conditions like this.
74+
75+
> The following example
76+
77+
```kotlin
78+
injectMembers {
79+
method {
80+
name { it.contains("some") }
81+
}.all()
82+
afterHook {
83+
// Your code here.
84+
}
85+
}
86+
```
87+
88+
Now, you can use the following method instead.
89+
90+
> The following example
91+
92+
```kotlin
93+
method {
94+
name { it.contains("some") }
95+
}.hookAll {
96+
after {
97+
// Your code here.
98+
}
99+
}
100+
```
101+
102+
### New `allMembers(...)` Usage
103+
104+
Previously we needed to hook all methods and constructors like this.
105+
106+
> The following example
107+
108+
```kotlin
109+
injectMembers {
110+
allMembers(MembersType.METHOD)
111+
afterHook {
112+
// Your code here.
113+
}
114+
}
115+
```
116+
117+
```kotlin
118+
injectMembers {
119+
allMembers(MembersType.CONSTRUCTOR)
120+
afterHook {
121+
// Your code here.
122+
}
123+
}
124+
```
125+
126+
Now, you can use the following method instead.
127+
128+
> The following example
129+
130+
```kotlin
131+
method().hookAll {
132+
after {
133+
// Your code here.
134+
}
135+
}
136+
```
137+
138+
```kotlin
139+
constructor().hookAll {
140+
after {
141+
// Your code here.
142+
}
143+
}
144+
```
145+
146+
When the find conditions are not filled in, all members in the current `Class` are obtained by default.
147+
148+
If you want to hook `MembersType.ALL`, there is currently no direct method, but you can concatenate all members and then hook.
149+
150+
> The following example
151+
152+
```kotlin
153+
(method().giveAll() + constructor().giveAll()).hookAll {
154+
after {
155+
// Your code here.
156+
}
157+
}
158+
```
159+
160+
But we do not recommend this approach, too many hook members at one time are uncontrollable and problems may occur.

docs-source/src/zh-cn/about/future.md

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -52,48 +52,4 @@ API 已经提供了 Xposed 原生 API 监听接口,你可以 [在这里](../co
5252

5353
- [New Xposed Module Config Plan](https://github.com/fankes/YukiHookAPI/issues/49)
5454
- [New Hook Entry Class](https://github.com/fankes/YukiHookAPI/issues/48)
55-
- [New Hook Code Style](https://github.com/fankes/YukiHookAPI/issues/33)
56-
57-
#### New Hook Code Style (Preview)
58-
59-
`YukiHookAPI``1.2.0` 版本引入了 `2.0.0` 准备实现的 `New Hook Code Style` (新版 API),现处于实验性阶段,你可以在 `2.0.0` 版本正式发布前,开始迁移并体验新版 API。
60-
61-
例如,我们要 Hook `com.example.Test` 类中的 `test` 方法。
62-
63-
> 旧版 API
64-
65-
```kotlin
66-
findClass("com.example.Test").hook {
67-
injectMember {
68-
method {
69-
name = "test"
70-
}
71-
beforeHook {
72-
// Your code here.
73-
}
74-
afterHook {
75-
// Your code here.
76-
}
77-
}
78-
}
79-
```
80-
81-
> 新版 API
82-
83-
```kotlin
84-
"com.example.Test".toClass()
85-
.method {
86-
name = "test"
87-
}.hook {
88-
before {
89-
// Your code here.
90-
}
91-
after {
92-
// Your code here.
93-
}
94-
}
95-
```
96-
97-
新版 API 的 Hook 对象从 `Class` 迁移到了 `Member`,这种方式将更加直观。
98-
99-
所有旧版 API 已被标记 `LegacyHookApi`,你可以使用 `@OptIn(LegacyHookApi::class)` 的方式消除警告,继续使用旧版 API。
55+
- [New Hook Code Style](https://github.com/fankes/YukiHookAPI/issues/33)

0 commit comments

Comments
 (0)