-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdesklet.js
executable file
·135 lines (116 loc) · 3.08 KB
/
desklet.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
const Cinnamon = imports.gi.Cinnamon;
const Desklet = imports.ui.desklet;
const GLib = imports.gi.GLib;
const Settings = imports.ui.settings;
const St = imports.gi.St;
const uuid = "sticker@KaitWang";
const Gettext = imports.gettext;
function _(str) {
return Gettext.dgettext(uuid, str);
}
Gettext.bindtextdomain(uuid, GLib.get_home_dir() + "/.local/share/locale");
function sticker(metadata, desklet_id) {
this._init(metadata, desklet_id);
}
sticker.prototype = {
__proto__: Desklet.Desklet.prototype,
_init: function (metadata, desklet_id) {
Desklet.Desklet.prototype._init.call(this, metadata, desklet_id);
this._note = new St.Label({ style_class: "note-container" });
this.setContent(this._note);
this.setHeader(_("Desktop Note"));
this.maxSize = 7000; // Cinnamon can crash if this int is too high
this.setupUI();
try {
this.settings = new Settings.DeskletSettings(
this,
this.metadata["uuid"],
desklet_id,
);
this.settings.bindProperty(
Settings.BindingDirection.IN,
"note-entry",
"noteEntry",
this.on_setting_changed,
null,
);
this.settings.bindProperty(
Settings.BindingDirection.IN,
"font-size",
"fontSize",
this.on_font_setting_changed,
null,
);
this.settings.bindProperty(
Settings.BindingDirection.IN,
"text-color",
"fontColor",
this.on_font_setting_changed,
null,
);
this.settings.bindProperty(
Settings.BindingDirection.IN,
"bg-color",
"bgColor",
this.on_font_setting_changed,
null,
);
this.settings.bindProperty(
Settings.BindingDirection.IN,
"pending-size",
"pendingSize",
this.on_font_setting_changed,
null,
);
this.settings.bindProperty(
Settings.BindingDirection.IN,
"text-align",
"textAlign",
this.on_font_setting_changed,
null,
);
} catch (e) {
global.logError(e);
}
this.on_setting_changed();
this.on_font_setting_changed();
},
on_setting_changed: function () {
var new_text = this.noteEntry;
this.text.set_text(new_text);
},
on_font_setting_changed: function () {
this.text.style = "margin: " + this.pendingSize + "px;\n";
this._note.style =
"font-size: " +
this.fontSize +
"px;\n" +
"color: " +
this.fontColor +
";\n" +
"background: " +
this.bgColor +
";\n" +
"text-align: " +
this.textAlign +
";\n";
},
setupUI: function () {
// main container for the desklet
this.window = new St.Bin({
style: "background: rgba(0,0,0,0);",
});
this.text = new St.Label();
this.text.set_text("");
this._note = new St.BoxLayout({
vertical: true,
style_class: "note-container",
});
this._note.add(this.text);
this.window.add_actor(this._note);
this.setContent(this.window);
},
};
function main(metadata, desklet_id) {
return new sticker(metadata, desklet_id);
}