AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-1063859

pablomd's questions

Martin Hope
pablomd
Asked: 2020-07-22 15:40:23 +0800 CST

关闭盖子时禁止睡眠的 JS 脚本不起作用。文件描述符管理问题还是其他?

  • 0

我正在尝试为 gnome 开发一个扩展,它允许我在直接从状态栏关闭盖子时禁止系统睡眠,而无需打开调整。

到目前为止,我有一个基本的 js 脚本,它成功连接到 gdbus 并能够执行命令,但我无法让抑制剂工作。我相信问题是我没有处理禁止函数以正确方式返回的文件描述符,因为文档说只有在文件描述符被引用和打开时,抑制剂才保留在原位。但也有可能我没有正确调用该函数。

如果有人能给我一些建议,我将非常感激。我正在运行 Ubuntu 18.04.4 和 gnome 3.28.2

/* -*- mode: js2 - indent-tabs-mode: nil - js2-basic-offset: 4 -*- */
/*jshint multistr:true */
/*jshint esnext:true */
/*global imports: true */
/*global global: true */
/*global log: true */
'use strict';

const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Mainloop = imports.mainloop;
const Atk = imports.gi.Atk;


const DBusInterface = '<node>\
  <interface name="org.freedesktop.login1.Manager">\
    <method name="Inhibit">\
        <arg type="s" direction="in" />\
        <arg type="s" direction="in" />\
        <arg type="s" direction="in" />\
        <arg type="s" direction="in" />\
        <arg type="h" direction="out" />\
    </method>\
    <method name="ListInhibitors">\
      <arg type="a(ssssuu)" direction="out" />\
  </method>\
  </interface>\
</node>';

const DBusProxy = Gio.DBusProxy.makeProxyWrapper(DBusInterface);
let proxy = new DBusProxy(
    Gio.DBus.system,
    "org.freedesktop.login1",
    "/org/freedesktop/login1"
);

let inhibitors = proxy.ListInhibitorsSync();
print(inhibitors);


let fd = proxy.InhibitSync('handle-lid-switch',
                          'gnome-extension-lid-inhibitor',
                          'user preference',
                          'block');

inhibitors = proxy.ListInhibitorsSync();
print(inhibitors);

let loop = new GLib.MainLoop(null, false);
loop.run();
power-management gnome laptop gnome-shell-extension lid
  • 1 个回答
  • 63 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve