Skip to content

Commit bedb39f

Browse files
committed
Add a delay to AviaryUI
This prevents at least SOME races/desyncs while Advanced Scene Switcher does transitions.
1 parent f8d1a6a commit bedb39f

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

apps/aviaryui/src/main.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
gi.require_version('Gtk', '4.0')
2828
gi.require_version('Adw', '1')
2929

30-
from gi.repository import Gtk, Gio, Adw, GLib
30+
from gi.repository import Gtk, Gio, Adw, GLib, Soup
3131
from .window import AviaryuiWindow
3232

3333

@@ -119,11 +119,24 @@ def on_toggle_livestream_action(self, *args):
119119
new_state = not action.get_state()
120120
action.change_state(GLib.Variant.new_boolean(new_state))
121121

122-
# TODO use a real POST request when I don't have to deal with urllib's awfulness
123-
with request.urlopen(f'http://localhost:9000/aviaryui/set-livestream-state?state={new_state}') as res:
124-
pass
122+
status_label = self.props.active_window.status_label
123+
status_label.set_label('⚠️ Transitioning - this will take 15 seconds...')
124+
toggle_button = self.props.active_window.stream_toggle
125+
toggle_button.set_sensitive(False)
125126

126-
self.synchronize_ui()
127+
session = Soup.Session()
128+
# TODO use a real POST request
129+
message = Soup.Message.new('GET', f'http://localhost:9000/aviaryui/set-livestream-state?state={new_state}')
130+
131+
def on_response(session, result, _):
132+
# TODO handle exceptions
133+
response = session.send_and_read_finish(result)
134+
toggle_button.set_sensitive(True)
135+
self.synchronize_ui()
136+
#data = response.get_data().decode()
137+
#print(data)
138+
139+
session.send_and_read_async(message, GLib.PRIORITY_DEFAULT, None, on_response, None)
127140

128141
def create_action(self, name, callback, shortcuts=None):
129142
"""Add an application action.

apps/birdhoused/lib/http-aviaryui.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ router.get('/set-livestream-state', async function(req, res) {
1515

1616
var client = await obs();
1717
await client.call('SetCurrentProgramScene', {sceneName: targetScene});
18+
// https://stackoverflow.com/a/51939030
19+
await new Promise(resolve => setTimeout(resolve, 13000));
1820

1921
// TODO lol should we like... actually send something back
2022
res.send();

0 commit comments

Comments
 (0)