Skip to content

Commit b196ac3

Browse files
committed
refactor: remove dead plugin lifecycle code
1 parent 776b322 commit b196ac3

2 files changed

Lines changed: 13 additions & 40 deletions

File tree

RefactorPlan.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Incremental refactor assessment and plan
22

3-
Status: active plan for the 2.27.0 refactor, last updated 2026-08-08
3+
Status: active plan for the 2.27.0 refactor, last updated 2026-08-09
44

55
This document is the working plan for reducing the size and coupling of
66
`src/core/main.ts` and `src/view/ExcalidrawView.ts` without destabilizing the
@@ -24,6 +24,7 @@ validated, and what remains uncertain.
2424
| Extract footer safe-area styling | Implemented; awaiting manual validation | `FooterSafeAreaManager` now owns device-specific stylesheet injection, open-document traversal, and unload cleanup; the plugin method remains as a settings-UI compatibility delegate |
2525
| Extract font management | Implemented; awaiting manual validation | `FontManager` now owns CJK discovery/loading, custom-font registration, document stylesheets, readiness, and cleanup; plugin methods and the externally read `fourthFontLoaded` field remain intact |
2626
| Extract startup instrumentation | Implemented; awaiting manual validation | `StartupTimer` now owns startup event history, delta tracking, and breakdown formatting; lifecycle calls, public methods, and the public `loadTimestamp` field remain intact |
27+
| Remove confirmed dead `main.ts` code | Implemented; awaiting manual validation | Removed the uncalled cache-registration method and the never-assigned duplicate file-explorer observer field/cleanup; the active observer in `ObserverManager` remains unchanged |
2728
| Audit and consolidate duplicate logic | In progress | Consolidated `updateFrontmatterInString()`, `arrayToMap()`, `wrapTextAtCharLength()`, `getLinkParts()`/`LinkParts`, `getBinaryFileFromDataURL()`, `svgToBase64()`, `getFontDataURL()`, `cropCanvas()`, `getImageSize()`, `promiseTry()`, `isVersionNewerThanOther()`, `repositionElementsToCursor()`, the internal `cloneElement()`, and `getBoundTextElementId()`; continue one independently testable helper family at a time |
2829
| All later phases | Planned | Begin only after the preceding checkpoint is validated |
2930

@@ -56,6 +57,7 @@ validated, and what remains uncertain.
5657
| 2026-08-09 | Extracted footer safe-area styling from `main.ts` | Added documented `FooterSafeAreaManager` with a narrow host contract to own phone/tablet CSS injection, exact device-aware open-document traversal, setting-driven removal, and unload cleanup. Kept `plugin.updateFooterSafeAreaPadding()` and its layout-ready and settings UI call sites unchanged as delegates. Font document traversal remains in `main.ts` until the separate font extraction | `npm run build`, targeted manager ESLint, and scoped `git diff --check` passed; `main.ts` decreased by 46 lines from 1,558 to 1,512; bundle size increased by 99 bytes to 5,094,470 bytes from manager/delegate overhead; `npm run madge` could not run because `madge` is not installed; phone/tablet manual validation remains pending |
5758
| 2026-08-09 | Extracted font management from `main.ts` | Added documented `FontManager` to own the existing CJK asset cache, vault reads, CJK/custom stylesheet lifecycle, custom font metrics and package registration, readiness state, and device-aware document traversal. Preserved every plugin-facing font method as a delegate, retained `plugin.fourthFontLoaded` for view compatibility, kept the initial readiness value and 100ms timer unchanged, and injected lazy package-map access without changing `PackageManager` construction or ownership | `npm run build`, `npm run lib`, targeted manager ESLint, and scoped `git diff --check` passed; `main.ts` decreased by 130 lines from 1,512 to 1,382; bundle size increased by 379 bytes to 5,094,849 bytes from manager/facade overhead; `npm run madge` could not run because `madge` is not installed; desktop, mobile, CJK, custom-font, and popout manual validation remains pending |
5859
| 2026-08-09 | Extracted startup timing instrumentation from `main.ts` | Added documented `StartupTimer` to own the private event list, previous-event timestamp, total/delta formatting, and debug output. Kept every timing call in its original lifecycle position, retained `logStartupEvent()` and the misspelled `printStarupBreakdown()` as plugin delegates, preserved pre-layout events across the layout-ready baseline reset, and retained `loadTimestamp` as an own public field with unchanged assignment behavior | `npm run build`, `npm run lib`, targeted manager ESLint, and scoped `git diff --check` passed; `main.ts` decreased by 6 lines from 1,382 to 1,376; the latest bundle is 5,095,747 bytes, 898 bytes above the preceding checkpoint due to the manager and compatibility facade; `npm run madge` could not run because `madge` is not installed; startup breakdown inspection remains pending |
60+
| 2026-08-09 | Rejected a catch-all Markdown integration manager and removed proven dead code from `main.ts` | Markdown post-processing, install-codeblock handling, observer setup, and rerender behavior have different lifecycle and ownership constraints, so they will remain explicit rather than being grouped under a weak abstraction. Removed the uncalled private `registerEventListeners()`, its `MetadataCache` import, the never-assigned `main.ts` `fileExplorerObserver`, and its inert unload check. The active file-explorer observer and teardown in `ObserverManager` were not changed | Repository-wide reference searches confirmed both removed members had no callers or assignments and that `PluginFileManager.initialize()` owns the active initial cache walk; `npm run build` passed with the existing circular-dependency warnings; targeted lint reports only the same four pre-existing startup-script `any` diagnostics and none on changed lines; `git diff --check` passed; `main.ts` decreased by 29 lines from 1,376 to 1,347 and the bundle decreased by 381 bytes to 5,095,366 bytes; manual unload/reload validation remains pending |
5961

6062
## Executive recommendation
6163

@@ -296,7 +298,6 @@ src/core/
296298
PluginSettingsManager.ts Load/save/encryption/default assembly
297299
FontManager.ts Per-document fonts and package registration
298300
ViewportStyleManager.ts Phone/tablet safe-area behavior
299-
MarkdownIntegrationManager.ts Post processors and install code blocks
300301
301302
src/view/
302303
ExcalidrawView.ts Obsidian host, public facade, composition
@@ -478,19 +479,20 @@ popout creation, so it should not be combined with package-manager changes.
478479

479480
Candidates should be extracted one at a time:
480481

481-
1. Move install-codeblock registration and Markdown integration setup behind a
482-
`MarkdownIntegrationManager`, while still registering the Markdown post
483-
processor from `onload()`.
482+
1. Keep Markdown post-processing, install-codeblock registration, observer
483+
setup, and rerender behavior explicit in their current owners. A proposed
484+
`MarkdownIntegrationManager` was rejected because these responsibilities do
485+
not form a cohesive lifecycle unit.
484486
2. Move startup-script execution behind a focused runner owned by the script
485487
subsystem.
486-
3. Move startup timing storage/formatting into a small `StartupTimer` while
487-
retaining `plugin.logStartupEvent()` as a delegate if consumers need it.
488+
3. Completed: startup timing storage/formatting now belongs to `StartupTimer`,
489+
with the plugin methods retained as compatibility delegates.
488490
4. Group initialization and cleanup of managers, but keep a readable ordered
489491
list in `onloadOnLayoutReady()` and `onunload()`.
490-
5. Only after reference searches and runtime validation, remove confirmed dead
491-
members. Current review candidates include the unused private
492-
`registerEventListeners()` and a `fileExplorerObserver` field in `main.ts`
493-
that appears separate from the observer owned by `ObserverManager`.
492+
5. Completed: after repository-wide reference searches, removed the unused
493+
private `registerEventListeners()` and the never-assigned
494+
`fileExplorerObserver` field and unload check from `main.ts`. The active
495+
observer owned by `ObserverManager` remains intact.
494496

495497
Do not hide lifecycle ordering inside a generic service container. The desired
496498
`main.ts` is a readable composition root, not an empty forwarding shell.

src/core/main.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
ViewState,
1212
ViewStateResult,
1313
Notice,
14-
MetadataCache,
1514
TAbstractFile,
1615
FrontMatterCache,
1716
} from "obsidian";
@@ -178,7 +177,6 @@ export default class ExcalidrawPlugin extends Plugin {
178177
private legacyExcalidrawPopoverObserver:
179178
| MutationObserver
180179
| CustomMutationObserver;
181-
private fileExplorerObserver: MutationObserver | CustomMutationObserver;
182180
public opencount: number = 0;
183181
public ea: ExcalidrawAutomate;
184182
//A master list of fileIds to facilitate copy / paste
@@ -908,29 +906,6 @@ export default class ExcalidrawPlugin extends Plugin {
908906
};
909907
}
910908

911-
/**
912-
* Registers event listeners for the plugin
913-
* Must be called after the workspace is read (onLayoutReady)
914-
* Intended to be called from onLayoutReady in onload()
915-
*/
916-
private async registerEventListeners() {
917-
await this.awaitInit();
918-
919-
const metaCache: MetadataCache = this.app.metadataCache;
920-
metaCache.getCachedFiles().forEach((filename: string) => {
921-
const fm = metaCache.getCache(filename)?.frontmatter;
922-
if (
923-
(fm && typeof fm[FRONTMATTER_KEYS.plugin.name] !== "undefined") ||
924-
filename.match(/\.excalidraw$/)
925-
) {
926-
this.fileManager.updateFileCache(
927-
this.app.vault.getFileByPath(filename),
928-
fm,
929-
);
930-
}
931-
});
932-
}
933-
934909
onunload() {
935910
ExcalidrawSidepanelView.onPluginUnload(this);
936911
const excalidrawViews = getExcalidrawViews(this.app);
@@ -976,10 +951,6 @@ export default class ExcalidrawPlugin extends Plugin {
976951
}
977952
this.observerManager.destroy();
978953

979-
if (this.fileExplorerObserver) {
980-
this.fileExplorerObserver.disconnect();
981-
}
982-
983954
this.excalidrawConfig = null;
984955

985956
this.editorHandler.destroy();

0 commit comments

Comments
 (0)