2024-10-28 18:18:07 -04:00
|
|
|
import { App } from 'astal/gtk3';
|
2024-10-18 00:44:45 -04:00
|
|
|
|
2024-10-22 13:09:39 -04:00
|
|
|
import AstalApps from 'gi://AstalApps';
|
2024-10-18 00:44:45 -04:00
|
|
|
|
2024-10-28 18:18:07 -04:00
|
|
|
import SortedList from '../misc/sorted-list';
|
2024-10-18 00:44:45 -04:00
|
|
|
|
|
|
|
import { launchApp } from './launch';
|
2024-10-30 18:53:15 -04:00
|
|
|
import AppItem from './app-item';
|
2024-10-28 18:18:07 -04:00
|
|
|
|
2024-10-18 00:44:45 -04:00
|
|
|
|
2024-10-28 18:18:07 -04:00
|
|
|
export default () => SortedList({
|
|
|
|
name: 'applauncher',
|
2024-10-18 00:44:45 -04:00
|
|
|
|
2024-10-28 18:18:07 -04:00
|
|
|
create_list: () => AstalApps.Apps.new().get_list(),
|
2024-10-18 00:44:45 -04:00
|
|
|
|
2024-10-30 18:53:15 -04:00
|
|
|
create_row: (app) => <AppItem app={app} />,
|
2024-10-18 00:44:45 -04:00
|
|
|
|
2024-10-28 18:18:07 -04:00
|
|
|
fzf_options: {
|
2024-12-29 17:22:55 -05:00
|
|
|
selector: (app) => app.get_name() + app.get_executable(),
|
2024-10-28 18:18:07 -04:00
|
|
|
|
|
|
|
tiebreakers: [
|
2024-12-29 17:22:55 -05:00
|
|
|
(a, b) => b.item.get_frequency() - a.item.get_frequency(),
|
2024-10-28 18:18:07 -04:00
|
|
|
],
|
|
|
|
},
|
|
|
|
|
2024-11-01 15:55:57 -04:00
|
|
|
unique_props: ['name', 'executable'],
|
2024-10-30 01:42:00 -04:00
|
|
|
|
2024-10-28 18:18:07 -04:00
|
|
|
on_row_activated: (row) => {
|
2024-10-18 00:44:45 -04:00
|
|
|
const app = (row.get_children()[0] as AppItem).app;
|
|
|
|
|
|
|
|
launchApp(app);
|
|
|
|
App.get_window('win-applauncher')?.set_visible(false);
|
2024-10-28 18:18:07 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
sort_func: (a, b, entry, fzfResults) => {
|
2024-10-18 00:44:45 -04:00
|
|
|
const row1 = (a.get_children()[0] as AppItem).app;
|
|
|
|
const row2 = (b.get_children()[0] as AppItem).app;
|
|
|
|
|
|
|
|
if (entry.text === '' || entry.text === '-') {
|
|
|
|
a.set_visible(true);
|
|
|
|
b.set_visible(true);
|
|
|
|
|
2024-12-29 17:22:55 -05:00
|
|
|
return row2.get_frequency() - row1.get_frequency();
|
2024-10-18 00:44:45 -04:00
|
|
|
}
|
|
|
|
else {
|
2024-12-29 17:22:55 -05:00
|
|
|
const s1 = fzfResults.find((r) => r.item.get_name() === row1.get_name())?.score ?? 0;
|
|
|
|
const s2 = fzfResults.find((r) => r.item.get_name() === row2.get_name())?.score ?? 0;
|
2024-10-18 00:44:45 -04:00
|
|
|
|
|
|
|
a.set_visible(s1 !== 0);
|
|
|
|
b.set_visible(s2 !== 0);
|
|
|
|
|
|
|
|
return s2 - s1;
|
|
|
|
}
|
2024-10-28 18:18:07 -04:00
|
|
|
},
|
|
|
|
});
|