[Astal] Format

This commit is contained in:
2025-10-17 10:47:05 +02:00
parent 06325b09b8
commit 9cf14d3b55

View File

@@ -1,26 +1,31 @@
import { App } from "astal/gtk4" import {
import style from "./style.scss" App
import Bar from "./components/bar/Bar"; } from 'astal/gtk4';
import AstalHyprland from "gi://AstalHyprland?version=0.1"; import AstalHyprland from 'gi://AstalHyprland?version=0.1';
import { hyprToGdk } from "./util/hyprland"; import Bar from './components/bar/Bar';
import Brightness from "./util/brightness"; import Brightness from './util/brightness';
import {
hyprToGdk
} from './util/hyprland';
import style from './style.scss';
App.start({ App.start( {
instanceName: "runner", 'instanceName': 'runner',
css: style, 'css': style,
main() { main () {
const hypr = AstalHyprland.get_default(); const hypr = AstalHyprland.get_default();
const bars = new Map<number, string>(); const bars = new Map<number, string>();
const barCreator = ( monitor: AstalHyprland.Monitor ) => { const barCreator = ( monitor: AstalHyprland.Monitor ) => {
const gdkMonitor = hyprToGdk( monitor ); const gdkMonitor = hyprToGdk( monitor );
if ( gdkMonitor ) { if ( gdkMonitor ) {
print( 'Bar added for screen ' + monitor.get_id() ); print( 'Bar added for screen ' + monitor.get_id() );
bars.set( monitor.get_id(), Bar.BarLauncher( gdkMonitor ) ); bars.set( monitor.get_id(), Bar.BarLauncher( gdkMonitor ) );
} }
} };
for (const monitor of hypr.monitors) { for ( const monitor of hypr.monitors ) {
barCreator( monitor ); barCreator( monitor );
} }
@@ -30,14 +35,17 @@ App.start({
hypr.connect( 'monitor-removed', ( _, monitor ) => { hypr.connect( 'monitor-removed', ( _, monitor ) => {
const windowName = bars.get( monitor ); const windowName = bars.get( monitor );
if ( windowName ) { if ( windowName ) {
const win = App.get_window( windowName ); const win = App.get_window( windowName );
if ( win ) { if ( win ) {
App.toggle_window( windowName ); App.toggle_window( windowName );
win.set_child( null ); win.set_child( null );
App.remove_window( win ); App.remove_window( win );
print( 'Bar removed for screen', monitor ); print( 'Bar removed for screen', monitor );
} }
bars.delete( monitor ); bars.delete( monitor );
} }
} ); } );
@@ -49,7 +57,7 @@ App.start({
// } // }
// Launcher(); // Launcher();
}, },
requestHandler(request, res) { requestHandler ( request, res ) {
const args = request.trimStart().split( ' ' ); const args = request.trimStart().split( ' ' );
if ( args[ 0 ] === 'notifier' ) { if ( args[ 0 ] === 'notifier' ) {
@@ -60,6 +68,7 @@ App.start({
} else if ( args[ 0 ] === 'brightness' ) { } else if ( args[ 0 ] === 'brightness' ) {
try { try {
const brightness = Brightness.get_default(); const brightness = Brightness.get_default();
if ( brightness.screenAvailable ) { if ( brightness.screenAvailable ) {
if ( args[ 1 ] === 'increase' ) { if ( args[ 1 ] === 'increase' ) {
brightness.screen += args.length > 1 ? parseInt( args[ 2 ] ) / 100 : 1; brightness.screen += args.length > 1 ? parseInt( args[ 2 ] ) / 100 : 1;
@@ -70,12 +79,15 @@ App.start({
brightness.screen = parseInt( args[ 2 ] ) / 100; brightness.screen = parseInt( args[ 2 ] ) / 100;
} else { } else {
res( 'Argument <brightness> unspecified' ); res( 'Argument <brightness> unspecified' );
return; return;
} }
} else { } else {
res( 'Unknown command ' + args[ 1 ] ); res( 'Unknown command ' + args[ 1 ] );
return; return;
} }
res( 'Ok' ); res( 'Ok' );
} else { } else {
res( 'No controllable screen available' ); res( 'No controllable screen available' );
@@ -99,5 +111,4 @@ App.start({
// } // }
// } // }
}, },
}) } );