mirror of
https://github.com/bombsquad-community/plugin-manager.git
synced 2025-11-07 17:36:00 +00:00
settings: add option to auto-enable installed plugins
This commit is contained in:
parent
6cc514813f
commit
3cb05c5120
1 changed files with 27 additions and 24 deletions
|
|
@ -11,6 +11,7 @@ import sys
|
||||||
import asyncio
|
import asyncio
|
||||||
import re
|
import re
|
||||||
import pathlib
|
import pathlib
|
||||||
|
import copy
|
||||||
|
|
||||||
from typing import Union, Optional
|
from typing import Union, Optional
|
||||||
|
|
||||||
|
|
@ -84,31 +85,32 @@ class StartupTasks:
|
||||||
|
|
||||||
def setup_config(self):
|
def setup_config(self):
|
||||||
is_config_updated = False
|
is_config_updated = False
|
||||||
if "Community Plugin Manager" not in ba.app.config:
|
existing_plugin_manager_config = copy.deepcopy(ba.app.config.get("Community Plugin Manager"))
|
||||||
ba.app.config["Community Plugin Manager"] = {}
|
|
||||||
if "Installed Plugins" not in ba.app.config["Community Plugin Manager"]:
|
plugin_manager_config = ba.app.config.setdefault("Community Plugin Manager", {})
|
||||||
ba.app.config["Community Plugin Manager"]["Installed Plugins"] = {}
|
plugin_manager_config.setdefault("Custom Sources", [])
|
||||||
is_config_updated = True
|
installed_plugins = plugin_manager_config.setdefault("Installed Plugins", {})
|
||||||
if "Custom Sources" not in ba.app.config["Community Plugin Manager"]:
|
|
||||||
ba.app.config["Community Plugin Manager"]["Custom Sources"] = []
|
for plugin_name in tuple(installed_plugins.keys()):
|
||||||
is_config_updated = True
|
|
||||||
for plugin_name in ba.app.config["Community Plugin Manager"]["Installed Plugins"].keys():
|
|
||||||
plugin = PluginLocal(plugin_name)
|
plugin = PluginLocal(plugin_name)
|
||||||
if not plugin.is_installed:
|
if not plugin.is_installed:
|
||||||
del ba.app.config["Community Plugin Manager"]["Installed Plugins"][plugin_name]
|
del installed_plugins[plugin_name]
|
||||||
is_config_updated = True
|
|
||||||
if "Settings" not in ba.app.config["Community Plugin Manager"]:
|
# This order is the options will show up in Settings window.
|
||||||
ba.app.config["Community Plugin Manager"]["Settings"] = {}
|
current_settings = {
|
||||||
if "Auto Update Plugin Manager" not in ba.app.config["Community Plugin Manager"]["Settings"]:
|
"Auto Update Plugin Manager": True,
|
||||||
ba.app.config["Community Plugin Manager"]["Settings"]["Auto Update Plugin Manager"] = True
|
"Auto Update Plugins": True,
|
||||||
is_config_updated = True
|
"Auto Enable Plugins After Installation": True,
|
||||||
if "Auto Update Plugins" not in ba.app.config["Community Plugin Manager"]["Settings"]:
|
}
|
||||||
ba.app.config["Community Plugin Manager"]["Settings"]["Auto Update Plugins"] = True
|
settings = plugin_manager_config.setdefault("Settings", {})
|
||||||
is_config_updated = True
|
|
||||||
if "Load plugins immediately without restart" not in ba.app.config["Community Plugin Manager"]["Settings"]:
|
for setting, value in settings.items():
|
||||||
ba.app.config["Community Plugin Manager"]["Settings"]["Load plugins immediately without restart"] = False
|
if setting in current_settings:
|
||||||
is_config_updated = True
|
current_settings[setting] = value
|
||||||
if is_config_updated:
|
|
||||||
|
plugin_manager_config["Settings"] = current_settings
|
||||||
|
|
||||||
|
if plugin_manager_config != existing_plugin_manager_config:
|
||||||
ba.app.config.commit()
|
ba.app.config.commit()
|
||||||
|
|
||||||
async def update_plugin_manager(self):
|
async def update_plugin_manager(self):
|
||||||
|
|
@ -484,7 +486,8 @@ class Plugin:
|
||||||
|
|
||||||
async def install(self):
|
async def install(self):
|
||||||
local_plugin = await self._download()
|
local_plugin = await self._download()
|
||||||
await local_plugin.enable()
|
if ba.app.config["Community Plugin Manager"]["Settings"]["Auto Enable Plugins After Installation"]:
|
||||||
|
await local_plugin.enable()
|
||||||
ba.screenmessage("Plugin Installed", color = (0,1,0))
|
ba.screenmessage("Plugin Installed", color = (0,1,0))
|
||||||
|
|
||||||
async def uninstall(self):
|
async def uninstall(self):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue