Merge branch 'unavailable' into 'master'
Crash less when outside resources are unavailable See merge request Librem5/squeekboard!341
This commit is contained in:
@ -132,19 +132,40 @@ fn make_menu_builder(inputs: Vec<(&str, OwnedTranslation)>) -> gtk::Builder {
|
||||
)
|
||||
}
|
||||
|
||||
fn get_settings(schema_name: &str) -> Option<gio::Settings> {
|
||||
let mut error_handler = logging::Print{};
|
||||
gio::SettingsSchemaSource::get_default()
|
||||
.or_warn(
|
||||
&mut error_handler,
|
||||
logging::Problem::Surprise,
|
||||
"No gsettings schemas installed.",
|
||||
)
|
||||
.and_then(|sss|
|
||||
sss.lookup(schema_name, true)
|
||||
.or_warn(
|
||||
&mut error_handler,
|
||||
logging::Problem::Surprise,
|
||||
&format!("Gsettings schema {} not installed", schema_name),
|
||||
)
|
||||
)
|
||||
.map(|_sschema| gio::Settings::new(schema_name))
|
||||
}
|
||||
|
||||
fn set_layout(kind: String, name: String) {
|
||||
let settings = gio::Settings::new("org.gnome.desktop.input-sources");
|
||||
let inputs = settings.get_value("sources").unwrap();
|
||||
let current = (kind.clone(), name.clone());
|
||||
let inputs = variants::get_tuples(inputs).into_iter()
|
||||
.filter(|t| t != ¤t);
|
||||
let inputs = vec![(kind, name)].into_iter()
|
||||
.chain(inputs).collect();
|
||||
settings.set_value(
|
||||
"sources",
|
||||
&variants::ArrayPairString(inputs).to_variant(),
|
||||
);
|
||||
settings.apply();
|
||||
let settings = get_settings("org.gnome.desktop.input-sources");
|
||||
if let Some(settings) = settings {
|
||||
let inputs = settings.get_value("sources").unwrap();
|
||||
let current = (kind.clone(), name.clone());
|
||||
let inputs = variants::get_tuples(inputs).into_iter()
|
||||
.filter(|t| t != ¤t);
|
||||
let inputs = vec![(kind, name)].into_iter()
|
||||
.chain(inputs).collect();
|
||||
settings.set_value(
|
||||
"sources",
|
||||
&variants::ArrayPairString(inputs).to_variant(),
|
||||
);
|
||||
settings.apply();
|
||||
}
|
||||
}
|
||||
|
||||
/// A reference to what the user wants to see
|
||||
@ -284,9 +305,13 @@ pub fn show(
|
||||
let overlay_layouts = resources::get_overlays().into_iter()
|
||||
.map(|name| LayoutId::Local(name.to_string()));
|
||||
|
||||
let settings = gio::Settings::new("org.gnome.desktop.input-sources");
|
||||
let inputs = settings.get_value("sources").unwrap();
|
||||
let inputs = variants::get_tuples(inputs);
|
||||
let settings = get_settings("org.gnome.desktop.input-sources");
|
||||
let inputs = settings
|
||||
.map(|settings| {
|
||||
let inputs = settings.get_value("sources").unwrap();
|
||||
variants::get_tuples(inputs)
|
||||
})
|
||||
.unwrap_or_else(|| Vec::new());
|
||||
|
||||
let system_layouts: Vec<LayoutId> = inputs.into_iter()
|
||||
.map(|(kind, name)| LayoutId::System { kind, name })
|
||||
|
||||
@ -222,9 +222,9 @@ main (int argc, char **argv)
|
||||
error = NULL;
|
||||
connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
|
||||
if (connection == NULL) {
|
||||
g_printerr ("Can't connect to the bus: %s\n", error->message);
|
||||
g_printerr ("Can't connect to the bus: %s. "
|
||||
"Visibility switching unavailable.", error->message);
|
||||
g_error_free (error);
|
||||
exit (1);
|
||||
}
|
||||
break;
|
||||
case G_BUS_TYPE_NONE:
|
||||
@ -246,25 +246,28 @@ main (int argc, char **argv)
|
||||
g_assert_not_reached ();
|
||||
break;
|
||||
}
|
||||
guint owner_id = 0;
|
||||
DBusHandler *service = NULL;
|
||||
if (connection) {
|
||||
service = dbus_handler_new(connection, DBUS_SERVICE_PATH);
|
||||
|
||||
DBusHandler *service = dbus_handler_new(connection, DBUS_SERVICE_PATH);
|
||||
if (service == NULL) {
|
||||
g_printerr ("Can't create dbus server\n");
|
||||
exit (1);
|
||||
}
|
||||
instance.dbus_handler = service;
|
||||
|
||||
if (service == NULL) {
|
||||
g_printerr ("Can't create dbus server\n");
|
||||
exit (1);
|
||||
}
|
||||
instance.dbus_handler = service;
|
||||
|
||||
guint owner_id = g_bus_own_name_on_connection (connection,
|
||||
DBUS_SERVICE_INTERFACE,
|
||||
G_BUS_NAME_OWNER_FLAGS_NONE,
|
||||
on_name_acquired,
|
||||
on_name_lost,
|
||||
NULL,
|
||||
NULL);
|
||||
if (owner_id == 0) {
|
||||
g_printerr ("Can't own the name\n");
|
||||
exit (1);
|
||||
owner_id = g_bus_own_name_on_connection (connection,
|
||||
DBUS_SERVICE_INTERFACE,
|
||||
G_BUS_NAME_OWNER_FLAGS_NONE,
|
||||
on_name_acquired,
|
||||
on_name_lost,
|
||||
NULL,
|
||||
NULL);
|
||||
if (owner_id == 0) {
|
||||
g_printerr ("Can't own the name\n");
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
instance.submission = get_submission(instance.wayland.input_method_manager,
|
||||
@ -296,9 +299,15 @@ main (int argc, char **argv)
|
||||
|
||||
g_main_loop_run (loop);
|
||||
|
||||
g_bus_unown_name (owner_id);
|
||||
g_object_unref (service);
|
||||
g_object_unref (connection);
|
||||
if (connection) {
|
||||
if (service) {
|
||||
if (owner_id != 0) {
|
||||
g_bus_unown_name (owner_id);
|
||||
}
|
||||
g_object_unref (service);
|
||||
}
|
||||
g_object_unref (connection);
|
||||
}
|
||||
g_main_loop_unref (loop);
|
||||
|
||||
squeek_wayland_deinit (&instance.wayland);
|
||||
|
||||
Reference in New Issue
Block a user