parent
5d27b3d975
commit
f3e06554e4
105 changed files with 245 additions and 254 deletions
nixosModules/ags/config/widgets/applauncher
6
nixosModules/ags/config/widgets/applauncher/_index.scss
Normal file
6
nixosModules/ags/config/widgets/applauncher/_index.scss
Normal file
|
@ -0,0 +1,6 @@
|
|||
.applauncher {
|
||||
.app {
|
||||
margin: 20px;
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
65
nixosModules/ags/config/widgets/applauncher/app-item.tsx
Normal file
65
nixosModules/ags/config/widgets/applauncher/app-item.tsx
Normal file
|
@ -0,0 +1,65 @@
|
|||
import { Gtk, Widget } from 'astal/gtk3';
|
||||
import { register } from 'astal/gobject';
|
||||
|
||||
/* Types */
|
||||
import AstalApps from 'gi://AstalApps';
|
||||
type AppItemProps = Widget.BoxProps & {
|
||||
app: AstalApps.Application
|
||||
};
|
||||
|
||||
|
||||
@register()
|
||||
export class AppItem extends Widget.Box {
|
||||
readonly app: AstalApps.Application;
|
||||
|
||||
constructor({
|
||||
app,
|
||||
hexpand = true,
|
||||
className = '',
|
||||
...rest
|
||||
}: AppItemProps) {
|
||||
super({
|
||||
...rest,
|
||||
className: `app ${className}`,
|
||||
hexpand,
|
||||
});
|
||||
this.app = app;
|
||||
|
||||
const icon = (
|
||||
<icon
|
||||
icon={this.app.iconName}
|
||||
css="font-size: 42px; margin-right: 25px;"
|
||||
/>
|
||||
);
|
||||
|
||||
const textBox = (
|
||||
<box
|
||||
vertical
|
||||
>
|
||||
<label
|
||||
className="title"
|
||||
label={app.name}
|
||||
xalign={0}
|
||||
truncate
|
||||
valign={Gtk.Align.CENTER}
|
||||
/>
|
||||
|
||||
{app.description !== '' && (
|
||||
<label
|
||||
className="description"
|
||||
label={app.description}
|
||||
wrap
|
||||
xalign={0}
|
||||
justify={Gtk.Justification.LEFT}
|
||||
valign={Gtk.Align.CENTER}
|
||||
/>
|
||||
)}
|
||||
</box>
|
||||
);
|
||||
|
||||
this.add(icon);
|
||||
this.add(textBox);
|
||||
}
|
||||
}
|
||||
|
||||
export default AppItem;
|
27
nixosModules/ags/config/widgets/applauncher/launch.ts
Normal file
27
nixosModules/ags/config/widgets/applauncher/launch.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
import { execAsync } from 'astal';
|
||||
|
||||
import AstalApps from 'gi://AstalApps';
|
||||
|
||||
|
||||
const bash = async(strings: TemplateStringsArray | string, ...values: unknown[]) => {
|
||||
const cmd = typeof strings === 'string' ?
|
||||
strings :
|
||||
strings.flatMap((str, i) => `${str}${values[i] ?? ''}`)
|
||||
.join('');
|
||||
|
||||
return execAsync(['bash', '-c', cmd]).catch((err) => {
|
||||
console.error(cmd, err);
|
||||
|
||||
return '';
|
||||
});
|
||||
};
|
||||
|
||||
export const launchApp = (app: AstalApps.Application) => {
|
||||
const exe = app.executable
|
||||
.split(/\s+/)
|
||||
.filter((str) => !str.startsWith('%') && !str.startsWith('@'))
|
||||
.join(' ');
|
||||
|
||||
bash(`${exe} &`);
|
||||
app.frequency += 1;
|
||||
};
|
55
nixosModules/ags/config/widgets/applauncher/main.tsx
Normal file
55
nixosModules/ags/config/widgets/applauncher/main.tsx
Normal file
|
@ -0,0 +1,55 @@
|
|||
import { App } from 'astal/gtk3';
|
||||
|
||||
import AstalApps from 'gi://AstalApps';
|
||||
|
||||
import SortedList from '../misc/sorted-list';
|
||||
|
||||
import { launchApp } from './launch';
|
||||
import AppItem from './app-item';
|
||||
|
||||
|
||||
export default () => SortedList({
|
||||
name: 'applauncher',
|
||||
|
||||
create_list: () => AstalApps.Apps.new().get_list(),
|
||||
|
||||
create_row: (app) => <AppItem app={app} />,
|
||||
|
||||
fzf_options: {
|
||||
selector: (app) => app.name + app.executable,
|
||||
|
||||
tiebreakers: [
|
||||
(a, b) => b.item.frequency - a.item.frequency,
|
||||
],
|
||||
},
|
||||
|
||||
unique_props: ['name', 'executable'],
|
||||
|
||||
on_row_activated: (row) => {
|
||||
const app = (row.get_children()[0] as AppItem).app;
|
||||
|
||||
launchApp(app);
|
||||
App.get_window('win-applauncher')?.set_visible(false);
|
||||
},
|
||||
|
||||
sort_func: (a, b, entry, fzfResults) => {
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
return s2 - s1;
|
||||
}
|
||||
},
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue