@@ -39,16 +39,12 @@ export default class SimpleEmbedsPlugin extends Plugin {
3939 ] ;
4040 processedMarkdown : Debouncer < [ ] > ;
4141 currentTheme : "dark" | "light" ;
42-
4342 genericPreviewEmbed = new GenericPreviewEmbed ( ) ;
44- // use a separate property to save to cache during session
45- // saveSettings triggers reload and results in a loop
46- linkPreviewCache : { [ url : string ] : GenericPreviewMetadata } ;
4743
4844 async onload ( ) {
4945 console . log ( `Loading ${ this . manifest . name } v${ this . manifest . version } ` ) ;
5046 await this . loadSettings ( ) ;
51- this . linkPreviewCache = this . settings . genericPreviewCache ;
47+ console . log ( this . settings ) ;
5248 this . addSettingTab ( new SimpleEmbedPluginSettingTab ( this . app , this ) ) ;
5349
5450 this . currentTheme = this . _getCurrentTheme ( ) ;
@@ -89,12 +85,6 @@ export default class SimpleEmbedsPlugin extends Plugin {
8985 }
9086
9187 onunload ( ) {
92- // save the cache before unloading
93- console . log ( "Saving link preview cache to settings" ) ;
94- this . saveSettings ( {
95- genericPreviewCache : this . linkPreviewCache ,
96- } ) ;
97-
9888 console . log ( `Unloading ${ this . manifest . name } ` ) ;
9989 this . processedMarkdown = null ;
10090 }
@@ -113,6 +103,11 @@ export default class SimpleEmbedsPlugin extends Plugin {
113103 } ) ;
114104 }
115105
106+ async saveGenericPreviewCache ( link : string , metadata : GenericPreviewMetadata ) {
107+ this . settings . genericPreviewCache [ link ] = metadata ;
108+ await this . saveData ( this . settings ) ;
109+ }
110+
116111 private _getCurrentTheme ( ) : "dark" | "light" {
117112 return document . body . classList . contains ( "theme-dark" ) ? "dark" : "light" ;
118113 }
0 commit comments