当前位置:网站首页>Cinnamon taskbar speed
Cinnamon taskbar speed
2022-07-07 13:24:00 【Haitian Eagle】
Liver for a few days , Cinnamon The network speed of the taskbar is ready , No need to compile , It's delicious !
icon.png
metadata.json
{
"uuid": "[email protected]",
"name": "CMDU",
"description": "Uptime, CPU usage, memory usage, download bytes, upload bytes, download speed, upload speed"
}
applet.js
const Applet = imports.ui.applet;
const Util = imports.misc.util;
const {GLib, Gio} = imports.gi;
const PopupMenu = imports.ui.popupMenu;
const St = imports.gi.St;
var label;
var db0 = 0, ub0 = 0, tt0=0, idle0 = 0;
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);
//global.logError('sonichy');
this.set_applet_label("↑ 0KB/s\n↓ 0KB/s");
this.menuManager = new PopupMenu.PopupMenuManager(this);
this.menu = new Applet.AppletPopupMenu(this, orientation);
this.menuManager.addMenu(this.menu);
label = new St.Label();
this.menu.addActor(label);
//https://gjs.guide/guides/gjs/asynchronous-programming.html
//GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 1, this.update); //real name function do not run
GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 1, () => {
var net = this.net();
this.set_applet_label("↑ " + this.B2G(net.ubs) + "/s\n↓ " + this.B2G(net.dbs) + "/s");
var s = _("Uptime: " + this.uptime() + "\nCPU: " + this.cpu() + "%\nMem: " + this.mem() + "\nUp: " + this.B2G(net.ub) + "\nDown: "+ this.B2G(net.db));
this.set_applet_tooltip(s); //resize flash
label.set_text(s);
return true; // loop
});
},
uptime: function() {
//https://gjs.guide/guides/gio/file-operations.html
const file = Gio.File.new_for_path('/proc/uptime');
const [, contents, etag] = file.load_contents(null);
var t = contents.toString().split(' ');
var tt = Number(t[0]);
var h = ~~(tt/3600);
var m = ~~(tt%3600/60);
if (m < 10)
m = '0' + m;
var s = ~~(tt%3600%60);
if (s < 10)
s = '0' + s;
var hms = h + ':' + m + ':' + s;
return hms;
},
cpu: function() {
const file = Gio.File.new_for_path('/proc/stat');
const [, contents, etag] = file.load_contents(null);
var s = contents.toString().split('\n');
var ca = s[0].split(/\s+/);
var tt = 0;
for (var i=1; i<ca.length; i++) {
tt += Number(ca[i]);
}
global.log(tt);
var idle = Number(ca[4]);
var p = ~~(((tt - tt0) - (idle - idle0)) * 100 / (tt - tt0));
tt0 = tt;
idle0 = idle;
return p;
},
mem: function() {
const file = Gio.File.new_for_path('/proc/meminfo');
const [, contents, etag] = file.load_contents(null);
var s = contents.toString().split('\n');
var MT = s[0].split(/\s+/);
var MF = s[1].split(/\s+/);
var mt = Number(MT[1]);
var mf = Number(MF[1]);
var mu = mt - mf;
var p = ~~(mu / mt * 100);
var m = this.B2G(mu*1024) + ' / '+ this.B2G(mt*1024) + ' = ' + p + '%';
return m;
},
net: function() {
const file = Gio.File.new_for_path('/proc/net/dev');
const [, contents, etag] = file.load_contents(null);
var l = contents.toString().trim().split('\n');
var db = 0, ub = 0;
for (var i=2; i<l.length; i++) {
var la = l[i].trim().split(/\s+/);
db += Number(la[1]);
ub += Number(la[9]);
}
var dbs = db - db0;
var ubs = ub - ub0;
db0 = db;
ub0 = ub;
return {db, ub, dbs, ubs};
},
B2G: function(b) {
var s = '';
if (b > 999999999)
s = (b / 1073741824).toFixed(2) + ' GB';
else{
if (b > 999999)
s = (b / 1048576).toFixed(2) + ' MB';
else{
if (b > 999)
s = ~~(b / 1024) + ' KB';
else
s = b + ' B';
}
}
return s;
},
update: function() {
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);
return true; // loop
},
on_applet_clicked: function() {
//Util.spawnCommandLine("gnome-system-monitor");
this.menu.toggle();
}
};
function main(metadata, orientation, panel_height, instance_id) {
return new MyApplet(orientation, panel_height, instance_id);
}
边栏推荐
- Clion mingw64 Chinese garbled code
- JS缓动动画原理教学(超细节)
- 存储过程的介绍与基本使用
- MongoDB内部的存储原理
- Storage principle inside mongodb
- [dark horse morning post] Huawei refutes rumors about "military master" Chen Chunhua; Hengchi 5 has a pre-sale price of 179000 yuan; Jay Chou's new album MV has played more than 100 million in 3 hours
- 分布式事务解决方案
- [QNX hypervisor 2.2 user manual]6.3.4 virtual register (guest_shm.h)
- 靠卖概念上市,认养一头牛能走多远?
- 提升树莓派性能的方法
猜你喜欢
随机推荐
Summary of import, export, backup and recovery of mongodb
10 张图打开 CPU 缓存一致性的大门
一文读懂数仓中的pg_stat
RecyclerView的数据刷新
飞桨EasyDL实操范例:工业零件划痕自动识别
Introduction and basic use of stored procedures
Read PG in data warehouse in one article_ stat
Cinnamon Applet 入门
Mongodb slice summary
靠卖概念上市,认养一头牛能走多远?
Conversion from non partitioned table to partitioned table and precautions
记一次 .NET 某新能源系统 线程疯涨 分析
1、深拷贝 2、call apply bind 3、for of for in 区别
共创软硬件协同生态:Graphcore IPU与百度飞桨的“联合提交”亮相MLPerf
cmake 学习使用笔记(一)
如何让join跑得更快?
MongoDB的导入导出、备份恢复总结
Why can basic data types call methods in JS
迅为iTOP-IMX6ULL开发板Pinctrl和GPIO子系统实验-修改设备树文件
Write it down once Net a new energy system thread surge analysis