@@ -2,7 +2,6 @@ import { existsSync } from "node:fs";
22import fs from "node:fs/promises" ;
33import path from "node:path" ;
44import * as watcher from "@parcel/watcher" ;
5- import { app } from "electron" ;
65import { inject , injectable } from "inversify" ;
76import { MAIN_TOKENS } from "../../di/tokens" ;
87import { logger } from "../../utils/logger" ;
@@ -70,9 +69,6 @@ export class FileWatcherService extends TypedEventEmitter<FileWatcherEvents> {
7069 async startWatching ( repoPath : string ) : Promise < void > {
7170 if ( this . watchers . has ( repoPath ) ) return ;
7271
73- await fs . mkdir ( this . snapshotsDir , { recursive : true } ) ;
74- await this . emitChangesSinceSnapshot ( repoPath ) ;
75-
7672 const pending : PendingChanges = {
7773 dirs : new Set ( ) ,
7874 files : new Set ( ) ,
@@ -107,53 +103,13 @@ export class FileWatcherService extends TypedEventEmitter<FileWatcherEvents> {
107103 if ( ! w ) return ;
108104
109105 if ( w . pending . timer ) clearTimeout ( w . pending . timer ) ;
110- await this . saveSnapshot ( repoPath ) ;
111106 await this . watcherRegistry . unregister ( w . filesId ) ;
112107 for ( const gitId of w . gitIds ) {
113108 await this . watcherRegistry . unregister ( gitId ) ;
114109 }
115110 this . watchers . delete ( repoPath ) ;
116111 }
117112
118- private get snapshotsDir ( ) : string {
119- return path . join ( app . getPath ( "userData" ) , "snapshots" ) ;
120- }
121-
122- private snapshotPath ( repoPath : string ) : string {
123- return path . join (
124- this . snapshotsDir ,
125- `${ Buffer . from ( repoPath ) . toString ( "base64url" ) } .snapshot` ,
126- ) ;
127- }
128-
129- private async saveSnapshot ( repoPath : string ) : Promise < void > {
130- try {
131- await watcher . writeSnapshot ( repoPath , this . snapshotPath ( repoPath ) , {
132- ignore : IGNORE_PATTERNS ,
133- } ) ;
134- } catch ( error ) {
135- log . error ( "Failed to write snapshot:" , error ) ;
136- }
137- }
138-
139- private async emitChangesSinceSnapshot ( repoPath : string ) : Promise < void > {
140- const snapshotPath = this . snapshotPath ( repoPath ) ;
141- try {
142- await fs . access ( snapshotPath ) ;
143- } catch {
144- return ;
145- }
146-
147- const events = await watcher . getEventsSince ( repoPath , snapshotPath , {
148- ignore : IGNORE_PATTERNS ,
149- } ) ;
150-
151- const affectedDirs = new Set ( events . map ( ( e ) => path . dirname ( e . path ) ) ) ;
152- for ( const dirPath of affectedDirs ) {
153- this . emit ( FileWatcherEvent . DirectoryChanged , { repoPath, dirPath } ) ;
154- }
155- }
156-
157113 private async watchFiles (
158114 repoPath : string ,
159115 pending : PendingChanges ,
0 commit comments