无法使用GSettings更改dconf-entry [英] Can't change dconf-entry with GSettings

查看:168
本文介绍了无法使用GSettings更改dconf-entry的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在 Gjs 上构建一个简单的应用程序,它应该改变我的背景图像GNOME的外壳。可以找到使用 gsettings -tool完成此操作的解决方案这里

I'm currently building a simple application on Gjs, which should change the background-image of my gnome-shell. A solution on how this can be done using the gsettings-tool can be found here.

由于我想围绕它构建桌面应用程序,我想要更改 org.gnome.desktop.background.picture-uri -key使用Gio的 GSettings -class 。但是使用 set_X() -method不会改变密钥的值。

Since I want to build a desktop-application around it, I want to change the org.gnome.desktop.background.picture-uri-key by using Gio's GSettings-class. But using the set_X()-method does not change the value of the key.

这是我的代码更改gsettings值:

This is my code to change the gsettings value:

var gio = imports.gi.Gio;

// Get the GSettings-object for the background-schema:
var background = new gio.Settings({schema: "org.gnome.desktop.background"});

// Read the current Background-Image:
print( "Current Background-Image: "+background.get_string("picture-uri") );

if (background.is_writable("picture-uri")){
    // Set a new Background-Image (should show up immediately):
    if (background.set_string("picture-uri", "file:///path/to/some/pic.jpg")){
        print("Success!");
    }
    else throw "Couldn't set the key!";
} else throw "The key is not writable";

读取值确实按预期工作, is_writable() -method返回 true set_string() -method也返回 true

Reading the value does work as expected, the is_writable()-method returns true and the set_string()-method also returns true.

我已经检查过我没有处于延迟应用模式,并且密钥有 GVariantType 字符串,所以 set_string() -method应该有用。

I have checked that I'm not in "delay-apply" mode and the key has a GVariantType of string, so the set_string()-method should work.

使用正常 gsettings 命令行工具(如链接帖子中所述)工作正常。

Using the normal gsettings command-line tool (as explained in the linked post) works just fine.

我不能找出问题所在,有什么地方可以查找日志或其他东西吗?

I can't figure out what the problem is, is there any place I can look for logs or something?

推荐答案

此处未收到任何回复我在gjs-mailing列表上问了同样的问题

After not getting any responses here I asked the same question on the gjs-mailing list.

事实证明,当我的脚本退出时,对dconf的写入还没有在磁盘上,因此它们从未真正应用过。

It turned out that the writes to dconf were not yet on the disk when my script exited, so they were never really applied.

解决方案是调用 g_settings_sync()功能 JsDoc )紧跟在 set_string()函数之后,以确保所有写入都已完成。

The solution was to call the g_settings_sync() function (JsDoc) right after the set_string() function, to ensure that all writes had finished.

if (background.set_string("picture-uri", "file:///path/to/some/pic.jpg")){
    gio.Settings.sync()
    print("Success!");
}

感谢Johan Dahlin和他的回答

Thanks to Johan Dahlin and his answer.

这篇关于无法使用GSettings更改dconf-entry的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆