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-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-08-01 17:21:52 -04:00
|
|
|
let fzfResults = [] as 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-08-01 17:21:52 -04:00
|
|
|
setup_list: (list, entry) => {
|
|
|
|
Applications.query('')
|
|
|
|
.flatMap((app) => AppItem(app))
|
|
|
|
.forEach((ch) => {
|
|
|
|
list.add(ch);
|
|
|
|
});
|
2023-12-20 03:45:05 -05:00
|
|
|
|
2024-08-01 17:21:52 -04:00
|
|
|
list.show_all();
|
|
|
|
|
|
|
|
list.set_sort_func((a, b) => {
|
|
|
|
const row1 = (a.get_children()[0] as AgsAppItem).attribute.app;
|
|
|
|
const row2 = (b.get_children()[0] as AgsAppItem).attribute.app;
|
|
|
|
|
|
|
|
if (entry.text === '' || entry.text === '-') {
|
|
|
|
a.set_visible(true);
|
|
|
|
b.set_visible(true);
|
2023-12-07 01:18:47 -05:00
|
|
|
|
2024-08-01 17:21:52 -04:00
|
|
|
return row2.frequency - row1.frequency;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const s1 = fzfResults.find((r) => r.item.name === row1.name)?.score ?? 0;
|
|
|
|
const s2 = fzfResults.find((r) => r.item.name === row2.name)?.score ?? 0;
|
|
|
|
|
|
|
|
a.set_visible(s1 !== 0);
|
|
|
|
b.set_visible(s2 !== 0);
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2024-08-01 17:21:52 -04:00
|
|
|
return s2 - s1;
|
|
|
|
}
|
2024-05-01 15:03:42 -04:00
|
|
|
});
|
|
|
|
},
|
2023-09-29 03:36:48 -04:00
|
|
|
|
2024-08-01 17:21:52 -04:00
|
|
|
on_text_change: (text, list, placeholder) => {
|
2024-05-01 15:03:42 -04:00
|
|
|
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);
|
2024-08-01 17:21:52 -04:00
|
|
|
list.invalidate_sort();
|
2023-11-13 15:19:49 -05:00
|
|
|
|
2024-08-01 17:21:52 -04:00
|
|
|
const visibleApps = list.get_children().filter((row) => row.visible).length;
|
2023-11-21 01:29:46 -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
|
|
|
};
|