Skip to content

Commit 86d79d2

Browse files
committed
feat(dashboard): 'Sync Everything Now' resyncs journals + characters + maps
The Overview's quick-action button only ran a journal resync, so after a manifest/path change a GM's character field data (and inventory/notes) stayed stale — the button implied a full sync but wasn't one. Replace it with 'Sync Everything Now' (new resync-everything action): one confirm, then resync all journals, re-push every LINKED character via ActorSync.repushActor (Foundry is source of truth for characters), and resync all maps. Failures are isolated per item so one bad actor can't abort the sweep. Unlinked actors stay on the Characters tab's 'Push All Actors' (that one creates entities — deliberately not bundled into a routine refresh). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LaDDiXB5GTVurEzJwYYopf
1 parent 2c58f2c commit 86d79d2

2 files changed

Lines changed: 73 additions & 2 deletions

File tree

scripts/sync-dashboard.mjs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export class SyncDashboard extends HandlebarsApplicationMixin(ApplicationV2) {
6666
'open-map-journal': SyncDashboard.#onOpenMapJournalAction,
6767
'resync-all-maps': SyncDashboard.#onResyncAllMapsAction,
6868
'resync-all-journals': SyncDashboard.#onResyncAllJournalsAction,
69+
'resync-everything': SyncDashboard.#onResyncEverythingAction,
6970
'open-maps-folder': SyncDashboard.#onOpenMapsFolderAction,
7071
'dismiss-map-errors': SyncDashboard.#onDismissMapErrorsAction,
7172
'pull-date': SyncDashboard.#onPullDateAction,
@@ -1469,6 +1470,11 @@ export class SyncDashboard extends HandlebarsApplicationMixin(ApplicationV2) {
14691470
await this._onResyncAllJournals();
14701471
}
14711472

1473+
/** Re-sync EVERYTHING: journals + every linked character + maps. */
1474+
static async #onResyncEverythingAction() {
1475+
await this._onResyncEverything();
1476+
}
1477+
14721478
/**
14731479
* Reveal the "Chronicle Maps" folder in Foundry's journal sidebar.
14741480
* Activates the journal tab and expands the folder.
@@ -2172,6 +2178,71 @@ export class SyncDashboard extends HandlebarsApplicationMixin(ApplicationV2) {
21722178
this.render({ force: true });
21732179
}
21742180

2181+
/**
2182+
* Re-sync everything that's already connected to Chronicle in one action:
2183+
* all journals, every LINKED character (re-pushes current field data — Foundry
2184+
* is source of truth for characters), and all maps. This is the Overview's
2185+
* "Sync Everything Now"; the previous button only did journals, which left
2186+
* actor field data (and inventory/notes) stale after a manifest/path change.
2187+
*
2188+
* Unlinked actors are intentionally NOT auto-created here — that's a heavier,
2189+
* entity-creating operation kept on the Characters tab's "Push All Actors".
2190+
* Each module's resyncAll / repushActor is the same proven path the per-tab
2191+
* buttons use; failures are isolated per item so one bad actor can't abort the
2192+
* sweep.
2193+
*/
2194+
async _onResyncEverything() {
2195+
let confirmed;
2196+
try {
2197+
confirmed = await confirmDialog({
2198+
title: 'Sync Everything Now',
2199+
content: '<p>Re-sync <strong>all</strong> journals, linked characters, and maps with Chronicle?</p>'
2200+
+ '<p class="hint">Foundry is the source of truth for characters — their current data is pushed up.</p>',
2201+
});
2202+
} catch {
2203+
return; // User dismissed the dialog.
2204+
}
2205+
if (!confirmed) return;
2206+
2207+
ui.notifications.info('Chronicle: Re-syncing everything…');
2208+
const mods = this._syncManager?._modules || [];
2209+
const find = (name) => mods.find((m) => m.constructor?.name === name);
2210+
const done = [];
2211+
2212+
// 1. Journals (verbose=false to avoid a flood of per-entry toasts mid-sweep).
2213+
const journalSync = find('JournalSync');
2214+
if (journalSync?.resyncAll) {
2215+
try { await journalSync.resyncAll({ verbose: false }); done.push('journals'); }
2216+
catch (err) { console.error('Chronicle: journal resync failed', err); }
2217+
}
2218+
2219+
// 2. Characters — re-push every LINKED actor so stale fields refresh.
2220+
const actorSync = find('ActorSync');
2221+
if (actorSync?.repushActor) {
2222+
const chars = actorSync.getSyncedActors?.() ?? [];
2223+
let pushed = 0;
2224+
for (const c of chars) {
2225+
if (!c.synced) continue; // unlinked → use "Push All Actors" (creates entities)
2226+
try { if (await actorSync.repushActor(c.id)) pushed++; }
2227+
catch (err) { console.error(`Chronicle: re-push failed for "${c.name}"`, err); }
2228+
}
2229+
if (pushed) done.push(`${pushed} character(s)`);
2230+
}
2231+
2232+
// 3. Maps.
2233+
const mapSync = find('MapSync');
2234+
if (mapSync?.resyncAll) {
2235+
try { await mapSync.resyncAll({ verbose: false }); done.push('maps'); }
2236+
catch (err) { console.error('Chronicle: map resync failed', err); }
2237+
}
2238+
2239+
this._cache.maps = null;
2240+
this._cache.entities = null;
2241+
this._logActivity('push', `Re-synced everything (${done.join(', ') || 'nothing'})`);
2242+
this.render({ force: true });
2243+
ui.notifications.info(`Chronicle: Re-sync complete — ${done.join(', ') || 'nothing to sync'}.`);
2244+
}
2245+
21752246
// ---------------------------------------------------------------------------
21762247
// Config actions
21772248
// ---------------------------------------------------------------------------

templates/sync-dashboard.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@
138138
{{!-- Quick actions --}}
139139
<h3 class="section-heading">Quick Actions</h3>
140140
<div class="overview-actions">
141-
<button type="button" class="dashboard-btn btn-sm" data-action="resync-all-journals">
142-
<i class="fa-solid fa-rotate"></i> Sync Journals Now
141+
<button type="button" class="dashboard-btn btn-sm" data-action="resync-everything">
142+
<i class="fa-solid fa-rotate"></i> Sync Everything Now
143143
</button>
144144
<button type="button" class="dashboard-btn btn-sm" data-jump-tab="status">
145145
<i class="fa-solid fa-stethoscope"></i> Diagnostics

0 commit comments

Comments
 (0)