Fix/problem with internet cheking (#3)

* [Marketplace] Change internet connection checking for plugin "Marketplace".

* [Marketplace] Fix problem with timeout.

* [Marketplace] Rename function.

* [Marketplace] Add link to jquery.

* [Marketplace] Add loader container.

* Fix problem with clouds for desktop.
This commit is contained in:
Alexey Matveev
2023-09-13 14:20:50 +03:00
committed by GitHub
parent e165684a56
commit 368c52696f
13 changed files with 147 additions and 78 deletions

View File

@ -0,0 +1,7 @@
This plugin uses code from the following 3rd party projects.
1. jQuery - Query is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. (http://jquery.com/)
License: MIT License
License File: jQuery.license

View File

@ -8,7 +8,7 @@
"cs" : "Správce Pluginů"
},
"guid" : "asc.{AA2EA9B6-9EC2-415F-9762-634EE8D9A95E}",
"version": "1.0.0",
"version": "1.0.2",
"group" : {
"name" : "Plugin Manager",
"rank" : 1

View File

@ -21,6 +21,7 @@
<script type="text/javascript" src="https://onlyoffice.github.io/sdkjs-plugins/v1/plugins.js"></script>
<script type="text/javascript" src="https://onlyoffice.github.io/sdkjs-plugins/v1/plugins-ui.js"></script>
<link rel="stylesheet" href="https://onlyoffice.github.io/sdkjs-plugins/v1/plugins.css">
<script type="text/javascript" src="./vendor/jQuery-2.2.2-min/jquery-v2.2.2-min.js"></script>
<link rel="stylesheet" href="resources/css/styles.css">
<script type="text/javascript" src="scripts/code.js"></script>
</head>
@ -32,5 +33,6 @@
<div id="div_noIternet" class="hidden" style="position: absolute;">
<label id="lb_noInternet" class="form-control lab noselect">No Internet Connection.</label>
</div>
<div id="loader-container" class="loader hidden"></div>
</body>
</html>

View File

@ -0,0 +1,20 @@
Copyright (c) 2009 John Resig, http://jquery.com/
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -43,4 +43,13 @@ html, body {
}
.info {
margin-top: 10px;
}
.loader {
margin: 0 !important;
position: absolute;
right: 0;
top: 0;
width: 100%;
height: 100% !important;
background-color: rgba(128, 128, 128, 0.5);
}

View File

@ -16,12 +16,11 @@
*
*/
(function(window, undefined) {
const isDesktop = window.AscDesktopEditor !== undefined;
let isOnline = isDesktop ? true : null;
let isInit = false;
const isLocal = ( (window.AscDesktopEditor !== undefined) && (window.location.protocol.indexOf('file') !== -1) );
let interval = null;
if (!isDesktop)
checkInternet();
let errTimeout = null;
let loader = null;
let loaderTimeout = null;
// create iframe
const iframe = document.createElement("iframe");
@ -32,7 +31,7 @@
let BPluginReady = false;
let editorVersion = null;
let marketplaceURl = null;
const OOMarketplaceUrl = isDesktop ? './store/index.html' : 'https://onlyoffice.github.io/store/index.html';
const OOMarketplaceUrl = isLocal ? './store/index.html' : 'https://onlyoffice.github.io/store/index.html';
try {
// for incognito mode
marketplaceURl = localStorage.getItem('DeveloperMarketplaceUrl') || OOMarketplaceUrl;
@ -41,8 +40,12 @@
}
window.Asc.plugin.init = function() {
isInit = true;
if (typeof isOnline === 'boolean') {
// resize window
window.Asc.plugin.resizeWindow(608, 570, 608, 570, 0, 0);
if (!isLocal) {
checkInternet(true);
loaderTimeout = setTimeout(createLoader, 500);
} else {
initPlugin();
}
};
@ -53,11 +56,10 @@
function initPlugin() {
document.body.appendChild(iframe);
// resize window
if (marketplaceURl !== OOMarketplaceUrl)
document.getElementById('notification').classList.remove('hidden');
window.Asc.plugin.resizeWindow(608, 570, 608, 570, 0, 0);
// send message that plugin is ready
window.Asc.plugin.executeMethod("GetVersion", null, function(version) {
editorVersion = version;
BPluginReady = true;
@ -66,31 +68,21 @@
});
let divNoInt = document.getElementById('div_noIternet');
// send message that plugin is ready
if (isOnline) {
let style = document.getElementsByTagName('head')[0].lastChild;
let pageUrl = marketplaceURl;
iframe.src = pageUrl + window.location.search;
iframe.onload = function() {
BFrameReady = true;
if (BPluginReady) {
if (!divNoInt.classList.contains('hidden')) {
divNoInt.classList.add('hidden');
clearInterval(interval);
interval = null;
}
postMessage( { type: 'Theme', theme: window.Asc.plugin.theme, style : style.innerHTML } );
postMessage( { type: 'PluginReady', version: editorVersion } );
let style = document.getElementsByTagName('head')[0].lastChild;
let pageUrl = marketplaceURl;
iframe.src = pageUrl + window.location.search;
iframe.onload = function() {
BFrameReady = true;
if (BPluginReady) {
if (!divNoInt.classList.contains('hidden')) {
divNoInt.classList.add('hidden');
clearInterval(interval);
interval = null;
}
};
} else {
divNoInt.classList.remove('hidden');
if (!interval) {
interval = setInterval(function() {
checkInternet();
}, 5000);
postMessage( { type: 'Theme', theme: window.Asc.plugin.theme, style : style.innerHTML } );
postMessage( { type: 'PluginReady', version: editorVersion } );
}
}
};
};
window.Asc.plugin.button = function(id, windowID) {
@ -183,33 +175,49 @@
label.innerHTML = window.Asc.plugin.tr(label.innerHTML);
};
function checkInternet() {
function checkInternet(bSetTimeout) {
try {
let xhr = new XMLHttpRequest();
let url = 'https://raw.githubusercontent.com/ONLYOFFICE/onlyoffice.github.io/master/store/translations/langs.json';
let url = 'https://onlyoffice.github.io/store/translations/langs.json';
xhr.open('GET', url, true);
xhr.onload = function () {
if (this.readyState == 4) {
if (this.status >= 200 && this.status < 300) {
isOnline = true;
if (isInit)
initPlugin();
endInternetChecking(true);
}
}
};
xhr.onerror = function (err) {
isOnline = false;
if (isInit)
initPlugin();
endInternetChecking(false);
};
xhr.send(null);
} catch (error) {
isOnline = false;
if (isInit)
initPlugin();
endInternetChecking(false);
}
if (bSetTimeout) {
errTimeout = setTimeout(function() {
// if loading is too long show the error (because sometimes requests can not send error)
endInternetChecking(false);
}, 15000);
}
};
function endInternetChecking(isOnline) {
clearTimeout(errTimeout);
errTimeout = null;
destroyLoader();
if (isOnline) {
initPlugin();
} else {
document.getElementById('div_noIternet').classList.remove('hidden');
if (!interval) {
interval = setInterval(function() {
checkInternet(false);
}, 5000);
}
}
};
@ -267,4 +275,18 @@
document.getElementsByTagName('html')[0].style.zoom = zoom;
};
function createLoader() {
$('#loader-container').removeClass( "hidden" );
loader && (loader.remove ? loader.remove() : $('#loader-container')[0].removeChild(loader));
loader = showLoader($('#loader-container')[0], window.Asc.plugin.tr('Checking internet connection...'));
};
function destroyLoader() {
clearTimeout(loaderTimeout);
loaderTimeout = null;
$('#loader-container').addClass( "hidden" )
loader && (loader.remove ? loader.remove() : $('#loader-container')[0].removeChild(loader));
loader = undefined;
};
})(window, undefined);

View File

@ -5,5 +5,6 @@
"Yes" : "Ano",
"No" : "Ne",
"Do you want to completely remove this plugin?" : "Chcete tento plugin úplně odstranit?",
"If you choose \"No\", you will be able to restore this plugin later in the marketplace." : "Pokud zvolíte \"Ne\", budete moci tento plugin obnovit později na Správce Pluginů."
"If you choose \"No\", you will be able to restore this plugin later in the marketplace." : "Pokud zvolíte \"Ne\", budete moci tento plugin obnovit později na Správce Pluginů.",
"Checking internet connection..." : "Kontrola připojení k internetu..."
}

View File

@ -5,5 +5,6 @@
"Yes" : "Ja",
"No" : "Nein",
"Do you want to completely remove this plugin?" : "Möchten Sie dieses Plugin vollständig entfernen?",
"If you choose \"No\", you will be able to restore this plugin later in the marketplace." : "Wenn Sie \"Nein\" wählen, können Sie dieses Plugin später auf dem Plugin-Verwaltung wiederherstellen."
"If you choose \"No\", you will be able to restore this plugin later in the marketplace." : "Wenn Sie \"Nein\" wählen, können Sie dieses Plugin später auf dem Plugin-Verwaltung wiederherstellen.",
"Checking internet connection..." : "Internetverbindung prüfen..."
}

View File

@ -5,5 +5,6 @@
"Yes" : "Sí",
"No" : "No",
"Do you want to completely remove this plugin?" : "¿Quieres eliminar por completo este plugin?",
"If you choose \"No\", you will be able to restore this plugin later in the marketplace." : "Si elige \"No\", podrá restaurar este complemento más adelante en el Administrador de Complementos."
"If you choose \"No\", you will be able to restore this plugin later in the marketplace." : "Si elige \"No\", podrá restaurar este complemento más adelante en el Administrador de Complementos.",
"Checking internet connection..." : "Comprobación de la conexión a Internet..."
}

View File

@ -5,5 +5,6 @@
"Yes" : "Oui",
"No" : "Aucun",
"Do you want to completely remove this plugin?" : "Voulez-vous supprimer complètement ce plugin?",
"If you choose \"No\", you will be able to restore this plugin later in the marketplace." : "Si vous choisissez \"Aucun\", vous pourrez restaurer ce plugin plus tard sur le Gestionnaire de Plugins."
"If you choose \"No\", you will be able to restore this plugin later in the marketplace." : "Si vous choisissez \"Aucun\", vous pourrez restaurer ce plugin plus tard sur le Gestionnaire de Plugins.",
"Checking internet connection..." : "Vérification de la connexion Internet..."
}

View File

@ -5,5 +5,6 @@
"Yes" : "Да",
"No" : "Нет",
"Do you want to completely remove this plugin?" : "Вы хотите полность удалить этот плагин?",
"If you choose \"No\", you will be able to restore this plugin later in the marketplace." : "Если вы выберете \"Нет\", вы сможете восстановить этот плагин позже в Менеджере плагинов."
"If you choose \"No\", you will be able to restore this plugin later in the marketplace." : "Если вы выберете \"Нет\", вы сможете восстановить этот плагин позже в Менеджере плагинов.",
"Checking internet connection..." : "Проверка интернет соединения..."
}

File diff suppressed because one or more lines are too long

View File

@ -16,12 +16,12 @@
*
*/
const version = '1.0.3'; // version of store (will change it when update something in store)
const version = '1.0.4'; // version of store (will change it when update something in store)
let start = Date.now();
const isLocal = ( (window.AscDesktopEditor !== undefined) && (window.location.protocol.indexOf('file') !== -1) ); // desktop detecting
let isPluginLoading = false; // flag plugins loading
const isDesktop = window.AscDesktopEditor !== undefined; // desktop detecting
let isOnline = true; // flag internet connection
isDesktop && checkInternet(); // check internet connection (only for desktop)
isLocal && checkInternet(); // check internet connection (only for desktop)
let interval = null; // interval for checking internet connection (if it doesn't work on launch)
const OOMarketplaceUrl = 'https://onlyoffice.github.io/'; // url to oficial store (for local version store in desktop)
const OOIO = 'https://github.com/ONLYOFFICE/onlyoffice.github.io/'; // url to oficial github repository (for links and discussions)
@ -113,7 +113,7 @@ const ioUrl = location.href.substring(0, pos);
// get translation file
getTranslation();
// fetch all plugins from config
if (!isDesktop)
if (!isLocal)
fetchAllPlugins(true, false);
window.onload = function() {
@ -179,7 +179,7 @@ window.addEventListener('message', function(message) {
if (message.updateInstalled)
showListofPlugins(false);
else if ( allPlugins.length || (isDesktop && !isOnline) )
else if ( allPlugins.length || (isLocal && !isOnline) )
getAllPluginsData(true, false);
break;
@ -260,14 +260,14 @@ window.addEventListener('message', function(message) {
if (installed) {
bHasLocal = !installed.obj.baseUrl.includes(ioUrl);
if (plugin && (!bHasLocal || (isDesktop && !needBackup) ) ) {
if (plugin && (!bHasLocal || (isLocal && !needBackup) ) ) {
installedPlugins = installedPlugins.filter(function(el){return el.guid !== message.guid});
bUpdate = true;
} else {
installed.removed = true;
// нужно обновить список установленных плагинов, чтобы ссылки на ресурсы были правильными
if (isDesktop)
if (isLocal)
sendMessage({ type: 'getInstalled', updateInstalled: true }, '*');
}
}
@ -536,7 +536,7 @@ function getAllPluginsData(bFirstRender, bshowMarketplace) {
isPluginLoading = true;
let count = 0;
let Unloaded = [];
let url = isDesktop ? OOMarketplaceUrl : ioUrl;
let url = isLocal ? OOMarketplaceUrl : ioUrl;
allPlugins.forEach(function(plugin, i, arr) {
count++;
if (typeof plugin !== 'object') {
@ -589,7 +589,7 @@ function getAllPluginsData(bFirstRender, bshowMarketplace) {
);
});
if (isDesktop && installedPlugins && bFirstRender && !isOnline) {
if (isLocal && installedPlugins && bFirstRender && !isOnline) {
isPluginLoading = false;
getInstalledLanguages();
showMarketplace();
@ -598,7 +598,7 @@ function getAllPluginsData(bFirstRender, bshowMarketplace) {
function getDiscussion(config) {
// get discussion page
if (isDesktop && window.AscSimpleRequest && window.AscSimpleRequest.createRequest) {
if (isLocal && window.AscSimpleRequest && window.AscSimpleRequest.createRequest) {
makeDesktopRequest(config.discussionUrl).then(
function(data) {
if (data.status == 'success') {
@ -674,7 +674,7 @@ function showListofPlugins(bAll, sortedArr) {
let arr = (sortedArr ? sortedArr : (bAll ? allPlugins : installedPlugins));
// получаем список backup плагинов
if (!bAll && isDesktop) {
if (!bAll && isLocal) {
var _pluginsTmp = JSON.parse(window["AscDesktopEditor"]["GetBackupPlugins"]());
if (_pluginsTmp.length) {
@ -858,7 +858,7 @@ function onClickInstall(target, event) {
event.stopImmediatePropagation();
// click install button
// we should do that because we have some problem when desktop is loading plugin
if (isDesktop) {
if (isLocal) {
toogleLoader(true, 'Installation');
} else {
clearTimeout(timeout);
@ -880,7 +880,7 @@ function onClickInstall(target, event) {
config : (installed ? installed.obj : plugin)
};
// we should do that because we have some problem when desktop is loading plugin
if (isDesktop) {
if (isLocal) {
setTimeout(function(){
sendMessage(message);
}, 200);
@ -892,7 +892,7 @@ function onClickInstall(target, event) {
function onClickUpdate(target) {
// click update button
// we should do that because we have some problem when desktop is loading plugin
if (isDesktop) {
if (isLocal) {
toogleLoader(true, 'Updating');
} else {
clearTimeout(timeout);
@ -908,7 +908,7 @@ function onClickUpdate(target) {
config : plugin
};
// we should do that because we have some problem when desktop is loading plugin
if (isDesktop) {
if (isLocal) {
setTimeout(function(){
sendMessage(message);
}, 200);
@ -920,7 +920,7 @@ function onClickUpdate(target) {
function onClickRemove(target, event) {
event.stopImmediatePropagation();
// click remove button
if (isDesktop) {
if (isLocal) {
toogleLoader(true, 'Removal');
} else {
clearTimeout(timeout);
@ -940,7 +940,7 @@ function needBackupPlugin(guid) {
// если плагин есть в стор ( и его версия <= ? ), то можем удалить, пользователь сможет поставить актуальную версию
// если плагина нет в стор, нужно его хранить у пользователя с возможностью восстановления
return isDesktop ? findPlugin(true, guid) == undefined : false;
return isLocal ? findPlugin(true, guid) == undefined : false;
}
function onClickUpdateAll() {
@ -990,14 +990,14 @@ function onClickItem() {
elements.divRatingLink.setAttribute('title', getTranslated('No disscussion page for this plugin.'));
}
if ( !plugin || ( isDesktop && installed ) ) {
if ( !plugin || ( isLocal && installed ) ) {
elements.divGitLink.classList.add('hidden');
plugin = installed.obj;
} else {
elements.divGitLink.classList.remove('hidden');
}
let bCorrectUrl = isDesktop || ( !plugin.baseUrl.includes('http://') && !plugin.baseUrl.includes('file:') && !plugin.baseUrl.includes('../'));
let bCorrectUrl = isLocal || ( !plugin.baseUrl.includes('http://') && !plugin.baseUrl.includes('file:') && !plugin.baseUrl.includes('../'));
if (bCorrectUrl && plugin.variations[0].store && plugin.variations[0].store.screenshots && plugin.variations[0].store.screenshots.length) {
let arrScreens = plugin.variations[0].store.screenshots;
@ -1407,7 +1407,7 @@ function getImageUrl(guid, bNotForStore, bSetSize, id) {
// In desktop we have a local installed marketplace. It's why we use local routes only for desktop.
let baseUrl;
if (installedPlugins && isDesktop) {
if (installedPlugins && isLocal) {
// it doesn't work when we use icons from other resource (cors problems)
// it's why we use local icons only for desktop
plugin = findPlugin(false, guid);
@ -1417,13 +1417,13 @@ function getImageUrl(guid, bNotForStore, bSetSize, id) {
}
}
if ( ( !plugin || !isDesktop ) && allPlugins) {
if ( ( !plugin || !isLocal ) && allPlugins) {
plugin = findPlugin(true, guid);
if (plugin)
baseUrl = plugin.baseUrl;
}
// github doesn't allow to use "http" or "file" as the URL for an image
if ( plugin && ( baseUrl.includes('https://') || isDesktop) ) {
if ( plugin && ( baseUrl.includes('https://') || isLocal) ) {
let variation = plugin.variations[0];
if (!bNotForStore && variation.store && variation.store.icons) {
@ -1517,7 +1517,7 @@ function toogleView(current, oldEl, text, bAll, bForce) {
current.classList.add('btn_toolbar_active');
elements.linkNewPlugin.innerHTML = getTranslated(text);
let toolbar = document.getElementById('toolbar_tools');
let flag = !isDesktop && !isOnline;
let flag = !isLocal && !isOnline;
if ( ( bAll && (!isOnline || isPluginLoading) ) || flag) {
$('.div_notification').remove();
$('.div_item').remove();
@ -1535,7 +1535,7 @@ function toogleView(current, oldEl, text, bAll, bForce) {
}
elements.linkNewPlugin.href = bAll ? (OOIO + "pulls") : "https://api.onlyoffice.com/plugin/installation";
if (isDesktop && !bAll) {
if (isLocal && !bAll) {
elements.linkNewPlugin.href = "#";
elements.linkNewPlugin.onclick = function (e) {
e.preventDefault();
@ -1699,7 +1699,7 @@ function changeAfterInstallOrRemove(bInstall, guid, bHasLocal) {
function checkInternet() {
// url for check internet connection
let url = 'https://raw.githubusercontent.com/ONLYOFFICE/onlyoffice.github.io/master/store/translations/langs.json';
let url = 'https://onlyoffice.github.io/store/translations/langs.json';
makeRequest(url, 'GET', null, null, true).then(
function() {
isOnline = true;
@ -1714,7 +1714,7 @@ function checkInternet() {
div.onclick();
} else if (bshowMarketplace) {
toogleView(elements.btnMarketplace, elements.btnAvailablePl, messages.linkPR, true, true);
} else if (!isDesktop) {
} else if (!isLocal) {
toogleView(elements.btnAvailablePl, elements.btnMarketplace, messages.linkManually, false, true);
}
clearInterval(interval);
@ -1733,7 +1733,7 @@ function handeNoInternet() {
let bshowMarketplace = elements.btnMarketplace && elements.btnMarketplace.classList.contains('btn_toolbar_active');
if ( (bshowMarketplace || !isDesktop) && elements.divSelected && !elements.divSelected.classList.contains('hidden') ) {
if ( (bshowMarketplace || !isLocal) && elements.divSelected && !elements.divSelected.classList.contains('hidden') ) {
sendMessage( { type : "showButton", show : false } );
onClickBack();
}
@ -1741,7 +1741,7 @@ function handeNoInternet() {
if (!document.getElementsByClassName('div_notification')[0]) {
if (bshowMarketplace)
toogleView(elements.btnMarketplace, elements.btnAvailablePl, messages.linkPR, true, true);
else if (!isDesktop)
else if (!isLocal)
toogleView(elements.btnAvailablePl, elements.btnMarketplace, messages.linkManually, false, true);
}
};