文档:
https://projects.linuxmint.com/reference/git/cinnamon-tutorials/write-applet.html
Cinnamon Applet 路径:
系统:/usr/share/cinnamon/applets
用户:~/.local/share/cinnamon/applets
Cinnamon Applet 调试:
打开命令窗口:Alt + F2,输入 lg,Log 标签查看错误。
1.创建文件夹 project@author
2.新建 icon.png
3.新建 metadata.json
{
"uuid": "CMDU@sonichy",
"name": "CMDU",
"description": "Uptime, CPU usage, memory usage, download bytes, upload bytes, download speed, upload speed",
"icon": "force-exit"
}
4.新建 applet.js
const Applet = imports.ui.applet;
const Util = imports.misc.util;
const {GLib, Gio} = imports.gi;
function MyApplet(orientation, panel_height, instance_id) {
this._init(orientation, panel_height, instance_id);
}
MyApplet.prototype = {
__proto__: Applet.TextApplet.prototype,
_init: function(orientation, panel_height, instance_id) {
Applet.TextApplet.prototype._init.call(this, orientation, panel_height, instance_id);
this.set_applet_label("↑ 0KB/s\n↓ 0KB/s");
this.set_applet_tooltip(_("Uptime:\nCPU:\nMem:\nUp:\nDown:"));
//https://gjs.guide/guides/gjs/asynchronous-programming.html
GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 1, () => {
var date = new Date();
var s = date.getFullYear() + "/" + (date.getMonth()+1) + "/" + date.getDate() + "\n" + date.getHours() + ":" + date.getMinutes()+ ":" + date.getSeconds();
this.set_applet_label(s);
this.set_applet_tooltip(_("Uptime: " + this.uptime() + "\nCPU:\nMem:\nUp:\nDown:"));
return true; // loop
});
},
on_applet_clicked: function() {
Util.spawnCommandLine("gnome-system-monitor");
}
};
function main(metadata, orientation, panel_height, instance_id) {
return new MyApplet(orientation, panel_height, instance_id);
}
5.任务栏右键 - 疑难解决 - 重启 Cinnamon
优点:无需编译。