|
@@ -46,6 +46,50 @@ export class WatcherService {
|
|
|
this.validationWorker.on('error', (error) => {
|
|
this.validationWorker.on('error', (error) => {
|
|
|
this.logger.error(`Validation worker error: ${error}`);
|
|
this.logger.error(`Validation worker error: ${error}`);
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+ // Load persisted state on startup
|
|
|
|
|
+ this.loadPersistedState();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private loadPersistedState() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const db = this.db.getDb();
|
|
|
|
|
+ const row = db
|
|
|
|
|
+ .prepare('SELECT value FROM settings WHERE key = ?')
|
|
|
|
|
+ .get('watcher_state') as { value?: string } | undefined;
|
|
|
|
|
+
|
|
|
|
|
+ if (row && row.value) {
|
|
|
|
|
+ const state = JSON.parse(row.value);
|
|
|
|
|
+ this.isWatching = state.isWatching || false;
|
|
|
|
|
+ this.lastWatches = state.lastWatches || [];
|
|
|
|
|
+ this.lastOptions = state.lastOptions || {};
|
|
|
|
|
+
|
|
|
|
|
+ // If we were watching before restart, resume watching
|
|
|
|
|
+ if (this.isWatching && this.lastWatches.length > 0) {
|
|
|
|
|
+ this.logger.log('Resuming watcher from persisted state');
|
|
|
|
|
+ this.start(this.lastWatches, this.lastOptions);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ this.logger.error(`Failed to load persisted watcher state: ${error}`);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private savePersistedState() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const db = this.db.getDb();
|
|
|
|
|
+ const state = {
|
|
|
|
|
+ isWatching: this.isWatching,
|
|
|
|
|
+ lastWatches: this.lastWatches,
|
|
|
|
|
+ lastOptions: this.lastOptions,
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ db.prepare(
|
|
|
|
|
+ 'INSERT OR REPLACE INTO settings (key, value) VALUES (?, ?)',
|
|
|
|
|
+ ).run('watcher_state', JSON.stringify(state));
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ this.logger.error(`Failed to save persisted watcher state: ${error}`);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
start(watches?: string[], options: any = {}) {
|
|
start(watches?: string[], options: any = {}) {
|
|
@@ -152,6 +196,10 @@ export class WatcherService {
|
|
|
type: 'started',
|
|
type: 'started',
|
|
|
watches: enabledWatches,
|
|
watches: enabledWatches,
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+ // Save the running state
|
|
|
|
|
+ this.savePersistedState();
|
|
|
|
|
+
|
|
|
return { started: true };
|
|
return { started: true };
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -473,6 +521,10 @@ export class WatcherService {
|
|
|
await this.watcher.close();
|
|
await this.watcher.close();
|
|
|
this.isWatching = false;
|
|
this.isWatching = false;
|
|
|
this.eventsGateway.emitWatcherUpdate({ type: 'stopped' });
|
|
this.eventsGateway.emitWatcherUpdate({ type: 'stopped' });
|
|
|
|
|
+
|
|
|
|
|
+ // Save the stopped state
|
|
|
|
|
+ this.savePersistedState();
|
|
|
|
|
+
|
|
|
return { stopped: true };
|
|
return { stopped: true };
|
|
|
}
|
|
}
|
|
|
return { stopped: false, message: 'Watcher is not running.' };
|
|
return { stopped: false, message: 'Watcher is not running.' };
|