1919'use strict' ;
2020
2121import * as vscode from 'vscode' ;
22- import { IConfiguration , IFileSystem , ILogger , IWorkspaceConfigReader , JournalController } from '../model' ;
23- import { Configuration } from '../vscode/conf' ;
24- import { Parser } from '../journal/parser' ;
25- import { Writer } from '../journal/writer' ;
26- import { Reader } from '../journal/reader' ;
27- import { Inject } from '../journal/inject' ;
28- import { Dialogues } from '../vscode/dialogues' ;
29- import { VscodeFileSystem } from '../vscode/vscode-fs' ;
22+ import { IConfiguration , IFileSystem , ILogger , IWorkspaceConfigReader , JournalController } from '../shared/model/index' ;
23+ import { Configuration } from '../shared/config/configuration' ;
24+ import { Parser } from '../features/smart-input/parser' ;
25+ import { Writer } from '../features/entries/writer' ;
26+ import { Reader } from '../features/entries/reader' ;
27+ import { Inject } from '../features/entries/inject' ;
28+ import { Dialogues } from '../features/smart-input/dialogues' ;
29+ import { VscodeFileSystem } from '../shared/fs/vscode-fs' ;
30+ import { JournalEvents } from '../shared/events' ;
31+ import { getWeekFromURIAndConfig } from '../shared/paths' ;
32+ import { SyncDailyLinks } from '../features/weekly/sync-daily-links' ;
3033
3134/**
3235 * Builds the logger once the configuration is available. The logger needs the
@@ -51,6 +54,7 @@ export class Container implements JournalController {
5154 public readonly ui : Dialogues ;
5255 public readonly writer : Writer ;
5356 public readonly reader : Reader ;
57+ public readonly events : JournalEvents ;
5458
5559 constructor ( configSource : IWorkspaceConfigReader , loggerFactory : LoggerFactory ) {
5660 this . config = new Configuration ( configSource ) ;
@@ -62,5 +66,25 @@ export class Container implements JournalController {
6266 this . writer = new Writer ( this . config , this . logger , this . inject , this . fs ,
6367 async ( path ) => vscode . workspace . openTextDocument ( vscode . Uri . file ( path ) ) ) ;
6468 this . reader = new Reader ( this . config , this . logger , this . writer , this . ui , this . fs ) ;
69+ this . events = new JournalEvents ( ) ;
70+
71+ // Cross-feature: when an entry opens, the weekly feature refreshes its
72+ // daily-entry links. Wired here (composition root) so the entries
73+ // feature need not import the weekly feature.
74+ this . events . onEntryOpened ( ( { doc } ) => this . syncWeeklyOnEntryOpened ( doc ) ) ;
75+ }
76+
77+ private syncWeeklyOnEntryOpened ( doc : vscode . TextDocument ) : void {
78+ // Fire-and-forget — must never reject the open flow.
79+ getWeekFromURIAndConfig ( doc . uri , this . config )
80+ . then ( weekInfo => {
81+ if ( weekInfo && this . config . getWeeklySyncConfig ( ) . enabled ) {
82+ const scopeId = weekInfo . scope === 'default' ? undefined : weekInfo . scope ;
83+ new SyncDailyLinks ( this )
84+ . sync ( doc , weekInfo . week , weekInfo . year , scopeId )
85+ . catch ( err => this . logger . error ( "entryOpened weekly sync failed:" , err ) ) ;
86+ }
87+ } )
88+ . catch ( err => this . logger . error ( "entryOpened getWeekFromURIAndConfig failed:" , err ) ) ;
6589 }
6690}
0 commit comments