2023-10-31 08:32:40 -04:00
|
|
|
import App from 'resource:///com/github/Aylur/ags/app.js';
|
|
|
|
import Applications from 'resource:///com/github/Aylur/ags/service/applications.js';
|
|
|
|
|
|
|
|
import { Label, Box, Icon, Button, Scrollable, Entry } from 'resource:///com/github/Aylur/ags/widget.js';
|
2023-11-02 16:49:38 -04:00
|
|
|
import { execAsync } from 'resource:///com/github/Aylur/ags/utils.js';
|
2023-09-29 03:36:48 -04:00
|
|
|
|
2023-10-17 13:47:02 -04:00
|
|
|
import Separator from '../misc/separator.js';
|
|
|
|
import PopupWindow from '../misc/popup.js';
|
2023-09-29 03:36:48 -04:00
|
|
|
|
|
|
|
const icons = {
|
2023-10-20 23:11:21 -04:00
|
|
|
apps: {
|
|
|
|
apps: 'view-app-grid-symbolic',
|
|
|
|
search: 'preferences-system-search-symbolic',
|
|
|
|
},
|
2023-09-29 03:36:48 -04:00
|
|
|
};
|
|
|
|
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-09-29 03:36:48 -04:00
|
|
|
const AppItem = (app, window) => {
|
2023-10-20 23:11:21 -04:00
|
|
|
if (app.app.get_string('Icon') == 'Nextcloud')
|
|
|
|
return;
|
2023-09-29 03:36:48 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
return Button({
|
|
|
|
className: 'app',
|
|
|
|
connections: [['clicked', () => {
|
|
|
|
App.closeWindow(window);
|
2023-11-03 13:49:50 -04:00
|
|
|
execAsync(['hyprctl', 'dispatch', 'exec', `sh -c ${app.executable}`]);
|
2023-10-20 23:11:21 -04:00
|
|
|
// TODO: focus on new client. Is this only needed after launch?
|
|
|
|
++app.frequency;
|
|
|
|
}]],
|
|
|
|
child: Box({
|
|
|
|
children: [
|
|
|
|
Icon({
|
|
|
|
icon: app.app.get_string('Icon'),
|
|
|
|
size: 42,
|
|
|
|
}),
|
|
|
|
Box({
|
|
|
|
vertical: true,
|
|
|
|
children: [
|
|
|
|
Label({
|
|
|
|
className: 'title',
|
|
|
|
label: app.name,
|
|
|
|
xalign: 0,
|
2023-11-06 18:37:23 -05:00
|
|
|
vpack: 'center',
|
2023-10-20 23:11:21 -04:00
|
|
|
ellipsize: 3,
|
|
|
|
}),
|
|
|
|
Label({
|
|
|
|
className: 'description',
|
|
|
|
label: app.description || '',
|
|
|
|
wrap: true,
|
|
|
|
xalign: 0,
|
|
|
|
justification: 'left',
|
2023-11-06 18:37:23 -05:00
|
|
|
vpack: 'center',
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
],
|
2023-09-29 03:36:48 -04:00
|
|
|
}),
|
2023-10-20 23:11:21 -04:00
|
|
|
});
|
2023-09-29 03:36:48 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
const Applauncher = ({ windowName = 'applauncher' } = {}) => {
|
2023-10-20 23:11:21 -04:00
|
|
|
const list = Box({ vertical: true });
|
|
|
|
const placeholder = Label({
|
|
|
|
label: " Couldn't find a match",
|
|
|
|
className: 'placeholder',
|
|
|
|
});
|
|
|
|
const entry = Entry({
|
|
|
|
hexpand: true,
|
|
|
|
placeholderText: 'Search',
|
|
|
|
onAccept: ({ text }) => {
|
|
|
|
const list = Applications.query(text);
|
|
|
|
if (list[0]) {
|
|
|
|
App.toggleWindow(windowName);
|
|
|
|
list[0].launch();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onChange: ({ text }) => {
|
|
|
|
list.children = Applications.query(text).map(app => [
|
|
|
|
Separator(4),
|
|
|
|
AppItem(app, windowName),
|
|
|
|
]).flat();
|
|
|
|
list.add(Separator(4));
|
|
|
|
list.show_all();
|
2023-09-29 03:36:48 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
placeholder.visible = list.children.length === 1;
|
|
|
|
},
|
|
|
|
});
|
2023-09-29 03:36:48 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
return Box({
|
|
|
|
className: 'applauncher',
|
|
|
|
properties: [['list', list]],
|
|
|
|
vertical: true,
|
2023-09-29 03:36:48 -04:00
|
|
|
children: [
|
2023-10-20 23:11:21 -04:00
|
|
|
Box({
|
|
|
|
className: 'header',
|
|
|
|
children: [
|
|
|
|
Icon(icons.apps.search),
|
|
|
|
entry,
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
Scrollable({
|
|
|
|
hscroll: 'never',
|
|
|
|
child: Box({
|
|
|
|
vertical: true,
|
|
|
|
children: [list, placeholder],
|
|
|
|
}),
|
|
|
|
}),
|
2023-09-29 03:36:48 -04:00
|
|
|
],
|
2023-10-20 23:11:21 -04:00
|
|
|
connections: [[App, (_b, name, visible) => {
|
|
|
|
if (name !== windowName)
|
|
|
|
return;
|
2023-09-29 03:36:48 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
entry.set_text('-'); // force onChange
|
|
|
|
entry.set_text('');
|
|
|
|
if (visible)
|
|
|
|
entry.grab_focus();
|
|
|
|
}]],
|
|
|
|
});
|
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
|
|
|
});
|