2025-04-25 20:56:59 +02:00

63 lines
2.0 KiB
TypeScript

import { App } from "astal/gtk4"
import style from "./style.scss"
import Bar from "./components/bar/Bar";
import AstalHyprland from "gi://AstalHyprland?version=0.1";
import { hyprToGdk } from "./util/hyprland";
import { writeFile } from "astal";
App.start({
instanceName: "runner",
css: style,
main() {
const hypr = AstalHyprland.get_default();
const bars = new Map<number, string>();
const barCreator = ( monitor: AstalHyprland.Monitor ) => {
const gdkMonitor = hyprToGdk( monitor );
if ( gdkMonitor ) {
print( 'Bar added for screen ' + monitor.get_id() );
bars.set( monitor.get_id(), Bar.BarLauncher( gdkMonitor ) );
}
}
for (const monitor of hypr.monitors) {
barCreator( monitor );
}
hypr.connect( 'monitor-added', ( _, monitor ) => {
barCreator( monitor );
} );
hypr.connect( 'monitor-removed', ( _, monitor ) => {
const windowName = bars.get( monitor );
if ( windowName ) {
const win = App.get_window( windowName );
if ( win ) {
App.toggle_window( windowName );
win.set_child( null );
App.remove_window( win );
print( 'Bar removed for screen', monitor );
}
bars.delete( monitor );
}
} );
// const monitors = App.get_monitors();
// print( "adding bar to monitors" );
// for (let index = 0; index < monitors.length; index++) {
// Bar.BarLauncher( monitors[ index ] );
// }
},
requestHandler(request, res) {
const args = request.trimStart().split( ' ' );
if ( args[ 0 ] === 'notifier' ) {
res( 'Not available here yet, run astal -i notifier ' + args[ 1 ] );
// res( notifications.cliHandler( args ) );
} else if ( args[ 0 ] === 'bar' ) {
res( Bar.cliHandler( args ) );
}
},
})