-
Notifications
You must be signed in to change notification settings - Fork 0
/
tray.tis
73 lines (66 loc) · 3.05 KB
/
tray.tis
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
//| Sciter Tray Menu v4.0.0
//| https://github.com/MustafaHi/Sciter-Tray
// var Tray.menu = undefined; Give it a View window or Element to use as menu.
// var Tray.center = true; True to center the menu to the TrayIcon.
// self.url is not relative if this is inside a folder you must name the folder self.url("folder/tray.htm")
const Tray = {
center: true,
menu : undefined,
init : function(init = true, content = "Welcome!", icon = "trayicon.png") {
if (init) {
view.trayIcon {
image: self.loadImage(self.url(icon)),
text: content
};
} else {
view.trayIcon(#remove);
}
}
}
view << event trayicon-click(evt) {
// if the main app window not showing on top add view.windowTopmost = true; then view.windowTopmost = false;
if (evt.buttons == 1) { view.state = View.WINDOW_SHOWN; view.focus = self; view.windowTopmost = true; view.windowTopmost = false; }
else {
if (Tray.menu?.isElement) {
Tray.menu.focus = self;
var (tx,ty) = view.trayIcon(#place);
var (sx,sy) = view.box(#position,#client,#screen);
self.popup(Tray.menu, (Tray.center ? 2 : 1), tx - sx, ty - sy);
}
else {
if (Tray.menu == undefined)
Tray.menu = View.all.find(:v: v.id == "traymenu");
if (Tray.menu == undefined) {
Tray.menu = view.window{
url : self.url("tray.htm"),
state: View.WINDOW_HIDDEN,
type : View.POPUP_WINDOW,
};
Tray.menu.id = "traymenu";
}
var x, y;
var (w,h) = Tray.menu.box(#dimension);
// var w = Tray.menu.root.intrinsicWidthMax();
// var h = Tray.menu.root.intrinsicHeight();
var (tx,ty,tw,th) = view.trayIcon(#place);
var (sX1,sY1,sX2,sY2) = view.screenBox(#workarea, #rect);
if (Tray.center) {
tx < sX1 ? x = sX1 : (tx > sX2 ? x = (sX2 - w) : x = (tx-(w/2))+(tw/2));
ty < (sY1*4) ? y = (ty + th) : (ty > sY2 ? y = (sY2 - h) : y = ty-h);
tx < sX1 || tx - sX2 > 0 ? y += (h/2) : "";
} else {
tx < (sX1*4) ? x = tx : (tx > sX2 ? x = (sX2 - w) : x = tx);
ty < (sY1*4) ? y = (ty + th) : (ty > sY2 ? y = (sY2 - h) : y = ty-h);
}
Tray.menu.move(x.limit(0, sX2-w), y.limit(0, sY2-h), w, h, true);
Tray.menu.state = View.WINDOW_SHOWN;
Tray.menu.windowTopmost = true;
Tray.menu.focus = self;
// Functions for tray.htm
Tray.menu.root.on("click", "#show", () => { view.state = View.WINDOW_SHOWN; });
Tray.menu.root.on("click", "#hide", () => { view.state = View.WINDOW_HIDDEN; });
Tray.menu.root.on("click", "#exit", () => { Tray.menu.close(); view.close(); });
Tray.menu.on("activate", (as) => { if (as === false) Tray.menu.state = View.WINDOW_HIDDEN; });
}
}
}