🐛 fix(vscode): profiles.json 在外部被改动后 Profile tab 实时刷新
This commit is contained in:
1 parent
0332d1da72
commit
7888d15a38
2 files changed
+24
-1
No files matched your search
@@ -317,6 +317,10 @@ export class KanbanWebviewPanel {
|
|||||||
// toolbar button whenever the working tree is clean. Fire-and-forget —
|
// toolbar button whenever the working tree is clean. Fire-and-forget —
|
||||||
// `setupGitWatcher` handles its own activation + retry logic.
|
// `setupGitWatcher` handles its own activation + retry logic.
|
||||||
toolbar.setupGitWatcher(this)
|
toolbar.setupGitWatcher(this)
|
||||||
|
|
||||||
|
const profilesWatcher = settings.watchProfilesFile(this)
|
||||||
|
if (profilesWatcher)
|
||||||
|
this.disposables.push(profilesWatcher)
|
||||||
}
|
}
|
||||||
|
|
||||||
private syncFocusedTerminalTab(): void {
|
private syncFocusedTerminalTab(): void {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type { Disposable } from 'vscode'
|
||||||
import type { ProfilesData } from '../../profiles/store'
|
import type { ProfilesData } from '../../profiles/store'
|
||||||
import type { KanbanWebviewPanel } from '../KanbanPanel'
|
import type { KanbanWebviewPanel } from '../KanbanPanel'
|
||||||
import { execFile } from 'node:child_process'
|
import { execFile } from 'node:child_process'
|
||||||
@@ -5,7 +6,7 @@ import * as fs from 'node:fs'
|
|||||||
import * as os from 'node:os'
|
import * as os from 'node:os'
|
||||||
import * as path from 'node:path'
|
import * as path from 'node:path'
|
||||||
import process from 'node:process'
|
import process from 'node:process'
|
||||||
import { commands, env, Uri, workspace } from 'vscode'
|
import { commands, env, RelativePattern, Uri, workspace } from 'vscode'
|
||||||
import { clearIdentityCache, initIdentity } from '../../auth/identity'
|
import { clearIdentityCache, initIdentity } from '../../auth/identity'
|
||||||
import { getToken, getYouTrackToken, setToken, setYouTrackToken } from '../../auth/secrets'
|
import { getToken, getYouTrackToken, setToken, setYouTrackToken } from '../../auth/secrets'
|
||||||
import { listClaudeProfiles, setProfilesDirOverride } from '../../cc/profiles'
|
import { listClaudeProfiles, setProfilesDirOverride } from '../../cc/profiles'
|
||||||
@@ -329,6 +330,24 @@ export async function handleProfilesGet(panel: KanbanWebviewPanel): Promise<void
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 盯住 `.spx/profiles.json`:git pull、切分支、外部编辑后重推 Profile tab。
|
||||||
|
* 面板自己保存也会触发一次,重推的是刚写入的同一份数据,无副作用。
|
||||||
|
*/
|
||||||
|
export function watchProfilesFile(panel: KanbanWebviewPanel): Disposable | undefined {
|
||||||
|
const folder = workspace.workspaceFolders?.[0]
|
||||||
|
if (!folder)
|
||||||
|
return undefined
|
||||||
|
const watcher = workspace.createFileSystemWatcher(new RelativePattern(folder, '.spx/profiles.json'))
|
||||||
|
const refresh = (): void => {
|
||||||
|
void handleProfilesGet(panel)
|
||||||
|
}
|
||||||
|
watcher.onDidChange(refresh)
|
||||||
|
watcher.onDidCreate(refresh)
|
||||||
|
watcher.onDidDelete(refresh)
|
||||||
|
return watcher
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read profiles from the hardcoded directory and push the list to the
|
* Read profiles from the hardcoded directory and push the list to the
|
||||||
* webview. Failures are swallowed and surfaced as an empty list so the
|
* webview. Failures are swallowed and surfaced as an empty list so the
|
||||||
|
|||||||
Reference in new issue
Block a user