2024-01-30 11:29:07 -05:00
|
|
|
const Applications = await Service.import('applications');
|
|
|
|
|
2024-03-19 15:10:18 -04:00
|
|
|
import { Fzf, FzfResultItem } from 'fzf';
|
2023-10-31 08:32:40 -04:00
|
|
|
|
2024-05-01 15:03:42 -04:00
|
|
|
import SortedList from '../misc/sorted-list.ts';
|
2024-01-13 23:38:31 -05:00
|
|
|
import AppItem from './app-item.ts';
|
2024-05-01 15:03:42 -04:00
|
|
|
|
2024-04-16 08:27:36 -04:00
|
|
|
import { launchApp } from './launch.ts';
|
2023-09-29 03:36:48 -04:00
|
|
|
|
2024-05-01 15:03:42 -04:00
|
|
|
/* Types */
|
2024-01-22 10:23:32 -05:00
|
|
|
import { ListBoxRow } from 'types/@girs/gtk-3.0/gtk-3.0.cjs';
|
2024-01-29 18:54:07 -05:00
|
|
|
import { Application } from 'types/service/applications.ts';
|
|
|
|
import { AgsAppItem } from 'global-types';
|
2023-12-20 03:45:05 -05:00
|
|
|
|
2023-09-29 03:36:48 -04:00
|
|
|
|
2024-05-01 15:03:42 -04:00
|
|
|
export default () => {
|
2024-01-29 18:54:07 -05:00
|
|
|
let fzfResults: FzfResultItem<Application>[];
|
2023-12-07 01:18:47 -05:00
|
|
|
|
2024-05-01 15:03:42 -04:00
|
|
|
return SortedList({
|
|
|
|
name: 'applauncher',
|
|
|
|
class_name: 'applauncher',
|
|
|
|
transition: 'slide top',
|
2024-03-19 15:10:18 -04:00
|
|
|
|
2024-05-01 15:03:42 -04:00
|
|
|
on_select: (r) => {
|
|
|
|
App.closeWindow('win-applauncher');
|
|
|
|
launchApp((r.get_child() as AgsAppItem).attribute.app);
|
|
|
|
},
|
2023-12-07 01:18:47 -05:00
|
|
|
|
2024-05-01 15:03:42 -04:00
|
|
|
init_rows: (list) => {
|
|
|
|
const rows = list.get_children() as ListBoxRow[];
|
2023-12-20 03:45:05 -05:00
|
|
|
|
2024-05-01 15:03:42 -04:00
|
|
|
rows.forEach((ch) => {
|
|
|
|
ch.destroy();
|
|
|
|
});
|
2023-12-07 01:18:47 -05:00
|
|
|
|
2024-05-01 15:03:42 -04:00
|
|
|
const children = Applications.query('')
|
|
|
|
.flatMap((app) => AppItem(app));
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2024-05-01 15:03:42 -04:00
|
|
|
children.forEach((ch) => {
|
|
|
|
list.add(ch);
|
|
|
|
});
|
|
|
|
list.show_all();
|
|
|
|
},
|
2023-09-29 03:36:48 -04:00
|
|
|
|
2024-05-01 15:03:42 -04:00
|
|
|
set_sort: (text, list, placeholder) => {
|
|
|
|
const fzf = new Fzf(Applications.list, {
|
|
|
|
selector: (app) => app.name + app.executable,
|
2023-11-13 15:19:49 -05:00
|
|
|
|
2024-05-01 15:03:42 -04:00
|
|
|
tiebreakers: [
|
|
|
|
(a, b) => b.item.frequency - a.item.frequency,
|
|
|
|
],
|
|
|
|
});
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2024-05-01 15:03:42 -04:00
|
|
|
fzfResults = fzf.find(text);
|
|
|
|
list.set_sort_func((a, b) => {
|
|
|
|
const row1 = (a.get_children()[0] as AgsAppItem).attribute.app.name;
|
|
|
|
const row2 = (b.get_children()[0] as AgsAppItem).attribute.app.name;
|
2023-11-13 15:19:49 -05:00
|
|
|
|
2024-05-01 15:03:42 -04:00
|
|
|
const s1 = fzfResults.find((r) => r.item.name === row1)?.score ?? 0;
|
|
|
|
const s2 = fzfResults.find((r) => r.item.name === row2)?.score ?? 0;
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2024-05-01 15:03:42 -04:00
|
|
|
return s2 - s1;
|
|
|
|
});
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-13 15:19:49 -05:00
|
|
|
let visibleApps = 0;
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2024-01-29 18:54:07 -05:00
|
|
|
const rows = list.get_children() as ListBoxRow[];
|
2023-12-20 03:45:05 -05:00
|
|
|
|
|
|
|
rows.forEach((row) => {
|
2023-12-07 01:18:47 -05:00
|
|
|
row.changed();
|
|
|
|
|
2024-01-29 18:54:07 -05:00
|
|
|
const item = (row.get_children()[0] as AgsAppItem);
|
2023-12-07 01:18:47 -05:00
|
|
|
|
2024-01-29 18:54:07 -05:00
|
|
|
if (item.attribute.app) {
|
2024-03-19 15:10:18 -04:00
|
|
|
const isMatching = fzfResults.some((r) => {
|
2023-12-18 18:00:30 -05:00
|
|
|
return r.item.name === item.attribute.app.name;
|
2023-12-07 01:18:47 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
row.visible = isMatching;
|
2023-09-29 03:36:48 -04:00
|
|
|
|
2023-12-07 01:18:47 -05:00
|
|
|
if (isMatching) {
|
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
|
|
|
}
|
|
|
|
});
|
2023-12-18 20:23:09 -05:00
|
|
|
placeholder.reveal_child = visibleApps <= 0;
|
2023-10-20 23:11:21 -04:00
|
|
|
},
|
|
|
|
});
|
2023-09-29 03:36:48 -04:00
|
|
|
};
|