Skip to content

Commit 6a88d64

Browse files
committed
Fixes #11
1 parent 0d6c59b commit 6a88d64

6 files changed

Lines changed: 94 additions & 40 deletions

File tree

build

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ cp /home/patch/patchOS/services/jack.service /etc/systemd/system/jack.service
9090
chmod 644 /etc/systemd/system/jack.service
9191
mkdir -p /home/patch/.config/jack
9292
cp /home/patch/patchOS/packages/jack/jack.conf /home/patch/.config/jack/jack.conf
93-
systemctl enable jack.service
9493

9594
# Configure jack service to start/stop on ES-8 connect/disconnect
9695
cp /home/patch/patchOS/es8/es8.rules /etc/udev/rules.d/es8.rules
@@ -100,8 +99,6 @@ cp /home/patch/patchOS/services/jacktrip-server.service /etc/systemd/system/jack
10099
cp /home/patch/patchOS/services/jacktrip-client.service /etc/systemd/system/jacktrip-client.service
101100
chmod 644 /etc/systemd/system/jacktrip-server.service
102101
chmod 644 /etc/systemd/system/jacktrip-client.service
103-
systemctl enable jacktrip-server.service
104-
systemctl enable jacktrip-client.service
105102

106103
# Enable and start mDNS service
107104
cp /home/patch/patchOS/services/http.service /etc/avahi/services/http.service

control-panel/control-panel.py

Lines changed: 53 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import sys
3+
from subprocess import call
34
import argparse
45
from time import sleep
56
from threading import Thread, Event
@@ -8,6 +9,8 @@
89
from flask import Flask, render_template, jsonify, request
910
from flask_socketio import SocketIO, emit
1011

12+
debug = False
13+
1114
parser = argparse.ArgumentParser(description='patchOS control panel')
1215
parser.add_argument('--port', dest='port', type=int, default=80)
1316
args = parser.parse_args()
@@ -23,37 +26,6 @@
2326
'org.freedesktop.systemd1.Manager'
2427
)
2528

26-
jackService = bus.get_object(
27-
'org.freedesktop.systemd1',
28-
object_path = manager.GetUnit('jack.service')
29-
)
30-
31-
jacktripServerService = bus.get_object(
32-
'org.freedesktop.systemd1',
33-
object_path = manager.GetUnit('jacktrip-server.service')
34-
)
35-
36-
jacktripClientService = bus.get_object(
37-
'org.freedesktop.systemd1',
38-
object_path = manager.GetUnit('jacktrip-client.service')
39-
)
40-
41-
jackServiceInterface = dbus.Interface(
42-
jackService,
43-
dbus_interface = 'org.freedesktop.DBus.Properties'
44-
)
45-
46-
jacktripServerServiceInterface = dbus.Interface(
47-
jacktripServerService,
48-
dbus_interface ='org.freedesktop.DBus.Properties'
49-
)
50-
51-
jacktripClientServiceInterface = dbus.Interface(
52-
jacktripClientService,
53-
dbus_interface = 'org.freedesktop.DBus.Properties'
54-
)
55-
56-
debug = False
5729
clientCount = 0
5830

5931
app = Flask(__name__)
@@ -66,12 +38,54 @@
6638
thread_stop_event = Event()
6739

6840
def getJackServiceStatus():
69-
return jackServiceInterface.Get('org.freedesktop.systemd1.Unit', 'ActiveState')
41+
status = 'inactive'
7042

43+
try:
44+
jackService = bus.get_object(
45+
'org.freedesktop.systemd1',
46+
object_path = manager.GetUnit('jack.service')
47+
)
48+
49+
jackServiceInterface = dbus.Interface(
50+
jackService,
51+
dbus_interface = 'org.freedesktop.DBus.Properties'
52+
)
53+
54+
status = jackServiceInterface.Get('org.freedesktop.systemd1.Unit', 'ActiveState')
55+
except:
56+
pass
57+
58+
return status
7159

7260
def getJacktripServiceStatus():
73-
serverStatus = jacktripServerServiceInterface.Get('org.freedesktop.systemd1.Unit', 'ActiveState')
74-
clientStatus = jacktripClientServiceInterface.Get('org.freedesktop.systemd1.Unit', 'ActiveState')
61+
serverStatus = 'inactive'
62+
clientStatus = 'inactive'
63+
64+
try:
65+
jacktripServerService = bus.get_object(
66+
'org.freedesktop.systemd1',
67+
object_path = manager.GetUnit('jacktrip-server.service')
68+
)
69+
70+
jacktripClientService = bus.get_object(
71+
'org.freedesktop.systemd1',
72+
object_path = manager.GetUnit('jacktrip-client.service')
73+
)
74+
75+
jacktripServerServiceInterface = dbus.Interface(
76+
jacktripServerService,
77+
dbus_interface ='org.freedesktop.DBus.Properties'
78+
)
79+
80+
jacktripClientServiceInterface = dbus.Interface(
81+
jacktripClientService,
82+
dbus_interface = 'org.freedesktop.DBus.Properties'
83+
)
84+
85+
serverStatus = jacktripServerServiceInterface.Get('org.freedesktop.systemd1.Unit', 'ActiveState')
86+
clientStatus = jacktripClientServiceInterface.Get('org.freedesktop.systemd1.Unit', 'ActiveState')
87+
except:
88+
pass
7589

7690
if serverStatus == 'inactive' and clientStatus == 'inactive':
7791
return {'status': 'inactive', 'mode': 'undefined'}
@@ -165,5 +179,10 @@ def queryExternalIp():
165179
emit('externalIp', urllib.request.urlopen('https://ident.me').read().decode('utf8'))
166180

167181

182+
@socketio.on('shutdown?')
183+
def queryExternalIp():
184+
call("shutdown now", shell=True)
185+
186+
168187
if __name__ == "__main__":
169188
socketio.run(app, host='0.0.0.0', port=args.port)

control-panel/static/css/app.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4549,6 +4549,14 @@ body.loading:after {
45494549
border-width: 0.25em;
45504550
z-index: 1001; }
45514551

4552+
.shutdown-button {
4553+
position: fixed;
4554+
top: 10px;
4555+
right: 10px;
4556+
background-color: transparent;
4557+
border: none;
4558+
color: #D0D1CD; }
4559+
45524560
.debug-info {
45534561
display: none; }
45544562

control-panel/static/css/app.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ body.loading {
6969
}
7070
}
7171

72+
.shutdown-button {
73+
position: fixed;
74+
top: 10px;
75+
right: 10px;
76+
background-color: transparent;
77+
border: none;
78+
color: $grey-light;
79+
}
80+
7281
.debug-info {
7382
display: none;
7483
}

control-panel/static/js/app.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const connectToServerButton = document.querySelector('.connect-to-server-button'
1010
const serverIpInput = document.querySelector('input[name="serverIp"]');
1111
const startServerButton = document.querySelector('.start-server-button');
1212
const stopButtons = document.querySelectorAll('.stop-button');
13+
const shutdownButton = document.querySelectorAll('.shutdown-button');
1314
const startupViewElement = document.querySelector('.startup-view');
1415
const audioDeviceDisconnectedViewElement = document.querySelector('.audio-device-disconnected-view');
1516
const serverRunningViewElement = document.querySelector('.server-running-view');
@@ -39,7 +40,8 @@ const states = [
3940
'client-active',
4041
'server-failed',
4142
'client-failed',
42-
'stopping'
43+
'stopping',
44+
'shutting-down'
4345
];
4446

4547
let state = 'inactive';
@@ -112,15 +114,17 @@ function onStatus(data) {
112114
}
113115
// Set status UI elements <--
114116

115-
// Handle inactive jack service
116-
if (jackStatus == 'inactive') {
117+
// Handle inactive/failed jack service
118+
if (jackStatus != 'active') {
117119
state = 'audio-device-disconnected';
118120

119121
showView(audioDeviceDisconnectedViewElement);
120122

121123
document.body.classList.remove('loading');
122124

123125
return;
126+
} else if (state == 'audio-device-disconnected') {
127+
state = 'inactive';
124128
}
125129

126130
// Handle stray failed jacktrip service
@@ -193,6 +197,8 @@ function onStatus(data) {
193197
break;
194198
case 'stopping':
195199
break;
200+
case 'shutting-down':
201+
break;
196202
}
197203

198204
document.body.classList.remove('loading');
@@ -272,3 +278,11 @@ function stop() {
272278

273279
socket.emit('jacktrip-stop');
274280
}
281+
282+
function shutdown() {
283+
state = 'shutting-down';
284+
285+
document.body.classList.add('loading');
286+
287+
socket.emit('shutdown?');
288+
}

control-panel/templates/index.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,16 @@
2222

2323
<link rel="stylesheet" href="{{ url_for('static', filename = 'css/app.css') }}">
2424

25+
<script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script>
2526
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.3.0/socket.io.js"></script>
2627
</head>
2728
<body class="loading">
29+
<button class="button is-medium is-rounded shutdown-button" onclick="shutdown()">
30+
<span class="icon is-medium">
31+
<i class="fas fa-power-off fa-lg"></i>
32+
</span>
33+
</button>
34+
2835
<section class="section">
2936
<div class="container">
3037
<div class="tile is-ancestor">

0 commit comments

Comments
 (0)