mirror of
https://github.com/ONLYOFFICE/sdkjs.git
synced 2026-02-10 18:15:19 +08:00
Autostart bundled background plugins
This commit is contained in:
@ -1429,7 +1429,7 @@
|
||||
};
|
||||
}
|
||||
|
||||
Api.prototype.getUsedBackgroundPlugins = function()
|
||||
Api.prototype.getUsedBackgroundPlugins = function(noCheckBundled)
|
||||
{
|
||||
let services = [];
|
||||
try
|
||||
@ -1442,13 +1442,71 @@
|
||||
{
|
||||
services = [];
|
||||
}
|
||||
|
||||
if (window.g_asc_plugins && noCheckBundled !== true)
|
||||
{
|
||||
let allPlugins = window.g_asc_plugins.plugins;
|
||||
let unbundledPlugins = this.getUnbundledPlugins();
|
||||
let bundledBackground = Object.create(null);
|
||||
|
||||
for (let i = 0, len = allPlugins.length; i < len; i++)
|
||||
{
|
||||
let item = allPlugins[i];
|
||||
if (item.isBackground() && !unbundledPlugins[item.guid])
|
||||
bundledBackground[item.guid] = true;
|
||||
}
|
||||
|
||||
for (let i = 0, len = services.length; i < len; i++)
|
||||
{
|
||||
if (bundledBackground[services[i]])
|
||||
delete bundledBackground[services[i]];
|
||||
}
|
||||
|
||||
for (let i in bundledBackground)
|
||||
{
|
||||
services.push(i);
|
||||
}
|
||||
}
|
||||
|
||||
return services;
|
||||
};
|
||||
Api.prototype["getUsedBackgroundPlugins"] = Api.prototype.getUsedBackgroundPlugins;
|
||||
|
||||
Api.prototype.setUsedBackgroundPlugins = function(services)
|
||||
{
|
||||
window.localStorage.setItem("asc_plugins_background", JSON.stringify(services));
|
||||
try
|
||||
{
|
||||
window.localStorage.setItem("asc_plugins_background", JSON.stringify(services));
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
Api.prototype.getStoppedBackgroundPlugins = function()
|
||||
{
|
||||
let services = [];
|
||||
try
|
||||
{
|
||||
services = JSON.parse(window.localStorage.getItem("asc_plugins_background_stopped"));
|
||||
if (!services)
|
||||
services = [];
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
services = [];
|
||||
}
|
||||
return services;
|
||||
};
|
||||
Api.prototype.setStoppedBackgroundPlugins = function(services)
|
||||
{
|
||||
try
|
||||
{
|
||||
window.localStorage.setItem("asc_plugins_background_stopped", JSON.stringify(services));
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
Api.prototype.checkInstalledPlugins = function()
|
||||
@ -1521,6 +1579,72 @@
|
||||
}
|
||||
};
|
||||
|
||||
// return user-changed plugins guids
|
||||
Api.prototype.getUnbundledPlugins = function()
|
||||
{
|
||||
let changed = Object.create(null);
|
||||
|
||||
let localStorageItems = getLocalStorageItem("asc_plugins_installed");
|
||||
if (localStorageItems)
|
||||
{
|
||||
for (let item in localStorageItems)
|
||||
{
|
||||
if (localStorageItems[item]["guid"])
|
||||
changed[localStorageItems[item]["guid"]] = true;
|
||||
}
|
||||
}
|
||||
|
||||
localStorageItems = getLocalStorageItem("asc_plugins_removed");
|
||||
if (localStorageItems)
|
||||
{
|
||||
for (let item in localStorageItems)
|
||||
{
|
||||
if (localStorageItems[item]["guid"])
|
||||
changed[localStorageItems[item]["guid"]] = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (window["Asc"]["extensionPlugins"] && window["Asc"]["extensionPlugins"].length)
|
||||
{
|
||||
let arrayExtensions = window["Asc"]["extensionPlugins"];
|
||||
for (let i = 0, len = arrayExtensions.length; i < len; i++)
|
||||
{
|
||||
if (arrayExtensions[i]["guid"])
|
||||
changed[arrayExtensions[i]["guid"]] = true;
|
||||
}
|
||||
}
|
||||
|
||||
let backgroundUsed = this.getUsedBackgroundPlugins(true);
|
||||
for (let i = 0, len = backgroundUsed.length; i < len; i++)
|
||||
{
|
||||
changed[backgroundUsed[i]] = true;
|
||||
}
|
||||
backgroundUsed = this.getStoppedBackgroundPlugins();
|
||||
for (let i = 0, len = backgroundUsed.length; i < len; i++)
|
||||
{
|
||||
changed[backgroundUsed[i]] = true;
|
||||
}
|
||||
|
||||
if (window["UpdateInstallPlugins"] && window["AscDesktopEditor"])
|
||||
{
|
||||
try
|
||||
{
|
||||
let plugins = JSON.parse(window["AscDesktopEditor"]["GetInstallPlugins"]());
|
||||
let userPlugins = plugins[1] || [];
|
||||
|
||||
for (var i = 0, len = userPlugins.length; i < len; i++)
|
||||
{
|
||||
changed[userPlugins[i]["guid"]] = true;
|
||||
}
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
return changed;
|
||||
};
|
||||
|
||||
/**
|
||||
* The plugin object.
|
||||
* @typedef {Object} PluginData
|
||||
|
||||
@ -212,7 +212,7 @@
|
||||
{
|
||||
this.path = basePath;
|
||||
|
||||
let services = {};
|
||||
let services = Object.create(null);
|
||||
for (let i = 0; i < plugins.length; i++)
|
||||
{
|
||||
let newPlugin = plugins[i];
|
||||
@ -862,14 +862,11 @@
|
||||
}
|
||||
},
|
||||
|
||||
setUsedBackgroundPlugins : function(services)
|
||||
{
|
||||
window.localStorage.setItem("asc_plugins_background", JSON.stringify(services));
|
||||
},
|
||||
|
||||
// Added a new list (stopped) for compatibility.
|
||||
// And so that those background plugins that were in the delivery initially - were launched.
|
||||
addUsedBackgroundPlugins : function(guid)
|
||||
{
|
||||
let services = this.api.getUsedBackgroundPlugins();
|
||||
let services = this.api.getUsedBackgroundPlugins(true);
|
||||
for (let i = 0, len = services.length; i < len; i++)
|
||||
{
|
||||
if (services[i] === guid)
|
||||
@ -877,11 +874,31 @@
|
||||
}
|
||||
services.push(guid);
|
||||
this.api.setUsedBackgroundPlugins(services);
|
||||
|
||||
let removed = this.api.getStoppedBackgroundPlugins();
|
||||
for (let i = 0, len = removed.length; i < len; i++)
|
||||
{
|
||||
if (removed[i] === guid)
|
||||
{
|
||||
removed.splice(i, 1);
|
||||
this.api.setStoppedBackgroundPlugins(removed);
|
||||
return;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
removeUsedBackgroundPlugins : function(guid)
|
||||
{
|
||||
let services = this.api.getUsedBackgroundPlugins();
|
||||
let removed = this.api.getStoppedBackgroundPlugins();
|
||||
for (let i = 0, len = removed.length; i < len; i++)
|
||||
{
|
||||
if (removed[i] === guid)
|
||||
return;
|
||||
}
|
||||
removed.push(guid);
|
||||
this.api.setStoppedBackgroundPlugins(removed);
|
||||
|
||||
let services = this.api.getUsedBackgroundPlugins(true);
|
||||
for (let i = 0, len = services.length; i < len; i++)
|
||||
{
|
||||
if (services[i] === guid)
|
||||
|
||||
Reference in New Issue
Block a user