oxjs might be replaced get replaced right now, only use js
This commit is contained in:
parent
fb51189d15
commit
47fe90329c
3 changed files with 57 additions and 89 deletions
|
@ -242,6 +242,10 @@ actions.register(restart, cache=False)
|
|||
|
||||
|
||||
class Update(Thread):
|
||||
_status = {
|
||||
'reload': False,
|
||||
'status': 'Updating Open Media Library...'
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
Thread.__init__(self)
|
||||
|
@ -250,10 +254,11 @@ class Update(Thread):
|
|||
|
||||
def status(self, status, reload=False):
|
||||
from websocket import trigger_event
|
||||
trigger_event('updatestatus', {
|
||||
self._status = {
|
||||
'reload': reload,
|
||||
'status': status,
|
||||
})
|
||||
}
|
||||
trigger_event('updatestatus', self._status)
|
||||
|
||||
def install(self):
|
||||
while update_available():
|
||||
|
@ -272,7 +277,7 @@ class Update(Thread):
|
|||
db_version = settings.server.get('db_version', 0)
|
||||
if db_version < settings.DB_VERSION:
|
||||
self.status('Migrating database...')
|
||||
time.sleep(1)
|
||||
time.sleep(30)
|
||||
settings.server['db_version'] = settings.DB_VERSION
|
||||
|
||||
def run(self):
|
||||
|
|
|
@ -34,6 +34,9 @@ class Handler(WebSocketHandler):
|
|||
self.close()
|
||||
if self not in state.websockets:
|
||||
state.websockets.append(self)
|
||||
if state.update:
|
||||
trigger_event('updatestatus', state.tasks._status)
|
||||
else:
|
||||
trigger_event('status', {
|
||||
'id': settings.USER_ID,
|
||||
'online': state.online
|
||||
|
|
|
@ -4,31 +4,63 @@
|
|||
|
||||
var animationInterval,
|
||||
enableDebugMode = getLocalStorage('oml.enableDebugMode'),
|
||||
omlVersion = getOMLVersion(),
|
||||
oxjsPath = '/static/oxjs/' + (enableDebugMode ? 'dev' : 'min'),
|
||||
terminal,
|
||||
theme = getLocalStorage('Ox.theme')
|
||||
&& JSON.parse(localStorage['Ox.theme'])
|
||||
|| 'oxlight';
|
||||
|
||||
loadImages(function(images) {
|
||||
loadScreen(images);
|
||||
loadOxJS(loadOML);
|
||||
initUpdate();
|
||||
});
|
||||
|
||||
function connectSocket() {
|
||||
update.socket = new WebSocket('ws://' + document.location.host + '/ws');
|
||||
update.socket.onopen = function(event) {
|
||||
if (update.reload) {
|
||||
reload();
|
||||
}
|
||||
};
|
||||
update.socket.onmessage = function(event) {
|
||||
var name, data = JSON.parse(event.data);
|
||||
name = data[0];
|
||||
data = data[1];
|
||||
if (name == 'updatestatus') {
|
||||
update.status.innerHTML = data.status;
|
||||
update.reload = data.reload;
|
||||
} else {
|
||||
console.log(name, data);
|
||||
}
|
||||
};
|
||||
update.socket.onerror = function(event) {
|
||||
update.socket.close();
|
||||
};
|
||||
update.socket.onclose = function(event) {
|
||||
setTimeout(connectSocket, 1000);
|
||||
};
|
||||
}
|
||||
|
||||
function getLocalStorage(key) {
|
||||
try {
|
||||
return localStorage[key];
|
||||
} catch(e) {}
|
||||
}
|
||||
|
||||
function getOMLVersion() {
|
||||
var i, path, scripts = document.getElementsByTagName('script');
|
||||
for (i = 0; i < scripts.length; i++) {
|
||||
if(/oml.update.js/.test(scripts[i].src)) {
|
||||
return scripts[i].src.replace(/.*\?/, '');
|
||||
}
|
||||
}
|
||||
function initUpdate(browserSupported) {
|
||||
window.update = {};
|
||||
update.status = document.createElement('div');
|
||||
update.status.className = 'OxElement';
|
||||
update.status.style.left = 0;
|
||||
update.status.style.right = 0;
|
||||
update.status.style.bottom = '50px';
|
||||
update.status.style.textAlign = 'center';
|
||||
update.status.style.position = 'absolute';
|
||||
update.status.style.paddingLeft = '16px';
|
||||
update.status.style.color = '#999999';
|
||||
update.status.style.fontFamily = "Lucida Grande, Segoe UI, DejaVu Sans, Lucida Sans Unicode, Helvetica, Arial, sans-serif";
|
||||
update.status.style.fontSize = "11px";
|
||||
document.querySelector('#loadingScreen').appendChild(update.status);
|
||||
connectSocket();
|
||||
}
|
||||
|
||||
function loadImages(callback) {
|
||||
|
@ -68,65 +100,6 @@
|
|||
images.logo.src = '/static/png/oml.png';
|
||||
}
|
||||
|
||||
function loadOML(browserSupported) {
|
||||
window.oml = Ox.App({
|
||||
name: 'oml',
|
||||
socket: 'ws://' + document.location.host + '/ws',
|
||||
url: '/api/'
|
||||
}).bindEvent({
|
||||
load: function(data) {
|
||||
data.browserSupported = browserSupported;
|
||||
oml.ui = {};
|
||||
|
||||
oml.ui.status = Ox.Element()
|
||||
.css({
|
||||
position: 'absolute',
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: '50px',
|
||||
textAlign: 'center',
|
||||
paddingLeft: '16px',
|
||||
color: '#999999'
|
||||
}).appendTo(Ox.$('#loadingScreen'));
|
||||
oml.ui.status.html('Updating Open Media Library...');
|
||||
oml.down = setTimeout(function() {
|
||||
if (oml.socket.readyState != oml.socket.OPEN && Ox.isUndefined(oml.reload)) {
|
||||
reload();
|
||||
}
|
||||
}, 5000);
|
||||
},
|
||||
updatestatus: function(data) {
|
||||
oml.ui.status.html(data.status);
|
||||
oml.reload = data.reload;
|
||||
},
|
||||
close: function(data) {
|
||||
},
|
||||
open: function(data) {
|
||||
if (oml.reload) {
|
||||
reload();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function loadOxJS(callback) {
|
||||
var head = document.head
|
||||
|| document.getElementsByTagName('head')[0]
|
||||
|| document.documentElement,
|
||||
script = document.createElement('script');
|
||||
script.onload = function() {
|
||||
Ox.load({UI: {theme: theme}}, function() {
|
||||
Ox.formatUpper = function(string) {
|
||||
return string.toUpperCase();
|
||||
};
|
||||
callback();
|
||||
});
|
||||
};
|
||||
script.src = oxjsPath + '/Ox.js?' + omlVersion;
|
||||
script.type = 'text/javascript';
|
||||
head.appendChild(script);
|
||||
}
|
||||
|
||||
function loadScreen(images) {
|
||||
var loadingScreen = document.createElement('div');
|
||||
loadingScreen.setAttribute('id', 'loadingScreen');
|
||||
|
@ -153,15 +126,6 @@
|
|||
document.location.href = document.location.protocol + '//' + document.location.host;
|
||||
}
|
||||
|
||||
function removeScreen() {
|
||||
var $loadingScreen = $('#loadingScreen');
|
||||
$loadingScreen.animate({
|
||||
opacity: 0
|
||||
}, 1000, function() {
|
||||
$loadingScreen.remove();
|
||||
});
|
||||
}
|
||||
|
||||
function startAnimation() {
|
||||
var css, deg = 0, loadingIcon = document.getElementById('loadingIcon'),
|
||||
previousTime = +new Date();
|
||||
|
@ -179,8 +143,4 @@
|
|||
}, 83);
|
||||
}
|
||||
|
||||
function stopAnimation() {
|
||||
clearInterval(animationInterval);
|
||||
}
|
||||
|
||||
}());
|
||||
|
|
Loading…
Reference in a new issue