import { exec, Variable } from "astal";
import AstalNetwork from "gi://AstalNetwork";

const networkEnabled = Variable( exec( 'nmcli networking connectivity' ) !== 'none' );
const network = AstalNetwork.get_default();


const setNetworking = ( status: boolean ) => {
    if ( status === true ) {
        exec( 'nmcli networking on' );
        networkEnabled.set( true );
    } else {
        exec( 'nmcli networking off' );
        networkEnabled.set( false );
    }
}


const getIP = () => {
    return exec( `/bin/bash -c "ip addr show | grep 'inet ' | awk '{print $2}' | grep -v '127'"` ).split( '/' )[ 0 ];
}


export default {
    networkEnabled,
    setNetworking,
    getIP
}
