2019-01-23 04:33:34 -07:00
|
|
|
define(['loading', 'events', 'dialogHelper', 'dom', 'layoutManager', 'scrollHelper', 'globalize', 'require', 'material-icons', 'emby-button', 'paper-icon-button-light', 'emby-input', 'formDialogStyle', 'flexStyles'], function (loading, events, dialogHelper, dom, layoutManager, scrollHelper, globalize, require) {
|
2019-01-10 05:39:37 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var currentApiClient;
|
|
|
|
var currentDlg;
|
|
|
|
var currentInstance;
|
2018-10-22 15:05:09 -07:00
|
|
|
|
|
|
|
function reloadPageWhenServerAvailable(retryCount) {
|
|
|
|
var apiClient = currentApiClient;
|
2019-01-10 05:39:37 -07:00
|
|
|
if (!apiClient) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't use apiclient method because we don't want it reporting authentication under the old version
|
2020-05-04 03:44:12 -07:00
|
|
|
apiClient.getJSON(apiClient.getUrl('System/Info')).then(function (info) {
|
2019-01-10 05:39:37 -07:00
|
|
|
|
|
|
|
// If this is back to false, the restart completed
|
|
|
|
if (!info.IsShuttingDown) {
|
|
|
|
currentInstance.restarted = true;
|
|
|
|
dialogHelper.close(currentDlg);
|
|
|
|
} else {
|
|
|
|
retryReload(retryCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
}, function () {
|
|
|
|
retryReload(retryCount);
|
|
|
|
});
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function retryReload(retryCount) {
|
2019-01-10 05:39:37 -07:00
|
|
|
setTimeout(function () {
|
|
|
|
retryCount = retryCount || 0;
|
|
|
|
retryCount++;
|
|
|
|
|
|
|
|
if (retryCount < 150) {
|
|
|
|
reloadPageWhenServerAvailable(retryCount);
|
|
|
|
}
|
|
|
|
}, 500);
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function startRestart(instance, apiClient, dlg) {
|
2019-01-10 05:39:37 -07:00
|
|
|
currentApiClient = apiClient;
|
|
|
|
currentDlg = dlg;
|
|
|
|
currentInstance = instance;
|
|
|
|
|
|
|
|
apiClient.restartServer().then(function () {
|
|
|
|
setTimeout(reloadPageWhenServerAvailable, 250);
|
|
|
|
});
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function showDialog(instance, options, template) {
|
2019-01-10 05:39:37 -07:00
|
|
|
|
2018-10-22 15:05:09 -07:00
|
|
|
var dialogOptions = {
|
2019-01-10 05:39:37 -07:00
|
|
|
removeOnClose: true,
|
|
|
|
scrollY: false
|
|
|
|
};
|
|
|
|
|
|
|
|
var enableTvLayout = layoutManager.tv;
|
|
|
|
|
|
|
|
if (enableTvLayout) {
|
|
|
|
dialogOptions.size = 'fullscreen';
|
|
|
|
}
|
|
|
|
|
|
|
|
var dlg = dialogHelper.createDialog(dialogOptions);
|
|
|
|
|
|
|
|
var configuredButtons = [];
|
|
|
|
|
|
|
|
dlg.classList.add('formDialog');
|
|
|
|
|
2019-02-07 23:50:23 -07:00
|
|
|
dlg.innerHTML = globalize.translateHtml(template, 'core');
|
2019-01-10 05:39:37 -07:00
|
|
|
|
|
|
|
dlg.classList.add('align-items-center');
|
|
|
|
dlg.classList.add('justify-items-center');
|
|
|
|
|
|
|
|
var formDialogContent = dlg.querySelector('.formDialogContent');
|
|
|
|
formDialogContent.style['flex-grow'] = 'initial';
|
|
|
|
|
|
|
|
if (enableTvLayout) {
|
|
|
|
formDialogContent.style['max-width'] = '50%';
|
|
|
|
formDialogContent.style['max-height'] = '60%';
|
|
|
|
scrollHelper.centerFocus.on(formDialogContent, false);
|
|
|
|
} else {
|
|
|
|
formDialogContent.style.maxWidth = (Math.min((configuredButtons.length * 150) + 200, dom.getWindowSize().innerWidth - 50)) + 'px';
|
|
|
|
dlg.classList.add('dialog-fullscreen-lowres');
|
|
|
|
}
|
|
|
|
|
2019-03-22 15:47:01 -07:00
|
|
|
dlg.querySelector('.formDialogHeaderTitle').innerHTML = globalize.translate('HeaderRestartingServer');
|
2019-01-10 05:39:37 -07:00
|
|
|
|
2019-02-02 10:41:16 -07:00
|
|
|
dlg.querySelector('.text').innerHTML = globalize.translate('RestartPleaseWaitMessage');
|
2019-01-10 05:39:37 -07:00
|
|
|
|
2019-11-22 08:29:38 -07:00
|
|
|
var i;
|
|
|
|
var length;
|
2019-01-10 05:39:37 -07:00
|
|
|
var html = '';
|
2018-10-22 15:05:09 -07:00
|
|
|
for (i = 0, length = configuredButtons.length; i < length; i++) {
|
2019-01-10 05:39:37 -07:00
|
|
|
var item = configuredButtons[i];
|
|
|
|
var autoFocus = i === 0 ? ' autofocus' : '';
|
|
|
|
var buttonClass = 'btnOption raised formDialogFooterItem formDialogFooterItem-autosize';
|
|
|
|
|
|
|
|
if (item.type) {
|
|
|
|
buttonClass += ' button-' + item.type;
|
|
|
|
}
|
|
|
|
html += '<button is="emby-button" type="button" class="' + buttonClass + '" data-id="' + item.id + '"' + autoFocus + '>' + item.name + '</button>';
|
|
|
|
}
|
|
|
|
|
|
|
|
dlg.querySelector('.formDialogFooter').innerHTML = html;
|
|
|
|
|
|
|
|
function onButtonClick() {
|
|
|
|
dialogHelper.close(dlg);
|
|
|
|
}
|
|
|
|
|
|
|
|
var buttons = dlg.querySelectorAll('.btnOption');
|
|
|
|
for (i = 0, length = buttons.length; i < length; i++) {
|
|
|
|
buttons[i].addEventListener('click', onButtonClick);
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
2019-01-10 05:39:37 -07:00
|
|
|
|
2018-10-22 15:05:09 -07:00
|
|
|
var dlgPromise = dialogHelper.open(dlg);
|
2019-01-10 05:39:37 -07:00
|
|
|
|
|
|
|
startRestart(instance, options.apiClient, dlg);
|
|
|
|
|
|
|
|
return dlgPromise.then(function () {
|
|
|
|
|
|
|
|
if (enableTvLayout) {
|
|
|
|
scrollHelper.centerFocus.off(dlg.querySelector('.formDialogContent'), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
instance.destroy();
|
|
|
|
loading.hide();
|
|
|
|
|
|
|
|
if (instance.restarted) {
|
|
|
|
events.trigger(instance, 'restarted');
|
|
|
|
}
|
|
|
|
});
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function ServerRestartDialog(options) {
|
2019-01-10 05:39:37 -07:00
|
|
|
this.options = options;
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
2019-01-10 05:39:37 -07:00
|
|
|
|
|
|
|
ServerRestartDialog.prototype.show = function () {
|
2018-10-22 15:05:09 -07:00
|
|
|
var instance = this;
|
2019-01-10 05:39:37 -07:00
|
|
|
loading.show();
|
|
|
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
require(['text!./../dialog/dialog.template.html'], function (template) {
|
|
|
|
showDialog(instance, instance.options, template).then(resolve, reject);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
ServerRestartDialog.prototype.destroy = function () {
|
|
|
|
currentApiClient = null;
|
|
|
|
currentDlg = null;
|
|
|
|
currentInstance = null;
|
|
|
|
this.options = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
return ServerRestartDialog;
|
2020-02-22 09:47:03 -07:00
|
|
|
});
|