mirror of
https://github.com/ONLYOFFICE/web-apps.git
synced 2026-07-26 19:53:36 +08:00
[common] Fix a bug with loading plugins
This commit is contained in:
@ -1,40 +1,39 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import React, { useEffect, useRef } from 'react';
|
||||
import { inject, observer } from 'mobx-react';
|
||||
import { f7 } from 'framework7-react';
|
||||
import { Device } from '../../utils/device';
|
||||
|
||||
const PluginsController = inject('storeAppOptions')(observer(props => {
|
||||
const { storeAppOptions } = props;
|
||||
let configPlugins = {autostart:[]},
|
||||
serverPlugins = {autostart:[]},
|
||||
modal,
|
||||
iframe;
|
||||
const refConfigPlugins = useRef({ autostart:[] });
|
||||
const refServerPlugins = useRef({ autostart:[] });
|
||||
let modal, iframe;
|
||||
|
||||
useEffect(() => {
|
||||
Common.Notifications.on('engineCreated', api => {
|
||||
if (storeAppOptions.customization && !!storeAppOptions.customization.plugins) {
|
||||
const api = Common.EditorApi.get();
|
||||
|
||||
api.asc_registerCallback("asc_onPluginShow", showPluginModal);
|
||||
api.asc_registerCallback("asc_onPluginClose", pluginClose);
|
||||
api.asc_registerCallback("asc_onPluginResize", pluginResize);
|
||||
api.asc_registerCallback('asc_onPluginsInit', onPluginsInit);
|
||||
|
||||
if(!storeAppOptions.customization || storeAppOptions.plugins !== false) {
|
||||
loadPlugins();
|
||||
}
|
||||
});
|
||||
loadPlugins();
|
||||
}
|
||||
|
||||
Common.Gateway.on('init', loadConfig);
|
||||
|
||||
return () => {
|
||||
const api = Common.EditorApi.get();
|
||||
|
||||
if ( api ) {
|
||||
if (api) {
|
||||
api.asc_unregisterCallback("asc_onPluginShow", showPluginModal);
|
||||
api.asc_unregisterCallback("asc_onPluginClose", pluginClose);
|
||||
api.asc_unregisterCallback("asc_onPluginResize", pluginResize);
|
||||
api.asc_unregisterCallback('asc_onPluginsInit', onPluginsInit);
|
||||
}
|
||||
};
|
||||
});
|
||||
}, [storeAppOptions.customization]);
|
||||
|
||||
const onDlgBtnClick = e => {
|
||||
const api = Common.EditorApi.get();
|
||||
@ -175,7 +174,7 @@ const PluginsController = inject('storeAppOptions')(observer(props => {
|
||||
};
|
||||
|
||||
const loadConfig = data => {
|
||||
configPlugins.config = data.config.plugins;
|
||||
refConfigPlugins.current.config = data.config.plugins;
|
||||
};
|
||||
|
||||
const onPluginsInit = pluginsdata => {
|
||||
@ -221,15 +220,15 @@ const PluginsController = inject('storeAppOptions')(observer(props => {
|
||||
};
|
||||
|
||||
const mergePlugins = () => {
|
||||
if (serverPlugins.plugins !== undefined && configPlugins.plugins !== undefined) {
|
||||
if (refServerPlugins.current.plugins !== undefined && refConfigPlugins.current.plugins !== undefined) {
|
||||
let arr = [],
|
||||
plugins = configPlugins;
|
||||
plugins = refConfigPlugins.current;
|
||||
|
||||
if (plugins.plugins && plugins.plugins.length > 0) {
|
||||
arr = plugins.plugins;
|
||||
}
|
||||
|
||||
plugins = serverPlugins;
|
||||
plugins = refServerPlugins.current;
|
||||
|
||||
if (plugins.plugins && plugins.plugins.length > 0) {
|
||||
arr = arr.concat(plugins.plugins);
|
||||
@ -240,30 +239,30 @@ const PluginsController = inject('storeAppOptions')(observer(props => {
|
||||
};
|
||||
|
||||
const loadPlugins = () => {
|
||||
if (configPlugins.config) {
|
||||
getPlugins(configPlugins.config.pluginsData)
|
||||
if (refConfigPlugins.current.config) {
|
||||
getPlugins(refConfigPlugins.current.config.pluginsData)
|
||||
.then(function(loaded)
|
||||
{
|
||||
configPlugins.plugins = loaded;
|
||||
refConfigPlugins.current.plugins = loaded;
|
||||
mergePlugins();
|
||||
});
|
||||
} else {
|
||||
configPlugins.plugins = false;
|
||||
refConfigPlugins.current.plugins = false;
|
||||
}
|
||||
|
||||
let server_plugins_url = '../../../../plugins.json';
|
||||
|
||||
Common.Utils.loadConfig(server_plugins_url, function (obj) {
|
||||
if (obj != 'error') {
|
||||
serverPlugins.config = obj;
|
||||
getPlugins(serverPlugins.config.pluginsData)
|
||||
refServerPlugins.current.config = obj;
|
||||
getPlugins(refServerPlugins.current.config.pluginsData)
|
||||
.then(function(loaded)
|
||||
{
|
||||
serverPlugins.plugins = loaded;
|
||||
refServerPlugins.current.plugins = loaded;
|
||||
mergePlugins();
|
||||
});
|
||||
} else
|
||||
serverPlugins.plugins = false;
|
||||
refServerPlugins.current.plugins = false;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@ -41,7 +41,9 @@ export class storeAppOptions {
|
||||
setEncryptionFile: action,
|
||||
|
||||
isFavorite: observable,
|
||||
setFavorite: action
|
||||
setFavorite: action,
|
||||
|
||||
customization: observable,
|
||||
});
|
||||
}
|
||||
|
||||
@ -100,6 +102,8 @@ export class storeAppOptions {
|
||||
}
|
||||
|
||||
config = {};
|
||||
customization;
|
||||
|
||||
setConfigOptions (config, _t) {
|
||||
this.config = config;
|
||||
this.customization = config.customization;
|
||||
@ -217,7 +221,7 @@ export class storeAppOptions {
|
||||
this.canReader = (!type || typeof type[1] !== 'string');
|
||||
|
||||
this.canBranding = params.asc_getCustomization();
|
||||
this.canBrandingExt = params.asc_getCanBranding() && (typeof this.customization == 'object');
|
||||
this.canBrandingExt = params.asc_getCanBranding() && (typeof this.customization == 'object' || this.config.plugins);
|
||||
|
||||
this.canFavorite = document.info && (document.info?.favorite !== undefined && document.info?.favorite !== null) && !this.isOffline;
|
||||
this.isFavorite = document.info?.favorite;
|
||||
|
||||
@ -16,6 +16,8 @@ export class storeAppOptions {
|
||||
|
||||
isDocReady: observable,
|
||||
changeDocReady: action,
|
||||
|
||||
customization: observable,
|
||||
});
|
||||
}
|
||||
|
||||
@ -24,6 +26,7 @@ export class storeAppOptions {
|
||||
canBrandingExt = true;
|
||||
canBranding = true;
|
||||
config = {};
|
||||
customization;
|
||||
|
||||
lostEditingRights = false;
|
||||
changeEditingRights (value) {
|
||||
@ -137,7 +140,7 @@ export class storeAppOptions {
|
||||
this.canDownload = permissions.download !== false && (!type || typeof type[1] !== 'string');
|
||||
|
||||
this.canBranding = params.asc_getCustomization();
|
||||
this.canBrandingExt = params.asc_getCanBranding() && (typeof this.customization == 'object');
|
||||
this.canBrandingExt = params.asc_getCanBranding() && (typeof this.customization == 'object' || this.config.plugins);
|
||||
|
||||
this.canUseReviewPermissions = this.canLicense && (!!permissions.reviewGroups || this.customization
|
||||
&& this.customization.reviewPermissions && (typeof (this.customization.reviewPermissions) == 'object'));
|
||||
|
||||
@ -17,11 +17,14 @@ export class storeAppOptions {
|
||||
|
||||
isDocReady: observable,
|
||||
changeDocReady: action,
|
||||
|
||||
customization: observable,
|
||||
});
|
||||
}
|
||||
|
||||
isEdit = false;
|
||||
config = {};
|
||||
customization;
|
||||
|
||||
canViewComments = false;
|
||||
changeCanViewComments(value) {
|
||||
@ -105,7 +108,7 @@ export class storeAppOptions {
|
||||
if (params.asc_getRights() !== Asc.c_oRights.Edit)
|
||||
permissions.edit = false;
|
||||
this.canBranding = params.asc_getCustomization();
|
||||
this.canBrandingExt = params.asc_getCanBranding() && (typeof this.customization == 'object');
|
||||
this.canBrandingExt = params.asc_getCanBranding() && (typeof this.customization == 'object' || this.config.plugins);
|
||||
this.canModifyFilter = permissions.modifyFilter !== false;
|
||||
this.canAutosave = true;
|
||||
this.canAnalytics = params.asc_getIsAnalyticsEnable();
|
||||
|
||||
Reference in New Issue
Block a user