feat(fs-watcher): add 300ms delayed scanning toast for large project dirs
This commit is contained in:
parent
9d9cc75b28
commit
64ad4d2e58
2 changed files with 17 additions and 5 deletions
|
|
@ -15,7 +15,7 @@
|
||||||
import { getProjectHealth } from '../../stores/health.svelte';
|
import { getProjectHealth } from '../../stores/health.svelte';
|
||||||
import { fsWatchProject, fsUnwatchProject, onFsWriteDetected, fsWatcherStatus } from '../../adapters/fs-watcher-bridge';
|
import { fsWatchProject, fsUnwatchProject, onFsWriteDetected, fsWatcherStatus } from '../../adapters/fs-watcher-bridge';
|
||||||
import { recordExternalWrite } from '../../stores/conflicts.svelte';
|
import { recordExternalWrite } from '../../stores/conflicts.svelte';
|
||||||
import { notify } from '../../stores/notifications.svelte';
|
import { notify, dismissNotification } from '../../stores/notifications.svelte';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
project: ProjectConfig;
|
project: ProjectConfig;
|
||||||
|
|
@ -59,16 +59,26 @@
|
||||||
if (!cwd) return;
|
if (!cwd) return;
|
||||||
|
|
||||||
// Start watching, then check inotify capacity
|
// Start watching, then check inotify capacity
|
||||||
|
// Show scanning toast only if status check takes >300ms
|
||||||
|
let scanToastId: string | null = null;
|
||||||
|
const scanTimer = setTimeout(() => {
|
||||||
|
scanToastId = notify('info', 'Scanning project directories…');
|
||||||
|
}, 300);
|
||||||
|
|
||||||
fsWatchProject(projectId, cwd)
|
fsWatchProject(projectId, cwd)
|
||||||
.then(() => fsWatcherStatus())
|
.then(() => fsWatcherStatus())
|
||||||
.then((status) => {
|
.then((status) => {
|
||||||
|
clearTimeout(scanTimer);
|
||||||
|
if (scanToastId) dismissNotification(scanToastId);
|
||||||
if (status.warning) {
|
if (status.warning) {
|
||||||
notify('warning', status.warning);
|
notify('warning', status.warning);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(e =>
|
.catch(e => {
|
||||||
console.warn(`Failed to start fs watcher for ${projectId}:`, e)
|
clearTimeout(scanTimer);
|
||||||
);
|
if (scanToastId) dismissNotification(scanToastId);
|
||||||
|
console.warn(`Failed to start fs watcher for ${projectId}:`, e);
|
||||||
|
});
|
||||||
|
|
||||||
// Listen for fs write events (filter to this project)
|
// Listen for fs write events (filter to this project)
|
||||||
let unlisten: (() => void) | null = null;
|
let unlisten: (() => void) | null = null;
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ export function getNotifications(): Notification[] {
|
||||||
return notifications;
|
return notifications;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function notify(type: NotificationType, message: string): void {
|
export function notify(type: NotificationType, message: string): string {
|
||||||
const id = crypto.randomUUID();
|
const id = crypto.randomUUID();
|
||||||
notifications.push({ id, type, message, timestamp: Date.now() });
|
notifications.push({ id, type, message, timestamp: Date.now() });
|
||||||
|
|
||||||
|
|
@ -29,6 +29,8 @@ export function notify(type: NotificationType, message: string): void {
|
||||||
|
|
||||||
// Auto-dismiss
|
// Auto-dismiss
|
||||||
setTimeout(() => dismissNotification(id), TOAST_DURATION_MS);
|
setTimeout(() => dismissNotification(id), TOAST_DURATION_MS);
|
||||||
|
|
||||||
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function dismissNotification(id: string): void {
|
export function dismissNotification(id: string): void {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue