Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add vpn to the network service #341

Merged
merged 8 commits into from
Mar 27, 2024
Merged

Conversation

PixisVI
Copy link
Contributor

@PixisVI PixisVI commented Mar 9, 2024

This PR adds a vpn service to the network one.

It works similarly to bluetooth devices.

I'm still kinda new to typescript and ags so any feedback would be appreciated :)

Vpn

signals

  • connection-added: (uuid: string)
  • connection-removed: (uuid: string)

properties

  • connections: VpnConnection[]
  • activated-connections: VpnConnection[]

methods

  • getConnection: (uuid: string) => VpnConnection

VpnConnection

properties

  • uuid: string
  • id: string
  • state: string
  • vpn-state: string
  • icon-name: string

methods

  • setConnection: (connect: boolean) => void

Example Widget

const { vpn } = await Service.import("network");

const VpnConnectionItem = (vpnConnection) => Widget.Box({
    tooltip_text: vpnConnection.bind("vpn_state").as(vpnState => `State: ${vpnState}`),
    children: [
        Widget.Icon({
            icon: vpnConnection.bind("icon_name"),
        }),
        Widget.Label({
            label: vpnConnection.bind("id"),
        }),
        Widget.Box({ hexpand: true }),
        Widget.Spinner({
            active: vpnConnection.bind("state").as(s => s === "connecting" || s === "disconnecting"),
            visible: vpnConnection.bind("state").as(s => s === "connecting" || s === "disconnecting"),
        }),
        Widget.Switch({
            active: vpnConnection.bind("state").as(s => s !== "disconnected"),
            visible: vpnConnection.bind("state").as(s => !(s === "connecting" || s === "disconnecting")),
            on_activate: ({ active }) => vpnConnection.setConnection(active),
        }),
    ]
});

export const VpnConnections = () => Widget.Box({
    class_name: "vpn-connections",
    hexpand: true,
    vertical: true,
    children: vpn.bind("connections").as(connections => connections.map(VpnConnectionItem)),
})

@Aylur Aylur merged commit 0f3abad into Aylur:main Mar 27, 2024
2 checks passed
@PixisVI PixisVI deleted the feat/vpn-service branch March 27, 2024 18:03
PixisVI added a commit to PixisVI/ags-docs that referenced this pull request Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants