better restart logic

This commit is contained in:
jr-k 2024-02-27 15:27:37 +01:00
parent b4e3e71a30
commit eb3cadf75a
3 changed files with 25 additions and 9 deletions

View File

@ -1,4 +1,10 @@
jQuery(document).ready(function ($) {
var done = function () {
setTimeout(function() {
document.location.reload();
}, 3000);
};
$(document).on('click', '.sysinfo-restart', function () {
if (confirm(l.js_sysinfo_restart_confirmation)) {
$('body').html(l.js_sysinfo_restart_loading).css({margin:200});
@ -7,11 +13,7 @@ jQuery(document).ready(function ($) {
headers: {'Content-Type': 'application/json'},
data: '',
method: 'POST',
}).catch(function () {
setTimeout(function() {
document.location.reload();
}, 3000);
});
}).done(done).catch(done);
}
});

View File

@ -90,7 +90,7 @@ def inject_global_vars():
PlayerController(app, LANGDICT, slide_manager)
SlideshowController(app, LANGDICT, slide_manager)
SettingsController(app, LANGDICT, variable_manager)
SysinfoController(app, LANGDICT)
SysinfoController(app, LANGDICT, config)
if vars['fleet_enabled'].as_bool():
FleetController(app, LANGDICT, screen_manager)

View File

@ -1,5 +1,7 @@
import os
import sys
import platform
import subprocess
from flask import Flask, render_template, jsonify
from src.utils import get_ip_address
@ -7,9 +9,10 @@ from src.utils import get_ip_address
class SysinfoController:
def __init__(self, app, lang_dict):
def __init__(self, app, lang_dict, config):
self._app = app
self._lang_dict = lang_dict
self._config = config
self.register()
def register(self):
@ -24,7 +27,18 @@ class SysinfoController:
)
def sysinfo_restart(self):
python = sys.executable
os.execl(python, python, *sys.argv)
if platform.system().lower() == 'darwin':
if self._config['debug']:
python = sys.executable
os.execl(python, python, *sys.argv)
else:
try:
subprocess.run(["sudo", "systemctl", "restart", 'obscreen'], check=True, timeout=10, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
pass
except subprocess.TimeoutExpired:
pass
except subprocess.CalledProcessError:
pass
return jsonify({'status': 'ok'})