mirror of
https://github.com/jellyfin/jellyfin-web.git
synced 2024-11-18 03:18:19 -07:00
75 lines
2.0 KiB
JavaScript
75 lines
2.0 KiB
JavaScript
define(['loading', 'apphost', 'localsync'], function (loading, appHost) {
|
|
|
|
return function (view, params) {
|
|
|
|
var interval;
|
|
|
|
function isLocalSyncManagement() {
|
|
return appHost.supports('sync') && params.mode == 'offline';
|
|
}
|
|
|
|
function refreshSyncStatus(page) {
|
|
|
|
if (isLocalSyncManagement()) {
|
|
|
|
var status = LocalSync.getSyncStatus();
|
|
|
|
page.querySelector('.labelSyncStatus').innerHTML = Globalize.translate('LabelLocalSyncStatusValue', status);
|
|
if (status == 'Active') {
|
|
loading.show();
|
|
} else {
|
|
loading.hide();
|
|
}
|
|
|
|
if (status == "Active") {
|
|
page.querySelector('.btnSyncNow').classList.add('hide');
|
|
}
|
|
else {
|
|
page.querySelector('.btnSyncNow').classList.remove('hide');
|
|
}
|
|
}
|
|
}
|
|
|
|
function syncNow(page) {
|
|
|
|
LocalSync.sync();
|
|
require(['toast'], function (toast) {
|
|
toast(Globalize.translate('MessageSyncStarted'));
|
|
});
|
|
refreshSyncStatus(page);
|
|
}
|
|
|
|
view.querySelector('.btnSyncNow').addEventListener('click', function () {
|
|
syncNow(view);
|
|
});
|
|
|
|
if (isLocalSyncManagement()) {
|
|
|
|
view.querySelector('.localSyncStatus').classList.remove('hide');
|
|
|
|
} else {
|
|
view.querySelector('.localSyncStatus').classList.add('hide');
|
|
}
|
|
|
|
view.addEventListener('viewbeforeshow', function () {
|
|
var page = this;
|
|
|
|
refreshSyncStatus(page);
|
|
|
|
interval = setInterval(function () {
|
|
refreshSyncStatus(page);
|
|
}, 5000);
|
|
});
|
|
|
|
view.addEventListener('viewbeforehide', function () {
|
|
var page = this;
|
|
|
|
loading.hide();
|
|
|
|
if (interval) {
|
|
clearInterval(interval);
|
|
interval = null;
|
|
}
|
|
});
|
|
};
|
|
}); |