Git推送成功后现在会自动关闭推送窗口
This commit is contained in:
@@ -108,6 +108,12 @@ interface GitCommitSucceededEventPayload {
|
||||
committed_files: number
|
||||
}
|
||||
|
||||
interface GitPushSucceededEventPayload {
|
||||
folder_id: number
|
||||
pushed_commits: number
|
||||
upstream_set: boolean
|
||||
}
|
||||
|
||||
export function BranchDropdown({
|
||||
branch,
|
||||
parentBranch,
|
||||
@@ -187,6 +193,43 @@ export function BranchDropdown({
|
||||
}
|
||||
}, [folder, onBranchChange, t])
|
||||
|
||||
useEffect(() => {
|
||||
if (!folder) return
|
||||
|
||||
let unlisten: UnlistenFn | null = null
|
||||
|
||||
listen<GitPushSucceededEventPayload>(
|
||||
"folder://git-push-succeeded",
|
||||
(event) => {
|
||||
if (event.payload.folder_id !== folder.id) return
|
||||
const { pushed_commits, upstream_set } = event.payload
|
||||
let description: string
|
||||
if (upstream_set) {
|
||||
description =
|
||||
pushed_commits === 0
|
||||
? t("toasts.upstreamSet")
|
||||
: t("toasts.upstreamSetAndPushed", { count: pushed_commits })
|
||||
} else if (pushed_commits === 0) {
|
||||
description = t("toasts.noCommitsToPush")
|
||||
} else {
|
||||
description = t("toasts.pushedCommits", { count: pushed_commits })
|
||||
}
|
||||
toast.success(t("toasts.pushCodeCompleted"), { description })
|
||||
onBranchChange()
|
||||
}
|
||||
)
|
||||
.then((fn) => {
|
||||
unlisten = fn
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("[BranchDropdown] failed to listen push event:", err)
|
||||
})
|
||||
|
||||
return () => {
|
||||
disposeTauriListener(unlisten, "BranchDropdown.gitPushSucceeded")
|
||||
}
|
||||
}, [folder, onBranchChange, t])
|
||||
|
||||
async function runGitTask<T>(
|
||||
label: string,
|
||||
action: () => Promise<T>,
|
||||
|
||||
@@ -266,9 +266,14 @@ function parseDate(dateStr: string): Date | null {
|
||||
interface PushWorkspaceProps {
|
||||
folderPath: string
|
||||
folderName: string
|
||||
onPushed?: () => void
|
||||
}
|
||||
|
||||
export function PushWorkspace({ folderPath, folderName }: PushWorkspaceProps) {
|
||||
export function PushWorkspace({
|
||||
folderPath,
|
||||
folderName,
|
||||
onPushed,
|
||||
}: PushWorkspaceProps) {
|
||||
const t = useTranslations("Folder.pushWindow")
|
||||
const tLog = useTranslations("Folder.gitLogTab")
|
||||
const { withCredentialRetry } = useGitCredential()
|
||||
@@ -327,30 +332,10 @@ export function PushWorkspace({ folderPath, folderName }: PushWorkspaceProps) {
|
||||
async function handlePush() {
|
||||
setPushing(true)
|
||||
try {
|
||||
const result = await withCredentialRetry(
|
||||
(creds) => gitPush(folderPath, creds),
|
||||
{ folderPath }
|
||||
)
|
||||
let description: string | undefined
|
||||
if (result.upstream_set) {
|
||||
description =
|
||||
result.pushed_commits === 0
|
||||
? t("toasts.upstreamSet")
|
||||
: t("toasts.upstreamSetAndPushed", {
|
||||
count: result.pushed_commits,
|
||||
})
|
||||
} else if (result.pushed_commits === 0) {
|
||||
description = t("toasts.noCommitsToPush")
|
||||
} else {
|
||||
description = t("toasts.pushedCommits", {
|
||||
count: result.pushed_commits,
|
||||
})
|
||||
}
|
||||
toast.success(t("toasts.pushSuccess"), { description })
|
||||
await loadCommits()
|
||||
setSelectedFile(null)
|
||||
setSelectedCommit(null)
|
||||
setOpenByCommit({})
|
||||
await withCredentialRetry((creds) => gitPush(folderPath, creds), {
|
||||
folderPath,
|
||||
})
|
||||
onPushed?.()
|
||||
} catch (err) {
|
||||
toast.error(t("toasts.pushFailed"), {
|
||||
description: toErrorMessage(err),
|
||||
|
||||
Reference in New Issue
Block a user