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);
}

相关内容

热门资讯

云南省人民政府发布任职通知 云南省人民政府云政任〔2026〕20号关于陈建军同志任职的通知省农村信用社联合社:省人民政府决定:陈...
美军称发动“自卫性”空袭 ...   美军中央司令部发言人5月25日说,美军当天对伊朗南部的导弹发射阵地和布雷艇发动“自卫性”空袭。据...
40岁挑战极限,连登两座雪山当...     蒋青艳连续完成攀登珠峰(左图)、洛子峰(右图)的目标。    受访者 供图  凛冽寒风席卷珠...
长浏快线建设跑出加速度     5月26日,长浏快线永安站、金阳站有序推进墩柱、盖梁钢筋绑扎施工。土建工程预计2027年底全...
美国航空携手SpaceX,为超...   美国航空正在对机上互联体验进行重大升级。该公司于5月26日宣布,将从2027年第一季度起,在超过...