refactor(ags applauncher): use latest code from aylur

This commit is contained in:
matt1432 2023-11-13 15:19:49 -05:00
parent c0a97e044c
commit 93285a0db7
4 changed files with 106 additions and 75 deletions

View file

@ -0,0 +1,51 @@
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
import App from 'resource:///com/github/Aylur/ags/app.js';
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
import { lookUpIcon } from 'resource:///com/github/Aylur/ags/utils.js';
import Separator from '../misc/separator.js';
export default app => {
const title = Widget.Label({
class_name: 'title',
label: app.name,
xalign: 0,
vpack: 'center',
truncate: 'end',
});
const description = Widget.Label({
class_name: 'description',
label: app.description || '',
wrap: true,
xalign: 0,
justification: 'left',
vpack: 'center',
});
const icon = Widget.Icon({
icon: lookUpIcon(app.icon_name) ? app.icon_name :
app.app.get_string('Icon') !== 'nix-snowflake' ? app.app.get_string('Icon') : '',
size: 42,
});
const textBox = Widget.Box({
vertical: true,
vpack: 'center',
children: [title, description],
});
return Widget.Button({
class_name: 'app',
setup: self => self.app = app,
on_clicked: () => {
App.closeWindow('applauncher');
Hyprland.sendMessage(`dispatch exec sh -c ${app.executable}`);
++app.frequency;
},
child: Widget.Box({
children: [icon, Separator(16), textBox],
}),
});
};

View file

@ -2,102 +2,78 @@ import App from 'resource:///com/github/Aylur/ags/app.js';
import Applications from 'resource:///com/github/Aylur/ags/service/applications.js'; import Applications from 'resource:///com/github/Aylur/ags/service/applications.js';
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js'; import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
import { Label, Box, Icon, Button, Scrollable, Entry } from 'resource:///com/github/Aylur/ags/widget.js'; import { Box, Entry, Icon, Label, Scrollable } from 'resource:///com/github/Aylur/ags/widget.js';
import Separator from '../misc/separator.js';
import PopupWindow from '../misc/popup.js'; import PopupWindow from '../misc/popup.js';
import Separator from '../misc/separator.js';
const icons = { import AppItem from './app-item.js';
apps: {
apps: 'view-app-grid-symbolic',
search: 'preferences-system-search-symbolic',
},
};
const AppItem = (app, window) => { const Applauncher = ({ window_name = 'applauncher' } = {}) => {
if (app.app.get_string('Icon') == 'Nextcloud') const children = () => [
return; ...Applications.query('').flatMap(app => {
const item = AppItem(app);
return Button({ return [
className: 'app', Separator(4, {
connections: [['clicked', () => { binds: [['visible', item, 'visible']],
App.closeWindow(window);
Hyprland.sendMessage(`dispatch exec sh -c ${app.executable}`);
// 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({ item,
vertical: true, ];
children: [
Label({
className: 'title',
label: app.name,
xalign: 0,
vpack: 'center',
ellipsize: 3,
}),
Label({
className: 'description',
label: app.description || '',
wrap: true,
xalign: 0,
justification: 'left',
vpack: 'center',
}),
],
}),
],
}), }),
}); Separator(4),
}; ];
const Applauncher = ({ windowName = 'applauncher' } = {}) => { const list = Box({
const list = Box({ vertical: true }); vertical: true,
const placeholder = Label({ children: children(),
label: " Couldn't find a match",
className: 'placeholder',
}); });
const entry = Entry({ const entry = Entry({
hexpand: true, hexpand: true,
placeholderText: 'Search', placeholder_text: 'Search',
onAccept: ({ text }) => {
const list = Applications.query(text); // set some text so on-change works the first time
text: '-',
on_accept: ({ text }) => {
const list = Applications.query(text || '');
if (list[0]) { if (list[0]) {
App.toggleWindow(windowName); App.toggleWindow(window_name);
list[0].launch(); Hyprland.sendMessage(`dispatch exec sh -c ${list[0]}`);
++list[0].frequency;
} }
}, },
onChange: ({ text }) => { on_change: ({ text }) => {
list.children = Applications.query(text).map(app => [ let visibleApps = 0;
Separator(4), list.children.map(item => {
AppItem(app, windowName), if (item.app) {
]).flat(); item.visible = item.app.match(text);
list.add(Separator(4));
list.show_all();
placeholder.visible = list.children.length === 1; if (item.app.match(text))
++visibleApps;
}
});
placeholder.visible = visibleApps <= 0;
}, },
}); });
const placeholder = Label({
label: " Couldn't find a match",
className: 'placeholder',
});
return Box({ return Box({
className: 'applauncher', className: 'applauncher',
properties: [['list', list]],
vertical: true, vertical: true,
children: [ children: [
Box({ Box({
className: 'header', className: 'header',
children: [ children: [
Icon(icons.apps.search), Icon('preferences-system-search-symbolic'),
entry, entry,
], ],
}), }),
Scrollable({ Scrollable({
hscroll: 'never', hscroll: 'never',
child: Box({ child: Box({
@ -106,14 +82,15 @@ const Applauncher = ({ windowName = 'applauncher' } = {}) => {
}), }),
}), }),
], ],
connections: [[App, (_b, name, visible) => { connections: [[App, (_, name, visible) => {
if (name !== windowName) if (name !== window_name)
return; return;
entry.set_text('-'); // force onChange entry.text = '';
entry.set_text('');
if (visible) if (visible)
entry.grab_focus(); entry.grab_focus();
else
list.children = children();
}]], }]],
}); });
}; };

View file

@ -1,15 +1,17 @@
import { Box } from 'resource:///com/github/Aylur/ags/widget.js'; import { Box } from 'resource:///com/github/Aylur/ags/widget.js';
export default (size, { vertical = false } = {}) => { export default (size, { vertical = false, ...props } = {}) => {
if (vertical) { if (vertical) {
return Box({ return Box({
css: `min-height: ${size}px;`, css: `min-height: ${size}px;`,
...props,
}); });
} }
else { else {
return Box({ return Box({
css: `min-width: ${size}px;`, css: `min-width: ${size}px;`,
...props,
}); });
} }
}; };

View file

@ -107,7 +107,8 @@
image { image {
transition: 200ms; transition: 200ms;
margin-right: 9px; margin-left: -10px;
margin-bottom: -8px;
} }
} }
} }