Skip to content

Commit 8883a3f

Browse files
[feat]修改UI+优化很多细节
1 parent c0c1158 commit 8883a3f

34 files changed

Lines changed: 7838 additions & 5534 deletions

‎package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"release:preview:minor": "node scripts/release.mjs minor --channel preview",
1515
"release:preview:major": "node scripts/release.mjs major --channel preview",
1616
"tauri": "tauri",
17-
"tauri:dev": "tauri dev",
18-
"tauri:build": "tauri build",
17+
"tauri:dev": "node scripts/run-tauri-channel.mjs auto dev",
18+
"tauri:build": "node scripts/run-tauri-channel.mjs auto build",
1919
"tauri:dev:preview": "node scripts/run-tauri-channel.mjs preview dev",
2020
"tauri:build:preview": "node scripts/run-tauri-channel.mjs preview build"
2121
},

‎scripts/run-tauri-channel.mjs‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import path from "node:path";
44
import process from "node:process";
55
import { fileURLToPath } from "node:url";
66
import { spawnSync } from "node:child_process";
7+
import fs from "node:fs";
78

89
const __filename = fileURLToPath(import.meta.url);
910
const __dirname = path.dirname(__filename);
@@ -13,7 +14,7 @@ const [, , channelArg, tauriCommand, ...extraArgs] = process.argv;
1314
const channel = normalizeChannel(channelArg);
1415

1516
if (!channel) {
16-
fail("Missing channel. Use stable or preview.");
17+
fail("Missing channel. Use auto, stable or preview.");
1718
}
1819

1920
if (!tauriCommand) {
@@ -42,17 +43,25 @@ process.exit(1);
4243

4344
function normalizeChannel(value) {
4445
const channel = String(value || "").trim().toLowerCase();
46+
if (channel === "auto") {
47+
return readPackageVersion().includes("-preview.") ? "preview" : "stable";
48+
}
4549
if (channel === "stable" || channel === "preview") {
4650
return channel;
4751
}
4852
return "";
4953
}
5054

55+
function readPackageVersion() {
56+
const packageJsonPath = path.join(repoRoot, "package.json");
57+
return JSON.parse(fs.readFileSync(packageJsonPath, "utf8")).version ?? "";
58+
}
59+
5160
function resolveNpxCommand() {
5261
return process.platform === "win32" ? "npx.cmd" : "npx";
5362
}
5463

5564
function fail(message) {
5665
console.error(`Error: ${message}`);
5766
process.exit(1);
58-
}
67+
}

‎src-tauri/src/app.rs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1+
#[cfg(not(target_os = "macos"))]
2+
use tauri::menu::HELP_SUBMENU_ID;
13
use tauri::{
24
menu::{Menu, MenuItemBuilder, PredefinedMenuItem},
35
Emitter, Manager,
46
};
5-
#[cfg(not(target_os = "macos"))]
6-
use tauri::menu::HELP_SUBMENU_ID;
77

88
use crate::update::{UPDATE_MENU_EVENT, UPDATE_MENU_ID};
99

1010
pub(crate) fn run() {
1111
tauri::Builder::default()
1212
.invoke_handler(tauri::generate_handler![
1313
crate::repository::scan::scan_directory,
14+
crate::repository::scan::inspect_path,
1415
crate::repository::worktree::add_worktree,
1516
crate::repository::worktree::remove_worktree,
1617
crate::repository::worktree::prune_worktrees,
1718
crate::repository::worktree::refresh_repository,
19+
crate::repository::worktree::clone_repository,
1820
crate::repository::scan::list_branches,
1921
crate::system::open_path,
2022
crate::system::open_url,
23+
crate::system::copy_text,
2124
crate::review::commands::list_pull_requests,
2225
crate::review::commands::count_pull_requests,
2326
crate::review::commands::get_pull_request_detail,
@@ -30,6 +33,7 @@ pub(crate) fn run() {
3033
crate::review::commands::merge_pull_request,
3134
crate::review::commands::list_pull_request_commits,
3235
crate::review::commands::list_pull_request_files,
36+
crate::review::commands::get_pull_request_file_content,
3337
crate::review::commands::list_repository_members,
3438
crate::review::commands::prepare_code_review,
3539
crate::review::commands::cleanup_code_review_worktree,

‎src-tauri/src/common.rs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ pub(crate) fn path_arg(path: &Path) -> String {
6666
path.to_string_lossy().to_string()
6767
}
6868

69+
pub(crate) async fn run_blocking<T, F>(task: F) -> Result<T, String>
70+
where
71+
T: Send + 'static,
72+
F: FnOnce() -> Result<T, String> + Send + 'static,
73+
{
74+
tauri::async_runtime::spawn_blocking(task)
75+
.await
76+
.map_err(|error| format!("Background task failed: {error}"))?
77+
}
78+
6979
fn home_dir() -> Option<PathBuf> {
7080
std::env::var_os("HOME").map(PathBuf::from)
7181
}

‎src-tauri/src/git.rs‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ pub(crate) fn git_stdout(repo_path: &Path, args: &[&str]) -> Result<String, Stri
3333
run_git(repo_path, &args)
3434
}
3535

36+
pub(crate) fn git_clone(remote_url: &str, target_path: &Path) -> Result<String, String> {
37+
let output = Command::new("git")
38+
.arg("clone")
39+
.arg(remote_url)
40+
.arg(target_path)
41+
.output()
42+
.map_err(|error| format!("Failed to run git clone: {error}"))?;
43+
44+
if output.status.success() {
45+
Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
46+
} else {
47+
Err(String::from_utf8_lossy(&output.stderr).trim().to_string())
48+
}
49+
}
50+
3651
pub(crate) fn list_git_remotes(repo_path: &Path) -> Result<Vec<GitRemoteInfo>, String> {
3752
let output = git_stdout(repo_path, &["remote", "-v"])?;
3853
let mut remotes: BTreeMap<String, GitRemoteInfo> = BTreeMap::new();

‎src-tauri/src/models/git.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ pub(crate) struct GitHttpAuth {
2424
pub(crate) access_token: String,
2525
}
2626

27-
pub(crate) type GiteeGitAuth = GitHttpAuth;
27+
pub(crate) type GiteeGitAuth = GitHttpAuth;

‎src-tauri/src/models/mod.rs‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ pub(crate) use provider::{
1212
GiteeRepositoryInfo, ReviewProviderCapabilities, ReviewProviderInfo, ReviewProviderKind,
1313
};
1414
pub(crate) use requests::{
15-
AddWorktreeRequest, GiteeCodeReviewRequest, GiteePullRequestActionRequest,
16-
GiteePullRequestDetailRequest, GiteePullRequestListRequest, OpenPathRequest, OpenUrlRequest,
17-
RemoveWorktreeRequest, ReviewProviderListRequest, ReviewProviderPullRequestRequest,
15+
AddWorktreeRequest, CloneRepositoryRequest, GiteeCodeReviewRequest,
16+
GiteePullRequestActionRequest, GiteePullRequestDetailRequest, GiteePullRequestListRequest,
17+
OpenPathRequest, OpenUrlRequest, RemoveWorktreeRequest, ReviewProviderListRequest,
18+
ReviewProviderPullRequestFileRequest, ReviewProviderPullRequestRequest,
1819
};
1920
pub(crate) use review::{
2021
CodeReviewResult, GiteePullRequestInfo, PullRequestChangedFileInfo, PullRequestCommitInfo,
21-
PullRequestInfo, PullRequestPage, RepositoryMemberInfo,
22+
PullRequestFileContent, PullRequestFilePreview, PullRequestInfo, PullRequestPage,
23+
RepositoryMemberInfo,
2224
};
23-
pub(crate) use scan::{BranchInfo, RepositoryInfo, ScanResult, WorktreeInfo};
24-
pub(crate) use update::ReleaseCheckResult;
25+
pub(crate) use scan::{BranchInfo, RepositoryInfo, ScanResult, WorktreeInfo, WorktreeStatus};
26+
pub(crate) use update::ReleaseCheckResult;

‎src-tauri/src/models/provider.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ pub(crate) struct ReviewProviderInfo {
4545
}
4646

4747
// Gitee 是最早接入的平台,这个别名保留旧命名,避免评审命令调用链大面积改名。
48-
pub(crate) type GiteeRepositoryInfo = ReviewProviderInfo;
48+
pub(crate) type GiteeRepositoryInfo = ReviewProviderInfo;

‎src-tauri/src/models/requests.rs‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ pub(crate) struct RemoveWorktreeRequest {
1919
pub(crate) force: bool,
2020
}
2121

22+
#[derive(Debug, Deserialize)]
23+
pub(crate) struct CloneRepositoryRequest {
24+
pub(crate) remote_url: String,
25+
pub(crate) parent_dir: String,
26+
pub(crate) directory_name: Option<String>,
27+
}
28+
2229
#[derive(Debug, Deserialize)]
2330
pub(crate) struct OpenPathRequest {
2431
pub(crate) path: String,
@@ -48,6 +55,14 @@ pub(crate) struct ReviewProviderPullRequestRequest {
4855
pub(crate) number: i64,
4956
}
5057

58+
#[derive(Debug, Deserialize)]
59+
pub(crate) struct ReviewProviderPullRequestFileRequest {
60+
pub(crate) repo_path: String,
61+
pub(crate) access_token: String,
62+
pub(crate) number: i64,
63+
pub(crate) filename: String,
64+
}
65+
5166
/// 审批、重置、测试通过等动作共用的请求体。
5267
///
5368
/// 后端会根据 `repo_path` 推导具体 provider 行为,因此请求层只需要携带仓库路径、
@@ -69,4 +84,4 @@ pub(crate) struct ReviewProviderCodeReviewRequest {
6984
pub(crate) type GiteePullRequestListRequest = ReviewProviderListRequest;
7085
pub(crate) type GiteePullRequestDetailRequest = ReviewProviderPullRequestRequest;
7186
pub(crate) type GiteePullRequestActionRequest = ReviewProviderPullRequestActionRequest;
72-
pub(crate) type GiteeCodeReviewRequest = ReviewProviderCodeReviewRequest;
87+
pub(crate) type GiteeCodeReviewRequest = ReviewProviderCodeReviewRequest;

‎src-tauri/src/models/review.rs‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@ pub(crate) struct CodeReviewResult {
4747
pub(crate) web_url: String,
4848
}
4949

50+
#[derive(Debug, Serialize)]
51+
pub(crate) struct PullRequestFilePreview {
52+
pub(crate) mime_type: String,
53+
pub(crate) data_url: String,
54+
pub(crate) size: usize,
55+
}
56+
57+
#[derive(Debug, Serialize)]
58+
pub(crate) struct PullRequestFileContent {
59+
pub(crate) filename: String,
60+
pub(crate) patch: Option<String>,
61+
pub(crate) image_preview: Option<PullRequestFilePreview>,
62+
pub(crate) binary: bool,
63+
pub(crate) message: Option<String>,
64+
}
65+
5066
#[derive(Debug, Serialize)]
5167
pub(crate) struct RepositoryMemberInfo {
5268
pub(crate) username: String,
@@ -76,4 +92,4 @@ pub(crate) struct PullRequestChangedFileInfo {
7692
pub(crate) blob_url: Option<String>,
7793
pub(crate) raw_url: Option<String>,
7894
pub(crate) patch: Option<String>,
79-
}
95+
}

0 commit comments

Comments
 (0)