[email protected] 2.新建 ic...">

当前位置:网站首页>Cinnamon Applet 入门

Cinnamon Applet 入门

2022-07-07 11:09:00 海天鹰

文档:
https://projects.linuxmint.com/reference/git/cinnamon-tutorials/write-applet.html

Cinnamon Applet 路径:

系统:/usr/share/cinnamon/applets

用户:~/.local/share/cinnamon/applets

1.创建文件夹 [email protected]

2.新建 icon.png

3.新建 metadata.json

{
    "uuid": "[email protected]",
    "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

 优点:无需编译。

原网站

版权声明
本文为[海天鹰]所创,转载请带上原文链接,感谢
https://blog.csdn.net/sonichty/article/details/125628138