|
27 | 27 | gi.require_version('Gtk', '4.0') |
28 | 28 | gi.require_version('Adw', '1') |
29 | 29 |
|
30 | | -from gi.repository import Gtk, Gio, Adw, GLib |
| 30 | +from gi.repository import Gtk, Gio, Adw, GLib, Soup |
31 | 31 | from .window import AviaryuiWindow |
32 | 32 |
|
33 | 33 |
|
@@ -119,11 +119,24 @@ def on_toggle_livestream_action(self, *args): |
119 | 119 | new_state = not action.get_state() |
120 | 120 | action.change_state(GLib.Variant.new_boolean(new_state)) |
121 | 121 |
|
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) |
125 | 126 |
|
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) |
127 | 140 |
|
128 | 141 | def create_action(self, name, callback, shortcuts=None): |
129 | 142 | """Add an application action. |
|
0 commit comments