Skip to content
This repository was archived by the owner on Mar 4, 2024. It is now read-only.

Commit a29bdf8

Browse files
committed
gtk: application: Use startup signal to log rt startup
The GtkApplication itself will call gtk_init() so we shouldn't call `rt::init()` here, instead we should hang off the startup signal and log the initialisation. Signed-off-by: Daniel Silverstone <[email protected]>
1 parent 6874609 commit a29bdf8

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

src/application.rs

+30-4
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,49 @@
1+
use gio::ApplicationExt;
12
use gio::ApplicationFlags;
23
use glib;
4+
use glib::signal::SignalHandlerId;
35
use glib::translate::*;
6+
use glib::ObjectExt;
47
use gtk_sys;
58
use rt;
69
use Application;
710

11+
use std::cell::RefCell;
12+
use std::rc::Rc;
13+
814
impl Application {
15+
pub(crate) fn register_startup_hook(app: &Application) {
16+
skip_assert_initialized!();
17+
let signalid: Rc<RefCell<Option<SignalHandlerId>>> = Rc::new(RefCell::new(None));
18+
{
19+
let signalid_ = signalid.clone();
20+
21+
let id = app.connect_startup(move |app| {
22+
app.disconnect(
23+
signalid_
24+
.borrow_mut()
25+
.take()
26+
.expect("Signal ID went missing"),
27+
);
28+
unsafe { rt::set_initialized() }
29+
});
30+
*signalid.borrow_mut() = Some(id);
31+
}
32+
}
33+
934
pub fn new(
1035
application_id: Option<&str>,
1136
flags: ApplicationFlags,
1237
) -> Result<Application, glib::BoolError> {
1338
skip_assert_initialized!();
14-
try!(rt::init());
15-
unsafe {
39+
let app: Application = unsafe {
1640
Option::from_glib_full(gtk_sys::gtk_application_new(
1741
application_id.to_glib_none().0,
1842
flags.to_glib(),
1943
))
20-
.ok_or_else(|| glib_bool_error!("Failed to create application"))
21-
}
44+
.ok_or_else(|| glib_bool_error!("Failed to create application"))?
45+
};
46+
Application::register_startup_hook(&app);
47+
Ok(app)
2248
}
2349
}

0 commit comments

Comments
 (0)