简体   繁体   English

Gnome Extensions - 运行shell命令

[英]Gnome Extensions - Run shell command

I am writing a simple extension to open browser by clicking the extension button. 我正在编写一个简单的扩展来打开浏览器,单击扩展按钮。 I would like to know if there is a function which can execute passed shell command as argument. 我想知道是否有一个函数可以执行传递的shell命令作为参数。 Also, it'd be really helpful if anyone can suggest a good simple reference for extension development. 此外,如果任何人都可以为扩展开发提出一个很好的简单参考,那将非常有用。

From https://github.com/GNOME/gnome-shell/blob/master/js/misc/util.js : 来自https://github.com/GNOME/gnome-shell/blob/master/js/misc/util.js

// Runs @command_line in the background, handling any errors that
// occur when trying to parse or start the program.
function spawnCommandLine(command_line) {
    try {
        let [success, argv] = GLib.shell_parse_argv(command_line);
        trySpawn(argv);
    } catch (err) {
        _handleSpawnError(command_line, err);
    }
}

There are a few variations on that method in there. 那里的方法有一些变化。 Save yourself mountains of headaches and just bookmark the GitHub repository. 保存自己的头痛,只需将GitHub存储库添加为书签。

Some quick links: 一些快速链接:

  • popupMenu.js : working with popup menus popupMenu.js :使用弹出菜单
  • panel.js : a good read for implementing "tray" icons panel.js :实现“托盘”图标的好读物
  • modalDialog.js : some UI elements were made to be reused, runDialog.js uses this for example modalDialog.js :一些UI元素被重用,runDialog.js使用它作为例子
  • mpris.js : there are also good examples of using frameworks like DBus in gjs mpris.js :在gjs中也有使用像DBus这样的框架的好例子

I can't stress enough how much you'll get out of reading the gnome-shell source. 我不能强调你读取gnome-shell源代码的余量。 Unfortunately, it's compiled into a resource file now so we don't have local copies to stumble upon. 不幸的是,它现在被编译成一个资源文件,所以我们没有本地副本偶然发现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM