chat addon
This commit is contained in:
1 parent
d604c01114
commit
a45fa67ed2
4 files changed
+102
-1
No files matched your search
@@ -5,6 +5,7 @@ import signal
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
|
import time
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
|
||||||
import gi
|
import gi
|
||||||
@@ -21,11 +22,13 @@ from gi.repository import GLib, Gtk
|
|||||||
APP_URL = os.environ.get('BACKONE_APP_URL', 'http://127.0.0.1:9993/app/')
|
APP_URL = os.environ.get('BACKONE_APP_URL', 'http://127.0.0.1:9993/app/')
|
||||||
HEALTH_URL = os.environ.get('BACKONE_HEALTH_URL', 'http://127.0.0.1:9993/health')
|
HEALTH_URL = os.environ.get('BACKONE_HEALTH_URL', 'http://127.0.0.1:9993/health')
|
||||||
ICON_NAME = 'network-workgroup'
|
ICON_NAME = 'network-workgroup'
|
||||||
|
SERVICE_WAIT_SECONDS = int(os.environ.get('BACKONE_SERVICE_WAIT', '45'))
|
||||||
|
|
||||||
|
|
||||||
class BackOneTray:
|
class BackOneTray:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._windows = []
|
self._windows = []
|
||||||
|
self._service_ready = False
|
||||||
self.indicator = AppIndicator3.Indicator.new(
|
self.indicator = AppIndicator3.Indicator.new(
|
||||||
'backone-tray',
|
'backone-tray',
|
||||||
ICON_NAME,
|
ICON_NAME,
|
||||||
@@ -39,6 +42,7 @@ class BackOneTray:
|
|||||||
pass
|
pass
|
||||||
self._update_status()
|
self._update_status()
|
||||||
GLib.timeout_add_seconds(30, self._on_timer)
|
GLib.timeout_add_seconds(30, self._on_timer)
|
||||||
|
GLib.idle_add(self._bootstrap_service)
|
||||||
|
|
||||||
def _build_menu(self):
|
def _build_menu(self):
|
||||||
menu = Gtk.Menu()
|
menu = Gtk.Menu()
|
||||||
@@ -67,15 +71,94 @@ class BackOneTray:
|
|||||||
except Exception:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def _systemd_active(self):
|
||||||
|
try:
|
||||||
|
result = subprocess.run(
|
||||||
|
['systemctl', 'is-active', 'backone'],
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
timeout=5,
|
||||||
|
)
|
||||||
|
return result.returncode == 0 and result.stdout.strip() == 'active'
|
||||||
|
except (OSError, subprocess.TimeoutExpired):
|
||||||
|
return False
|
||||||
|
|
||||||
|
def _start_service(self):
|
||||||
|
for cmd in (
|
||||||
|
['systemctl', 'start', 'backone'],
|
||||||
|
['pkexec', 'systemctl', 'start', 'backone'],
|
||||||
|
):
|
||||||
|
try:
|
||||||
|
result = subprocess.run(
|
||||||
|
cmd,
|
||||||
|
capture_output=True,
|
||||||
|
timeout=30,
|
||||||
|
)
|
||||||
|
if result.returncode == 0:
|
||||||
|
return True
|
||||||
|
except (OSError, subprocess.TimeoutExpired):
|
||||||
|
continue
|
||||||
|
return False
|
||||||
|
|
||||||
|
def _wait_for_service(self, timeout=SERVICE_WAIT_SECONDS):
|
||||||
|
deadline = time.time() + timeout
|
||||||
|
while time.time() < deadline:
|
||||||
|
if self._service_ok():
|
||||||
|
self._service_ready = True
|
||||||
|
return True
|
||||||
|
time.sleep(0.5)
|
||||||
|
return False
|
||||||
|
|
||||||
|
def _ensure_service(self):
|
||||||
|
if self._service_ok():
|
||||||
|
self._service_ready = True
|
||||||
|
return True
|
||||||
|
if not self._systemd_active():
|
||||||
|
self._start_service()
|
||||||
|
return self._wait_for_service()
|
||||||
|
|
||||||
|
def _bootstrap_service(self):
|
||||||
|
def worker():
|
||||||
|
ready = self._ensure_service()
|
||||||
|
GLib.idle_add(self._on_bootstrap_done, ready)
|
||||||
|
threading.Thread(target=worker, daemon=True).start()
|
||||||
|
return False
|
||||||
|
|
||||||
|
def _on_bootstrap_done(self, ready):
|
||||||
|
self._service_ready = ready
|
||||||
|
self._update_status()
|
||||||
|
return False
|
||||||
|
|
||||||
def _update_status(self):
|
def _update_status(self):
|
||||||
title = 'BackOne (online)' if self._service_ok() else 'BackOne (offline)'
|
online = self._service_ok()
|
||||||
|
self._service_ready = online
|
||||||
|
title = 'BackOne (online)' if online else 'BackOne (offline)'
|
||||||
self.indicator.set_title(title)
|
self.indicator.set_title(title)
|
||||||
|
|
||||||
def _on_timer(self):
|
def _on_timer(self):
|
||||||
self._update_status()
|
self._update_status()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def _show_offline_dialog(self):
|
||||||
|
dialog = Gtk.MessageDialog(
|
||||||
|
transient_for=None,
|
||||||
|
flags=0,
|
||||||
|
message_type=Gtk.MessageType.ERROR,
|
||||||
|
buttons=Gtk.ButtonsType.OK,
|
||||||
|
text='BackOne service is not running',
|
||||||
|
)
|
||||||
|
dialog.format_secondary_text(
|
||||||
|
'Could not reach the BackOne web server on 127.0.0.1:9993.\n\n'
|
||||||
|
'Use "Restart BackOne Service" from the tray menu, or run:\n'
|
||||||
|
' sudo systemctl start backone'
|
||||||
|
)
|
||||||
|
dialog.run()
|
||||||
|
dialog.destroy()
|
||||||
|
|
||||||
def _open_url(self, url):
|
def _open_url(self, url):
|
||||||
|
if not self._ensure_service():
|
||||||
|
self._show_offline_dialog()
|
||||||
|
return
|
||||||
if self._try_webkit(url):
|
if self._try_webkit(url):
|
||||||
return
|
return
|
||||||
for cmd in (
|
for cmd in (
|
||||||
@@ -115,6 +198,10 @@ class BackOneTray:
|
|||||||
stdout=subprocess.DEVNULL,
|
stdout=subprocess.DEVNULL,
|
||||||
stderr=subprocess.DEVNULL,
|
stderr=subprocess.DEVNULL,
|
||||||
)
|
)
|
||||||
|
def worker():
|
||||||
|
ready = self._wait_for_service(timeout=30)
|
||||||
|
GLib.idle_add(self._on_bootstrap_done, ready)
|
||||||
|
threading.Thread(target=worker, daemon=True).start()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
Vendored
+8
@@ -6,6 +6,14 @@ case "$1" in
|
|||||||
elif [ -x /usr/lib/backone/addons/updater/rebuild-addon-manifest.sh ]; then
|
elif [ -x /usr/lib/backone/addons/updater/rebuild-addon-manifest.sh ]; then
|
||||||
BACKONE_HOME=/var/lib/backone /usr/lib/backone/addons/updater/rebuild-addon-manifest.sh || true
|
BACKONE_HOME=/var/lib/backone /usr/lib/backone/addons/updater/rebuild-addon-manifest.sh || true
|
||||||
fi
|
fi
|
||||||
|
if [ -x /usr/lib/backone/addons/updater/merge-local-conf.sh ]; then
|
||||||
|
BACKONE_HOME=/var/lib/backone /usr/lib/backone/addons/updater/merge-local-conf.sh '{"settings":{"enableWebServer":true}}' || true
|
||||||
|
fi
|
||||||
|
if [ -d /run/systemd/system ]; then
|
||||||
|
systemctl daemon-reload 2>/dev/null || true
|
||||||
|
systemctl enable backone.service 2>/dev/null || true
|
||||||
|
systemctl start backone.service 2>/dev/null || true
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
#DEBHELPER#
|
#DEBHELPER#
|
||||||
|
|||||||
Vendored
+1
@@ -6,6 +6,7 @@ Wants=network-online.target
|
|||||||
[Service]
|
[Service]
|
||||||
ExecStart=/usr/sbin/backone
|
ExecStart=/usr/sbin/backone
|
||||||
Restart=always
|
Restart=always
|
||||||
|
RestartSec=5
|
||||||
KillMode=process
|
KillMode=process
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
|
|||||||
Vendored
+5
@@ -20,6 +20,11 @@ case "$1" in
|
|||||||
rm -f /etc/systemd/system/backone.service
|
rm -f /etc/systemd/system/backone.service
|
||||||
systemctl daemon-reload 2>/dev/null || true
|
systemctl daemon-reload 2>/dev/null || true
|
||||||
fi
|
fi
|
||||||
|
# backone must run as root; older packages shipped User=backone which prevents startup
|
||||||
|
if [ -f /usr/lib/systemd/system/backone.service ] && grep -q '^User=backone' /usr/lib/systemd/system/backone.service 2>/dev/null; then
|
||||||
|
sed -i '/^User=backone$/d; /^Group=backone$/d; /^StateDirectory=backone$/d' /usr/lib/systemd/system/backone.service
|
||||||
|
systemctl daemon-reload 2>/dev/null || true
|
||||||
|
fi
|
||||||
if [ -x /usr/lib/backone/addons/updater/sync-authtoken.sh ]; then
|
if [ -x /usr/lib/backone/addons/updater/sync-authtoken.sh ]; then
|
||||||
/usr/lib/backone/addons/updater/sync-authtoken.sh || true
|
/usr/lib/backone/addons/updater/sync-authtoken.sh || true
|
||||||
elif [ -x /usr/share/backone/sync-authtoken.sh ]; then
|
elif [ -x /usr/share/backone/sync-authtoken.sh ]; then
|
||||||
|
|||||||
Reference in new issue
Block a user