Skip to content

Commit

Permalink
window: fix breakages with background daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
knuxify committed Jul 15, 2022
1 parent 53ce008 commit 5ddd8ee
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 17 deletions.
1 change: 1 addition & 0 deletions data/ui/window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<property name="width-request">290</property>
<property name="default-width">480</property>
<property name="default-height">800</property>
<property name="hide-on-close">true</property>

<child>
<object class="GtkBox">
Expand Down
39 changes: 29 additions & 10 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
from .window import LapelWindow, AboutDialog

class Application(Adw.Application):
win = None
assistant_popup = None

def __init__(self):
super().__init__(
application_id='org.dithernet.lapel',
Expand All @@ -24,28 +27,44 @@ def __init__(self):
)

def do_activate(self):
if not self.get_is_remote():
# FIXME: get_is_remote doesn't work sometimes? checking for self.win
# is a workaround for that
if not self.get_is_remote() and not self.win:
if not get_daemon():
start_daemon()
self.daemon = get_daemon()

self.assistant_popup = AssistantPopup(self)
if not self.assistant_popup:
self.assistant_popup = AssistantPopup(self)

# HACK: without this, showing the window results in:
# gdk_gl_context_make_current() failed
self.assistant_popup.present()
self.assistant_popup.hide()
# HACK: without this, showing the window results in:
# gdk_gl_context_make_current() failed
self.assistant_popup.present()
self.assistant_popup.hide()

# Keep running in the background
self.hold()

win = self.props.active_window
if not win:
win = LapelWindow(application=self)
self.show_window()

def show_window(self, *args):
active_window = self.get_active_window()
if active_window and type(active_window) == LapelWindow:
active_window.present()
return

if not self.win:
self.win = LapelWindow(application=self)
self.win.connect('close-request', self.close_window)

self.create_action('about', self.on_about_action)
self.create_action('preferences', self.on_preferences_action)
self.create_action('quit', self.on_quit_action)
win.present()
self.win.present()

def close_window(self, *args):
self.win = None
return False

def on_about_action(self, widget, _):
about = AboutDialog(self.props.active_window)
Expand Down
40 changes: 33 additions & 7 deletions src/views/popup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,58 @@ class AssistantPopup(Adw.Window):

flap = Gtk.Template.Child()

_state = -1 # closed

def __init__(self, app):
super().__init__()
self.app = app
self.flap.connect('notify::reveal-flap', self.handle_reveal_flap)
self.flap.connect('notify::reveal-progress', self.handle_reveal_progress)
self.daemon = get_daemon()
self.daemon.on('mycroft.mic.listen', self._show)
#self.daemon.on('mycroft.mic.listen', self._show)
self.daemon.on('recognizer_loop:wakeword', self._show)
self.daemon.on('recognizer_loop:record_end', self._hide)
self.daemon.on('speak', self.open_on_message)

def _show(self, *args):
active_window = self.app.get_active_window()
if active_window and active_window.get_visible():
return

self.set_visible(True)
self.present()
self.fullscreen()
self.flap.set_reveal_flap(True)
if self._state == -1:
self._state = 1 # showing
self.set_visible(True)
self.present()
self.fullscreen()
self.flap.set_reveal_flap(True)

def _hide(self, *args):
self.flap.set_reveal_flap(False)
if self.flap.get_reveal_flap():
self._state = 0
self.flap.set_reveal_flap(False)

def handle_reveal_flap(self, *args):
if self._state == -1: # closed
self._state = 1 # opening
elif self._state == 2: # opened
self._state = 0 # hiding

def handle_reveal_progress(self, flap, *args):
progress = flap.get_reveal_progress()
if progress == 0:
if progress == 0 and self._state == 0:
self.set_visible(False)
self.daemon.stop_record()
self._state = -1 # closed
elif progress == 1 and self._state == 1:
self._state = 2

def open_on_message(self, message):
try:
if message.data['meta']['skill'] == 'UnknownSkill':
return
except KeyError:
pass
self.app.show_window()

def close(self, *args):
# stub
Expand Down

0 comments on commit 5ddd8ee

Please sign in to comment.