feat(ags): import fzf correctly with types
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-03-19 15:10:18 -04:00
parent cea02da54c
commit 89c02b408d
3 changed files with 19 additions and 13 deletions

View file

@ -29,13 +29,15 @@ export const transpileTypeScript = async(host) => {
// Create the dir if it doesn't exist
`mkdir -p /tmp/ags-${host}; ` +
// Let bun see tsconfig.json
`cd ${App.configDir};` +
`bun build ${App.configDir}/${host}.ts ` +
'--external resource:///* ' +
'--external gi://* ' +
'--external cairo ' +
'--external */fzf.es.js ' +
// Since bun wants to right in cwd, we just redirect stdin instead
// Since bun wants to write in cwd, we just redirect stdin instead
`> ${outPath}`,
]).catch(print);

View file

@ -1,8 +1,7 @@
const Applications = await Service.import('applications');
const { Box, Entry, Icon, Label, ListBox, Revealer, Scrollable } = Widget;
// @ts-expect-error find cleaner way to import this
import { Fzf, FzfResultItem } from 'file:///home/matt/.nix/modules/ags/config/node_modules/fzf/dist/fzf.es.js';
import { Fzf, FzfResultItem } from 'fzf';
import PopupWindow from '../misc/popup.ts';
import AppItem from './app-item.ts';
@ -19,11 +18,10 @@ const Applauncher = (window_name = 'applauncher') => {
const setSort = (text: string) => {
const fzf = new Fzf(Applications.list, {
selector: (app: Application) => {
return app.name + app.executable;
},
selector: (app) => app.name + app.executable,
tiebreakers: [
(a: Application, b: Application) => b.frequency - a.frequency,
(a, b) => b.item.frequency - a.item.frequency,
],
});
@ -32,12 +30,14 @@ const Applauncher = (window_name = 'applauncher') => {
const row1 = (a.get_children()[0] as AgsAppItem).attribute.app.name;
const row2 = (b.get_children()[0] as AgsAppItem).attribute.app.name;
if (!row1 || !row2) {
const rowRes1 = fzfResults.find((r) => r.item.name === row1)?.score;
const rowRes2 = fzfResults.find((r) => r.item.name === row2)?.score;
if (!rowRes1 || !rowRes2) {
return 0;
}
return fzfResults.indexOf(row1) -
fzfResults.indexOf(row1) || 0;
return rowRes1 - rowRes2;
});
};
@ -95,7 +95,7 @@ const Applauncher = (window_name = 'applauncher') => {
const item = (row.get_children()[0] as AgsAppItem);
if (item.attribute.app) {
const isMatching = fzfResults.find((r) => {
const isMatching = fzfResults.some((r) => {
return r.item.name === item.attribute.app.name;
});

View file

@ -10,9 +10,13 @@
"strict": true,
"noImplicitAny": false,
"baseUrl": ".",
"paths": {
"fzf": ["./node_modules/fzf/dist/types"],
},
"typeRoots": [
"./types",
"./global-types.d.ts"
"./global-types.d.ts",
"./node_modules",
],
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true