Skip to content

Commit

Permalink
1.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
alangrainger committed Aug 17, 2024
1 parent 0bdafe3 commit 1746d68
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 14 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.5",
"version": "1.0.6",
"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.5",
"version": "1.0.6",
"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: 19 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Plugin, PluginManifest } from 'obsidian'
import { DEFAULT_SETTINGS, LazySettings, LoadingMethod, SettingsTab } from './Settings'
import { Platform, Plugin, PluginManifest } from 'obsidian'
import { DEFAULT_SETTINGS, LazySettings, LoadingMethod, SettingsTab } from './settings'

const lazyPluginId = require('../manifest.json').id

Expand All @@ -14,6 +14,7 @@ export default class LazyPlugin extends Plugin {
// Get the list of installed plugins
this.manifests = Object.values(this.app.plugins.manifests)
.filter(plugin => plugin.id !== lazyPluginId) // Filter out the Lazy Loader plugin
.filter(plugin => !(Platform.isMobile && plugin.isDesktopOnly)) // Filter out desktop-only plugins from mobile
.sort((a, b) => a.name.localeCompare(b.name))

await this.setInitialPluginsConfiguration()
Expand All @@ -31,7 +32,7 @@ export default class LazyPlugin extends Plugin {
async setPluginStartup (pluginId: string) {
const obsidian = this.app.plugins

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

Expand Down Expand Up @@ -74,6 +75,14 @@ export default class LazyPlugin extends Plugin {
}
}

getPluginStartup (pluginId: string): LoadingMethod {
let value
if (Platform.isMobile) value = this.settings.plugins?.[pluginId]?.startupMobile
return value ||
this.settings.plugins?.[pluginId]?.startupType ||
(this.app.plugins.enabledPlugins.has(pluginId) ? LoadingMethod.instant : LoadingMethod.disabled)
}

async loadSettings () {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData())
}
Expand Down Expand Up @@ -103,7 +112,13 @@ export default class LazyPlugin extends Plugin {
* Update an individual plugin's configuration and the settings file
*/
async updatePluginSettings (pluginId: string, startupType: LoadingMethod) {
this.settings.plugins[pluginId] = { startupType }
const settings = this.settings.plugins[pluginId] || { startupType }
if (Platform.isMobile) {
settings.startupMobile = startupType
} else {
settings.startupType = startupType
}
this.settings.plugins[pluginId] = settings
await this.saveSettings()
}

Expand Down
12 changes: 7 additions & 5 deletions src/Settings.ts → src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { App, DropdownComponent, PluginSettingTab, Setting } from 'obsidian'
import LazyPlugin from './main'

interface PluginSettings {
startupType: LoadingMethod
startupType: LoadingMethod;
startupMobile?: LoadingMethod;
}

export interface LazySettings {
Expand Down Expand Up @@ -82,13 +83,14 @@ export class SettingsTab extends PluginSettingTab {
dropdown
.setValue(this.lazyPlugin.settings.defaultStartupType || '')
.onChange(async (value: LoadingMethod) => {
this.lazyPlugin.settings.defaultStartupType = value || null
await this.lazyPlugin.saveSettings()
})
this.lazyPlugin.settings.defaultStartupType = value || null
await this.lazyPlugin.saveSettings()
})
})

new Setting(containerEl)
.setName('Individual plugin delay settings')
.setDesc('These settings can be set differently on a desktop or mobile device.')
.setHeading()

new Setting(containerEl)
Expand Down Expand Up @@ -118,7 +120,7 @@ export class SettingsTab extends PluginSettingTab {
this.addDelayOptions(dropdown)

dropdown
.setValue(pluginSettings?.[plugin.id]?.startupType)
.setValue(this.lazyPlugin.getPluginStartup(plugin.id))
.onChange(async (value: LoadingMethod) => {
// Update the config file, and disable/enable the plugin if needed
await this.lazyPlugin.updatePluginSettings(plugin.id, value)
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"1.0.2": "1.6.0",
"1.0.3": "1.6.0",
"1.0.4": "1.6.0",
"1.0.5": "1.6.0"
"1.0.5": "1.6.0",
"1.0.6": "1.6.0"
}

0 comments on commit 1746d68

Please sign in to comment.