Skip to content

Commit 19d6f81

Browse files
committed
fix: resolve CI build errors, formatting and clippy warnings
- Move `dirs` crate from macOS-specific to main dependencies - Remove unused `Sizable` import in app.rs - Add #[allow(dead_code)] for planned features - Fix code formatting issues - Fix clippy warnings (manual_async_fn, too_many_arguments, vec_init_then_push, ptr_arg, if_same_then_else)
1 parent 88984de commit 19d6f81

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+631
-286
lines changed

.claude/skills/gpui.md

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
# GPUI UI framework best practices for building desktop applications. Use when writing GPUI code, creating UI components, handling state/events, async tasks, animations, lists, forms, testing, or working with Zed-style Rust GUI code.
2+
3+
## 布局常见错误
4+
5+
### 1. `w_full() + margin` 导致溢出
6+
7+
**错误写法**
8+
```rust
9+
// ❌ 子元素 w_full() + mx_2() = 100% + margin = 溢出
10+
div().w_full().child(
11+
ListItem::new("item")
12+
.w_full()
13+
.mx_2() // 这会导致溢出!
14+
)
15+
```
16+
17+
**正确写法**
18+
```rust
19+
// ✅ 父容器用 padding 代替子元素 margin
20+
div().w_full().px_2().child(
21+
ListItem::new("item")
22+
.w_full()
23+
)
24+
```
25+
26+
**原理**:CSS 盒模型中 `width: 100%` 不包含 margin,添加 margin 后总宽度超出容器。
27+
28+
### 2. VirtualList 固定高度
29+
30+
VirtualList 需要预计算每个 item 的尺寸:
31+
32+
```rust
33+
// 定义固定高度常量
34+
const ITEM_HEIGHT: f32 = 40.0;
35+
36+
// 构建尺寸数组
37+
let sizes: Vec<Size<Pixels>> = items
38+
.iter()
39+
.map(|_| size(px(WIDTH), px(ITEM_HEIGHT)))
40+
.collect();
41+
42+
// 使用 VirtualList
43+
v_virtual_list(
44+
cx.entity().clone(),
45+
"list-id",
46+
Rc::new(sizes),
47+
|view, visible_range, _, cx| {
48+
visible_range.map(|ix| /* render item */).collect()
49+
},
50+
)
51+
.w_full()
52+
.flex_1()
53+
.track_scroll(&scroll_handle)
54+
```
55+
56+
### 3. 滚动容器必须有约束高度
57+
58+
```rust
59+
// ❌ 错误:没有高度约束,无法滚动
60+
v_flex()
61+
.overflow_y_scroll()
62+
.children(items)
63+
64+
// ✅ 正确:使用 flex_1() 或固定高度
65+
v_flex()
66+
.flex_1() // 或 .h(px(400.))
67+
.min_h_0() // 重要:允许收缩
68+
.overflow_y_scroll()
69+
.children(items)
70+
```
71+
72+
## 组件模式
73+
74+
### Entity 状态管理
75+
76+
```rust
77+
pub struct MyComponent {
78+
state: SomeState,
79+
}
80+
81+
impl MyComponent {
82+
pub fn new(cx: &mut Context<Self>) -> Self {
83+
Self { state: SomeState::default() }
84+
}
85+
86+
pub fn update_state(&mut self, value: T, cx: &mut Context<Self>) {
87+
self.state = value;
88+
cx.notify(); // 通知 UI 重新渲染
89+
}
90+
}
91+
92+
impl Render for MyComponent {
93+
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
94+
// 渲染逻辑
95+
}
96+
}
97+
```
98+
99+
### 事件发射
100+
101+
```rust
102+
pub struct MyEvent {
103+
pub data: String,
104+
}
105+
106+
impl EventEmitter<MyEvent> for MyComponent {}
107+
108+
// 发射事件
109+
cx.emit(MyEvent { data: "value".to_string() });
110+
111+
// 订阅事件
112+
cx.subscribe(&component, |this, _, event: &MyEvent, cx| {
113+
// 处理事件
114+
});
115+
```
116+
117+
### 异步任务
118+
119+
```rust
120+
cx.spawn(async move |this, cx| {
121+
let result = async_operation().await;
122+
let _ = cx.update(|app| {
123+
let _ = this.update(app, |this, cx| {
124+
this.data = result;
125+
cx.notify();
126+
});
127+
});
128+
}).detach();
129+
```
130+
131+
## 主题使用
132+
133+
```rust
134+
use gpui_component::{ActiveTheme, Theme, ThemeMode};
135+
136+
// 获取主题
137+
let theme = cx.theme();
138+
139+
// 使用主题颜色
140+
div()
141+
.bg(theme.background)
142+
.text_color(theme.foreground)
143+
.border_color(theme.border)
144+
145+
// 切换主题
146+
Theme::change(ThemeMode::Dark, Some(window), cx);
147+
```
148+
149+
## 常用布局
150+
151+
```rust
152+
use gpui_component::{h_flex, v_flex};
153+
154+
// 水平布局
155+
h_flex()
156+
.gap_2()
157+
.items_center()
158+
.justify_between()
159+
.children(items)
160+
161+
// 垂直布局
162+
v_flex()
163+
.gap_4()
164+
.p_4()
165+
.children(items)
166+
167+
// 条件渲染
168+
div()
169+
.when(condition, |this| this.child(element))
170+
.when_some(option_value, |this, value| this.child(value))
171+
```

.github/workflows/release.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ jobs:
5656
run: cargo install cargo-bundle
5757

5858
- name: Build release binary
59+
env:
60+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5961
run: cargo build --release --target ${{ matrix.target }}
6062

6163
- name: Bundle macOS app
@@ -91,6 +93,8 @@ jobs:
9193
run: cargo install cargo-bundle
9294

9395
- name: Build both architectures
96+
env:
97+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9498
run: |
9599
cargo build --release --target aarch64-apple-darwin
96100
cargo build --release --target x86_64-apple-darwin

.github/workflows/rust-ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ jobs:
4343
mold
4444
4545
- name: Check workspace
46+
env:
47+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4648
run: cargo check
4749

4850
fmt:
@@ -88,6 +90,8 @@ jobs:
8890
run: rustup component add clippy
8991

9092
- name: Run clippy
93+
env:
94+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9195
run: cargo clippy --all-targets
9296

9397
# test:
@@ -128,4 +132,6 @@ jobs:
128132
mold
129133
130134
- name: Build workspace
135+
env:
136+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
131137
run: cargo build

.pre-commit-config.yaml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
repos:
2-
- repo: https://github.com/fsfe/reuse-tool
3-
rev: v6.2.0
2+
- repo: local
43
hooks:
5-
- id: reuse
4+
- id: cargo-fmt
5+
name: cargo fmt
6+
entry: cargo fmt -- --check
7+
language: system
8+
types: [rust]
9+
pass_filenames: false
10+
11+
- id: cargo-clippy
12+
name: cargo clippy
13+
entry: cargo clippy -- -D warnings
14+
language: system
15+
types: [rust]
16+
pass_filenames: false
17+
18+
# - repo: https://github.com/fsfe/reuse-tool
19+
# rev: v6.2.0
20+
# hooks:
21+
# - id: reuse

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ sea-orm-migration = { version = "1.1", features = ["runtime-tokio-rustls"] }
8686
# Random password generation
8787
rand = "0.9"
8888

89+
# Config directory
90+
dirs = "5"
91+
8992
# Unix process management
9093
[target.'cfg(unix)'.dependencies]
9194
libc = "0.2"
@@ -94,9 +97,6 @@ libc = "0.2"
9497
[target.'cfg(target_os = "macos")'.dependencies]
9598
cocoa = "0.26"
9699

97-
# Config directory
98-
dirs = "5"
99-
100100
[package.metadata.bundle]
101101
name = "ChatGPUI"
102102
identifier = "com.aprilnea.chatgpui"

assets/icons/brand/deepseek.svg

Lines changed: 1 addition & 0 deletions
Loading

assets/icons/brand/google.svg

Lines changed: 1 addition & 0 deletions
Loading

assets/icons/brand/grok-dark.svg

Lines changed: 1 addition & 0 deletions
Loading

assets/icons/brand/grok-light.svg

Lines changed: 1 addition & 0 deletions
Loading

assets/icons/brand/kimi-icon.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)