2023-11-21 01:29:46 -05:00
|
|
|
import App from 'resource:///com/github/Aylur/ags/app.js';
|
2023-10-31 08:32:40 -04:00
|
|
|
import Applications from 'resource:///com/github/Aylur/ags/service/applications.js';
|
2023-11-13 13:19:14 -05:00
|
|
|
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
|
2023-10-31 08:32:40 -04:00
|
|
|
|
2023-11-13 15:19:49 -05:00
|
|
|
import { Box, Entry, Icon, Label, Scrollable } from 'resource:///com/github/Aylur/ags/widget.js';
|
2023-09-29 03:36:48 -04:00
|
|
|
|
2023-10-17 13:47:02 -04:00
|
|
|
import PopupWindow from '../misc/popup.js';
|
2023-11-13 15:19:49 -05:00
|
|
|
import Separator from '../misc/separator.js';
|
|
|
|
import AppItem from './app-item.js';
|
2023-09-29 03:36:48 -04:00
|
|
|
|
|
|
|
|
2023-11-13 15:19:49 -05:00
|
|
|
const Applauncher = ({ window_name = 'applauncher' } = {}) => {
|
2023-11-21 01:29:46 -05:00
|
|
|
const ICON_SEPARATION = 4;
|
|
|
|
|
2023-11-13 15:19:49 -05:00
|
|
|
const children = () => [
|
2023-11-21 01:29:46 -05:00
|
|
|
...Applications.query('').flatMap((app) => {
|
2023-11-13 15:19:49 -05:00
|
|
|
const item = AppItem(app);
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-13 15:19:49 -05:00
|
|
|
return [
|
2023-11-21 01:29:46 -05:00
|
|
|
Separator(ICON_SEPARATION, {
|
2023-11-13 15:19:49 -05:00
|
|
|
binds: [['visible', item, 'visible']],
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
2023-11-13 15:19:49 -05:00
|
|
|
item,
|
|
|
|
];
|
2023-09-29 03:36:48 -04:00
|
|
|
}),
|
2023-11-21 01:29:46 -05:00
|
|
|
Separator(ICON_SEPARATION),
|
2023-11-13 15:19:49 -05:00
|
|
|
];
|
2023-09-29 03:36:48 -04:00
|
|
|
|
2023-11-13 15:19:49 -05:00
|
|
|
const list = Box({
|
|
|
|
vertical: true,
|
|
|
|
children: children(),
|
2023-10-20 23:11:21 -04:00
|
|
|
});
|
2023-11-13 15:19:49 -05:00
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
const placeholder = Label({
|
|
|
|
label: " Couldn't find a match",
|
|
|
|
className: 'placeholder',
|
|
|
|
});
|
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
const entry = Entry({
|
2023-11-21 01:29:46 -05:00
|
|
|
// Set some text so on-change works the first time
|
|
|
|
text: '-',
|
2023-10-20 23:11:21 -04:00
|
|
|
hexpand: true,
|
2023-11-13 15:19:49 -05:00
|
|
|
|
|
|
|
on_accept: ({ text }) => {
|
2023-11-21 01:29:46 -05:00
|
|
|
const appList = Applications.query(text || '');
|
|
|
|
|
|
|
|
if (appList[0]) {
|
2023-11-13 15:19:49 -05:00
|
|
|
App.toggleWindow(window_name);
|
2023-11-21 01:29:46 -05:00
|
|
|
Hyprland.sendMessage(`dispatch exec sh -c ${appList[0]}`);
|
|
|
|
++appList[0].frequency;
|
2023-10-20 23:11:21 -04:00
|
|
|
}
|
|
|
|
},
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-13 15:19:49 -05:00
|
|
|
on_change: ({ text }) => {
|
|
|
|
let visibleApps = 0;
|
2023-11-21 01:29:46 -05:00
|
|
|
|
|
|
|
list.children.forEach((item) => {
|
2023-11-13 15:19:49 -05:00
|
|
|
if (item.app) {
|
|
|
|
item.visible = item.app.match(text);
|
2023-09-29 03:36:48 -04:00
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
if (item.app.match(text)) {
|
2023-11-13 15:19:49 -05:00
|
|
|
++visibleApps;
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
2023-11-13 15:19:49 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
placeholder.visible = visibleApps <= 0;
|
2023-10-20 23:11:21 -04:00
|
|
|
},
|
|
|
|
});
|
2023-09-29 03:36:48 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
return Box({
|
|
|
|
className: 'applauncher',
|
|
|
|
vertical: true,
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-09-29 03:36:48 -04:00
|
|
|
children: [
|
2023-10-20 23:11:21 -04:00
|
|
|
Box({
|
|
|
|
className: 'header',
|
|
|
|
children: [
|
2023-11-13 15:19:49 -05:00
|
|
|
Icon('preferences-system-search-symbolic'),
|
2023-10-20 23:11:21 -04:00
|
|
|
entry,
|
|
|
|
],
|
|
|
|
}),
|
2023-11-13 15:19:49 -05:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
Scrollable({
|
|
|
|
hscroll: 'never',
|
|
|
|
child: Box({
|
|
|
|
vertical: true,
|
|
|
|
children: [list, placeholder],
|
|
|
|
}),
|
|
|
|
}),
|
2023-09-29 03:36:48 -04:00
|
|
|
],
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-13 15:19:49 -05:00
|
|
|
connections: [[App, (_, name, visible) => {
|
2023-11-21 01:29:46 -05:00
|
|
|
if (name !== window_name) {
|
2023-10-20 23:11:21 -04:00
|
|
|
return;
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
2023-09-29 03:36:48 -04:00
|
|
|
|
2023-11-13 15:19:49 -05:00
|
|
|
entry.text = '';
|
2023-11-21 01:29:46 -05:00
|
|
|
|
|
|
|
if (visible) {
|
2023-10-20 23:11:21 -04:00
|
|
|
entry.grab_focus();
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
|
|
|
else {
|
2023-11-13 15:19:49 -05:00
|
|
|
list.children = children();
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
2023-10-20 23:11:21 -04:00
|
|
|
}]],
|
|
|
|
});
|
2023-09-29 03:36:48 -04:00
|
|
|
};
|
|
|
|
|
2023-10-16 18:11:19 -04:00
|
|
|
export default () => PopupWindow({
|
2023-10-20 23:11:21 -04:00
|
|
|
name: 'applauncher',
|
|
|
|
focusable: true,
|
|
|
|
child: Applauncher(),
|
2023-09-29 03:36:48 -04:00
|
|
|
});
|