Skip to content

Instantly share code, notes, and snippets.

@saivert
Last active July 4, 2023 17:31
Show Gist options
  • Save saivert/bfd5740d710021cc992f58eda96a2f4c to your computer and use it in GitHub Desktop.
Save saivert/bfd5740d710021cc992f58eda96a2f4c to your computer and use it in GitHub Desktop.
// First some setup code
pub struct PwvucontrolApplication {
pub(crate) window: OnceCell<PwvucontrolWindow>,
}
impl ApplicationImpl for PwvucontrolApplication {
fn activate(&self) {
let window = self
.window
.get()
.expect("Should always be initialized in gio_application_startup");
// Ask the window manager/compositor to present the window
window.present();
self.setup_wp_connection();
}
fn startup(&self) {
self.parent_startup();
let window = PwvucontrolWindow::new(&self.obj());
self.window
.set(window)
.expect("Failed to initialize application window");
}
}
// Now the part that breaks
impl PwvucontrolApplication {
fn setup_wp_connection(&self) {
wp::core::Core::init();
wireplumber::Log::set_default_level("3");
let props = wp::pw::Properties::new_string("media.category=Manager");
let wp_core = wp::core::Core::new(Some(&glib::MainContext::default()), Some(props));
let wp_om = wp::registry::ObjectManager::new();
wp_core.connect_local("connected", false, |_obj| {
let app = PwvucontrolApplication::default();
let win = app.window.get().expect("window"); // PANICS HERE!
win.imp().viewstack.set_visible_child_name("connected");
None
});
}
// For reference the default impl:
impl Default for PwvucontrolApplication {
fn default() -> Self {
gio::Application::default()
.expect("Could not get default GApplication")
.downcast()
.unwrap()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment