refactor(ags systray): use subclass
This commit is contained in:
parent
5a66324c35
commit
43cf2ec543
1 changed files with 34 additions and 41 deletions
|
@ -1,8 +1,6 @@
|
||||||
import SystemTray from 'resource:///com/github/Aylur/ags/service/systemtray.js';
|
import SystemTray from 'resource:///com/github/Aylur/ags/service/systemtray.js';
|
||||||
import { timeout } from 'resource:///com/github/Aylur/ags/utils.js';
|
import { timeout } from 'resource:///com/github/Aylur/ags/utils.js';
|
||||||
import { Box, Icon, MenuItem, Revealer } from 'resource:///com/github/Aylur/ags/widget.js';
|
import { Box, Icon, MenuItem, MenuBar, Revealer } from 'resource:///com/github/Aylur/ags/widget.js';
|
||||||
|
|
||||||
import Gtk from 'gi://Gtk';
|
|
||||||
|
|
||||||
import Separator from '../misc/separator.js';
|
import Separator from '../misc/separator.js';
|
||||||
|
|
||||||
|
@ -16,25 +14,21 @@ const SysTrayItem = item => {
|
||||||
transition: 'slide_right',
|
transition: 'slide_right',
|
||||||
child: Icon({
|
child: Icon({
|
||||||
size: 24,
|
size: 24,
|
||||||
|
binds: [['icon', item, 'icon']],
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
submenu: item.menu,
|
submenu: item.menu,
|
||||||
connections: [[item, btn => {
|
binds: [['tooltipMarkup', item, 'tooltip-markup']],
|
||||||
btn.child.child.icon = item.icon;
|
|
||||||
btn.tooltipMarkup = item.tooltipMarkup;
|
|
||||||
}]],
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const SysTray = () => {
|
const SysTray = () => MenuBar({
|
||||||
const widget = Gtk.MenuBar.new();
|
setup: self => {
|
||||||
|
self.items = new Map();
|
||||||
|
|
||||||
// Properties
|
self.onAdded = id => {
|
||||||
widget._items = new Map();
|
|
||||||
|
|
||||||
widget._onAdded = id => {
|
|
||||||
const item = SystemTray.getItem(id);
|
const item = SystemTray.getItem(id);
|
||||||
if (widget._items.has(id) || !item)
|
if (self.items.has(id) || !item)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const w = SysTrayItem(item);
|
const w = SysTrayItem(item);
|
||||||
|
@ -42,29 +36,28 @@ const SysTray = () => {
|
||||||
if (!w)
|
if (!w)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
widget._items.set(id, w);
|
self.items.set(id, w);
|
||||||
widget.add(w);
|
self.add(w);
|
||||||
widget.show_all();
|
self.show_all();
|
||||||
w.child.revealChild = true;
|
w.child.revealChild = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
widget._onRemoved = id => {
|
self.onRemoved = id => {
|
||||||
if (!widget._items.has(id))
|
if (!self.items.has(id))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
widget._items.get(id).child.revealChild = false;
|
self.items.get(id).child.revealChild = false;
|
||||||
timeout(400, () => {
|
timeout(400, () => {
|
||||||
widget._items.get(id).destroy();
|
self.items.get(id).destroy();
|
||||||
widget._items.delete(id);
|
self.items.delete(id);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
},
|
||||||
// Connections
|
connections: [
|
||||||
SystemTray.connect('added', (_, id) => widget._onAdded(id));
|
[SystemTray, (self, id) => self.onAdded(id), 'added'],
|
||||||
SystemTray.connect('removed', (_, id) => widget._onRemoved(id));
|
[SystemTray, (self, id) => self.onRemoved(id), 'removed'],
|
||||||
|
],
|
||||||
return widget;
|
});
|
||||||
};
|
|
||||||
|
|
||||||
export default () => Revealer({
|
export default () => Revealer({
|
||||||
transition: 'slide_right',
|
transition: 'slide_right',
|
||||||
|
|
Loading…
Reference in a new issue