Cinnamon Applet 设置
创始人
2024-06-01 14:06:37

Cinnamon Applet 入门_海天鹰的博客-CSDN博客

进一步如何保存文本到提示文字呢?

1.设置界面 settings-schema.json (固定名称)

{    "memo" : {"type" : "textview","default" : "","description" : "Memo","tooltip" : "Set your memo here."}
}

2.在 applet.js 中绑定设置

this.settings = new Settings.AppletSettings(this, "datetime@sonichy", this.instance_id);
this.settings.bind("memo", "memo", null);

小程序 - 右键 - 配置,弹出窗口:

修改后关闭自动保存,小程序会自动读取。

效果图:

完整的 applet.js:

const Applet = imports.ui.applet;
const Settings = imports.ui.settings;
const PopupMenu = imports.ui.popupMenu;
const St = imports.gi.St;
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.settings = new Settings.AppletSettings(this, "datetime@sonichy", this.instance_id);this.settings.bind("memo", "memo", null);this.set_applet_label("00:00\n1/1 一");this._applet_label.set_style("text-align:center");this.set_applet_tooltip(_("Tooltip"));this._applet_tooltip._tooltip.set_style("text-align:left");this.menuManager = new PopupMenu.PopupMenuManager(this);        this.menu = new Applet.AppletPopupMenu(this, orientation);this.menuManager.addMenu(this.menu);var label = new St.Label();this.menu.addActor(label);        //https://gjs.guide/guides/gjs/asynchronous-programming.html                  GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 1, () => {            var date = new Date();var h = date.getHours();if (h < 10)h = "0" + h;var m = date.getMinutes();if (m < 10)m = "0" + m;var s = date.getSeconds();if (s < 10)s = "0" + s;var m1 = (date.getMonth()+1);var day = date.getDay();var weekday = ["日", "一", "二", "三", "四", "五", "六"];var s1 = h + ":" + m + "\n" + m1 + "/" + date.getDate() + " " + weekday[day];this.set_applet_label(s1);s1 = date.getFullYear() + "/" + m1 + "/" + date.getDate() + " " + h + ":" + m + ":" + s + "\n" + this.memo;this.set_applet_tooltip(s1);label.set_text(s1);return true; // loop});   	},on_applet_clicked: function() {this.menu.toggle();}};function main(metadata, orientation, panel_height, instance_id) {return new MyApplet(orientation, panel_height, instance_id);
}

相关内容

热门资讯

投资者提问:请问董秘,当前中日... 投资者提问:请问董秘,当前中日关系陷入僵局乃至谷底之际,公司有规划更多使用国产光刻胶等材料来替代日系...
富德生命人寿咸阳中心支公司被罚... 12月16日金融一线消息,据咸阳金融监管分局行政处罚信息公开表显示,富德生命人寿保险股份有限公司咸阳...
市场监管总局:抓紧推进出台《互... 转自:北京日报客户端记者16日从市场监管总局获悉,市场监管总局正抓紧推进《互联网平台反垄断合规指引》...
天奇股份:锂电循环业务夯实产业... 12月16日,江西天奇金泰阁集团(简称“天奇金泰阁”)资本赋能发展大会在江西龙南举行。会上,天奇股份...
「侠客岛」他们用上了“AI分身...   炒股就看金麒麟分析师研报,权威,专业,及时,全面,助您挖掘潜力主题机会! (来源:海外网)来源...