Cinnamon Applet 入门

文档:
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

 优点:无需编译。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值