Skip to content

Commit

Permalink
1.0.11
Browse files Browse the repository at this point in the history
Manage plugin loading solely within Lazy Loader
  • Loading branch information
alangrainger committed Aug 29, 2024
1 parent 077ed2e commit 98c6920
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "lazy-plugins",
"name": "Lazy Plugin Loader",
"version": "1.0.10",
"version": "1.0.11",
"minAppVersion": "1.6.0",
"description": "Load plugins with a delay on startup, so that you can get your app startup down into the sub-second loading time.",
"author": "Alan Grainger",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lazy-plugins",
"version": "1.0.10",
"version": "1.0.11",
"description": "Load plugins with a delay on startup, so that you can get your app startup down into the sub-second loading time.",
"main": "main.js",
"scripts": {
Expand Down
23 changes: 11 additions & 12 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,33 @@ export default class LazyPlugin extends Plugin {

/**
* Configure and load a plugin based on its startup settings.
* This uses Obsidian's enablePluginAndSave() and disablePluginAndSave() functions
* to save the configuration state for Obsidian's next start.
*/
async setPluginStartup (pluginId: string) {
const obsidian = this.app.plugins

const startupType = this.getPluginStartup(pluginId)
const isActiveOnStartup = obsidian.enabledPlugins.has(pluginId)
const isRunning = obsidian.plugins?.[pluginId]?._loaded

// Check if the plugin is loaded by Obsidian
if (obsidian.enabledPlugins.has(pluginId)) {
// Disable it and save, so that plugin loading is handled solely by Lazy Loader
// https://github.com/obsidianmd/obsidian-releases/pull/3998#issuecomment-2318012016
await obsidian.disablePluginAndSave(pluginId)
}

switch (startupType) {
// For disabled plugins
case LoadingMethod.disabled:
await obsidian.disablePluginAndSave(pluginId)
if (isRunning) await obsidian.disablePlugin(pluginId)
break
// For instant-start plugins
case LoadingMethod.instant:
if (!isActiveOnStartup && !isRunning) await obsidian.enablePluginAndSave(pluginId)
if (!isRunning) await obsidian.enablePlugin(pluginId)
break
// For plugins with a delay
case LoadingMethod.short:
case LoadingMethod.long:
if (isActiveOnStartup) {
// Disable and save so that it won't auto-start next time
await obsidian.disablePluginAndSave(pluginId)
// Immediately re-enable, since the plugin is already active and in-use
await obsidian.enablePlugin(pluginId)
} else {
if (!isRunning) {
// Start with a delay
const seconds = startupType === LoadingMethod.short ? this.settings.shortDelaySeconds : this.settings.longDelaySeconds
// Add a short additional delay to each plugin, for two purposes:
Expand Down Expand Up @@ -147,7 +146,7 @@ export default class LazyPlugin extends Plugin {
// Iterate over the configured plugins
for (const plugin of this.manifests) {
const startupType = this.settings.plugins?.[plugin.id]?.startupType
if (startupType === LoadingMethod.short || startupType === LoadingMethod.long) {
if (startupType !== LoadingMethod.disabled) {
await this.app.plugins.disablePlugin(plugin.id)
await this.app.plugins.enablePluginAndSave(plugin.id)
console.log(`Set ${plugin.id} back to instant start`)
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"1.0.6": "1.6.0",
"1.0.7": "1.6.0",
"1.0.9": "1.6.0",
"1.0.10": "1.6.0"
"1.0.10": "1.6.0",
"1.0.11": "1.6.0"
}

0 comments on commit 98c6920

Please sign in to comment.