javascript - 在 CJS/GJS (Gnome JavaScript) 中开发 Cinnamon Shell 扩展 (Desklet) 的介绍?

标签 javascript gnome-shell gnome-shell-extensions gjs cinnamon

我开始学习如何编写 Cinnamon 扩展。好吧,我尝试......虽然我设法写了第一个simple desklet ,我还是没有找到真正好的、最新的文档和介绍。

我有以下问题,很高兴得到一些提示:

最佳/建议的开发工作流程是什么?

现在,我这样做:

  • 将更改的文件从我的项目目录复制到 .local/share/cinnamon/uuid,
  • 打开混合/镜子,
  • 在那里搜索扩展程序并通过右键单击重新加载
  • 切换到“日志”选项卡并检查是否有错误

与 vue.js 开发相比 automatic hot-reload of changes在浏览器中,这似乎有点……嗯……耗时。

在哪里可以找到可用小部件和小部件库的介绍?

我知道有 Gtk 和 St,并且都有 JS/GJS/CJS 绑定(bind)。

Gnome Dev Docu没有提到St。我读到another answer here看来 shell 扩展不使用 Gtk,而是使用 St 而不是(而不是另外使用?)。

我根本没有找到任何关于CJS的文档,但据我目前所知,它似乎与GJS非常相似。好像desklet和applet的定义方式不一样?

但现在,我仍然希望有一个(至少是简短的)介绍哪些小部件可用。在 Gtk there seems to be a whole set of different list-like widgets 时,我在 St 中没有找到任何列表小部件。看来我不能使用 Gtk 小部件作为 St 小部件的子部件......?这个St documentation缺乏对可用小部件和类及其用途的任何概述。

有关事件的文档

我发现有St.Entry widget可用于单行文本输入。我发现可以将函数绑定(bind)到按键释放事件,如下所示:

        this.input.connect('key-release-event', (widget, event) => {
            const input = widget.get_text();
            // ...
            return true; // event has been handled
        });

我未能获得有关该事件的一些信息。 使用 JSON.stringify(event) 打印时,它显示一个空对象。

这个Gtk documentation看起来应该有诸如 keyvalstate 之类的字段,但这些字段未定义。

当每一个很小的步骤都需要很长时间才能理解时,这真的有点令人沮丧......所以,我真的很感激任何提示和建议!

最佳答案

我刚刚找到https://projects.linuxmint.com/reference/git/cinnamon-tutorials/其中还包括 Cinnamon 特定的部分(但尚未研究详细信息,我将更新:-))

我添加了一些指向下面引用手册的链接。对于St,我还没有找到在线版本。但是:您可以通过 sudo apt install cinnamon-doc 离线安装一些开发文档。 This adds the Devhelp program in the Programming category of your menu and it has reference manuals for Cinnamon components and for libraries it uses.

Overview

The documentation of Cinnamon is separated into 4 different parts (5 if you count muffin). What you are currently reading is the tutorials, which includes the general top-level overviews and tutorials you will need for Cinnamon. This is named “Cinnamon Tutorials”.

The second part is the Javascript reference, which describes the Javascript part of Cinnamon. This is named the “Cinnamon Javascript Reference Manual”. This is a technical reference for the individual functions and objects available in Cinnamon. Note that this documentation is aimed at both applet/extension developers and Cinnamon developers themselves. So depending on who you are, some of the information might be entirely irrelevant.

The third part of the documentation is for the C part of Cinnamon, which is simply referred to as the “Cinnamon Reference Manual”.

The last part is the documentation for Shell toolkit, or St. This is the graphical toolkit used to draw widgets on the screen (similar to Gtk).

The modules covered by the Javascript documentation are those imported via imports.ui.* and imports.misc.*. The global object is documented in the C part of Cinnamon, as well as things accessed through imports.gi.Cinnamon. Things accessed through imports.gi.St are, unsurprisingly, documented in the St part.

imports.gi.Meta refers to Muffin, while others (eg. imports.gi.Gio) are third-party (usually GNOME) libraries that are documented elsewhere.

Accessing the documentation

There are two ways of accessing this documentation, one of which is what you are currently using. The first method is accessing it online, which will be available at http://linuxmint.github.io.

The second method is to access it locally. Install the program devhelp and the cinnamon-doc package (might be named differently in different distros or included in the cinnamon package itself). Then run the program devhelp to access all documentations you have installed in your system (not limited to Cinnamon).

同样值得一看的可能是 Linux Mint Developer Guide

CJS repo in GitHub还包括一些docsexamples (实际上是 GJS 应用程序,但仍然是灵感的来源)。

关于javascript - 在 CJS/GJS (Gnome JavaScript) 中开发 Cinnamon Shell 扩展 (Desklet) 的介绍?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69312633/

相关文章:

gnome-shell - 如何测试我的 GNOME Shell 扩展而不会有 shell 崩溃的风险?

gnome - 如何重新禁用 gnome-shell 40 中的热角?

javascript - 选择:Trigger function if no results

javascript - javascript 中的变量问题

css - 是否可以在 GNOME 3.24 中消除服务器端窗口标题栏?

gnome-shell - Gjs中Shell对象的使用

linux - CentOS 7 如何从命令行停止/启动 Gnome 桌面

javascript - 测试 Angular $emit 和 $on 事件

javascript - 单击空白区域时如何触发body.onclick

gnome - 如何在Gnome Shell扩展中为St.Icon设置PNG文件