Fixed error with reopening libremsonic
This commit is contained in:
@@ -40,54 +40,6 @@ class LibremsonicApp(Gtk.Application):
|
|||||||
|
|
||||||
self.connect('shutdown', self.on_app_shutdown)
|
self.connect('shutdown', self.on_app_shutdown)
|
||||||
|
|
||||||
self.last_play_queue_update = 0
|
|
||||||
|
|
||||||
def time_observer(value):
|
|
||||||
self.state.song_progress = value
|
|
||||||
GLib.idle_add(
|
|
||||||
self.window.player_controls.update_scrubber,
|
|
||||||
self.state.song_progress,
|
|
||||||
self.state.current_song.duration,
|
|
||||||
)
|
|
||||||
if not value:
|
|
||||||
self.last_play_queue_update = 0
|
|
||||||
elif self.last_play_queue_update + 15 <= value:
|
|
||||||
self.save_play_queue()
|
|
||||||
|
|
||||||
def on_track_end():
|
|
||||||
GLib.idle_add(self.on_next_track)
|
|
||||||
|
|
||||||
def on_player_event(event: PlayerEvent):
|
|
||||||
if event.name == 'play_state_change':
|
|
||||||
self.state.playing = event.value
|
|
||||||
elif event.name == 'volume_change':
|
|
||||||
self.state.old_volume = self.state.volume
|
|
||||||
self.state.volume = event.value
|
|
||||||
|
|
||||||
GLib.idle_add(self.update_window)
|
|
||||||
|
|
||||||
self.mpv_player = MPVPlayer(
|
|
||||||
time_observer,
|
|
||||||
on_track_end,
|
|
||||||
on_player_event,
|
|
||||||
self.state.config,
|
|
||||||
)
|
|
||||||
self.chromecast_player = ChromecastPlayer(
|
|
||||||
time_observer,
|
|
||||||
on_track_end,
|
|
||||||
on_player_event,
|
|
||||||
self.state.config,
|
|
||||||
)
|
|
||||||
self.player = self.mpv_player
|
|
||||||
|
|
||||||
if self.state.current_device != 'this device':
|
|
||||||
# TODO figure out how to activate the chromecast if possible
|
|
||||||
# without blocking the main thread. Also, need to make it obvious
|
|
||||||
# that we are trying to connect.
|
|
||||||
pass
|
|
||||||
|
|
||||||
self.state.current_device = 'this device'
|
|
||||||
|
|
||||||
# Handle command line option parsing.
|
# Handle command line option parsing.
|
||||||
def do_command_line(self, command_line):
|
def do_command_line(self, command_line):
|
||||||
options = command_line.get_options_dict()
|
options = command_line.get_options_dict()
|
||||||
@@ -138,20 +90,24 @@ class LibremsonicApp(Gtk.Application):
|
|||||||
|
|
||||||
def do_activate(self):
|
def do_activate(self):
|
||||||
# We only allow a single window and raise any existing ones
|
# We only allow a single window and raise any existing ones
|
||||||
if not self.window:
|
if self.window:
|
||||||
# Windows are associated with the application when the last one is
|
self.window.show_all()
|
||||||
# closed the application shuts down.
|
self.window.present()
|
||||||
self.window = MainWindow(application=self, title="LibremSonic")
|
return
|
||||||
|
|
||||||
# Configure the CSS provider so that we can style elements on the
|
# Windows are associated with the application when the last one is
|
||||||
# window.
|
# closed the application shuts down.
|
||||||
css_provider = Gtk.CssProvider()
|
self.window = MainWindow(application=self, title="LibremSonic")
|
||||||
css_provider.load_from_path(
|
|
||||||
os.path.join(os.path.dirname(__file__), 'ui/app_styles.css'))
|
# Configure the CSS provider so that we can style elements on the
|
||||||
context = Gtk.StyleContext()
|
# window.
|
||||||
screen = Gdk.Screen.get_default()
|
css_provider = Gtk.CssProvider()
|
||||||
context.add_provider_for_screen(screen, css_provider,
|
css_provider.load_from_path(
|
||||||
Gtk.STYLE_PROVIDER_PRIORITY_USER)
|
os.path.join(os.path.dirname(__file__), 'ui/app_styles.css'))
|
||||||
|
context = Gtk.StyleContext()
|
||||||
|
screen = Gdk.Screen.get_default()
|
||||||
|
context.add_provider_for_screen(screen, css_provider,
|
||||||
|
Gtk.STYLE_PROVIDER_PRIORITY_USER)
|
||||||
|
|
||||||
self.window.stack.connect('notify::visible-child',
|
self.window.stack.connect('notify::visible-child',
|
||||||
self.on_stack_change)
|
self.on_stack_change)
|
||||||
@@ -163,10 +119,6 @@ class LibremsonicApp(Gtk.Application):
|
|||||||
'value-changed', self.on_volume_change)
|
'value-changed', self.on_volume_change)
|
||||||
self.window.connect('key-press-event', self.on_window_key_press)
|
self.window.connect('key-press-event', self.on_window_key_press)
|
||||||
|
|
||||||
# Display the window.
|
|
||||||
self.window.show_all()
|
|
||||||
self.window.present()
|
|
||||||
|
|
||||||
# Load the configuration and update the UI with the curent server, if
|
# Load the configuration and update the UI with the curent server, if
|
||||||
# it exists.
|
# it exists.
|
||||||
self.state.load()
|
self.state.load()
|
||||||
@@ -178,6 +130,54 @@ class LibremsonicApp(Gtk.Application):
|
|||||||
|
|
||||||
self.update_window()
|
self.update_window()
|
||||||
|
|
||||||
|
self.last_play_queue_update = 0
|
||||||
|
|
||||||
|
def time_observer(value):
|
||||||
|
self.state.song_progress = value
|
||||||
|
GLib.idle_add(
|
||||||
|
self.window.player_controls.update_scrubber,
|
||||||
|
self.state.song_progress,
|
||||||
|
self.state.current_song.duration,
|
||||||
|
)
|
||||||
|
if not value:
|
||||||
|
self.last_play_queue_update = 0
|
||||||
|
elif self.last_play_queue_update + 15 <= value:
|
||||||
|
self.save_play_queue()
|
||||||
|
|
||||||
|
def on_track_end():
|
||||||
|
GLib.idle_add(self.on_next_track)
|
||||||
|
|
||||||
|
def on_player_event(event: PlayerEvent):
|
||||||
|
if event.name == 'play_state_change':
|
||||||
|
self.state.playing = event.value
|
||||||
|
elif event.name == 'volume_change':
|
||||||
|
self.state.old_volume = self.state.volume
|
||||||
|
self.state.volume = event.value
|
||||||
|
|
||||||
|
GLib.idle_add(self.update_window)
|
||||||
|
|
||||||
|
self.mpv_player = MPVPlayer(
|
||||||
|
time_observer,
|
||||||
|
on_track_end,
|
||||||
|
on_player_event,
|
||||||
|
self.state.config,
|
||||||
|
)
|
||||||
|
self.chromecast_player = ChromecastPlayer(
|
||||||
|
time_observer,
|
||||||
|
on_track_end,
|
||||||
|
on_player_event,
|
||||||
|
self.state.config,
|
||||||
|
)
|
||||||
|
self.player = self.mpv_player
|
||||||
|
|
||||||
|
if self.state.current_device != 'this device':
|
||||||
|
# TODO figure out how to activate the chromecast if possible
|
||||||
|
# without blocking the main thread. Also, need to make it obvious
|
||||||
|
# that we are trying to connect.
|
||||||
|
pass
|
||||||
|
|
||||||
|
self.state.current_device = 'this device'
|
||||||
|
|
||||||
# ########## ACTION HANDLERS ########## #
|
# ########## ACTION HANDLERS ########## #
|
||||||
def on_configure_servers(self, action, param):
|
def on_configure_servers(self, action, param):
|
||||||
self.show_configure_servers_dialog()
|
self.show_configure_servers_dialog()
|
||||||
|
Reference in New Issue
Block a user