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

Update connect-to-vpn extension #16004

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions extensions/connect-to-vpn/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Connect to VPN Changelog

## [Bug fix] - 2024-12-22

- Fixed spawning zombie process while updating services status in background

## [New Additions] - 2024-11-13

- Menu bar icon updates in the background
Expand Down
3 changes: 2 additions & 1 deletion extensions/connect-to-vpn/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"contributors": [
"sato11",
"stonerl",
"vyacheslav"
"vyacheslav",
"yshmeel"
],
"license": "MIT",
"commands": [
Expand Down
4 changes: 2 additions & 2 deletions extensions/connect-to-vpn/src/menu-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export default function Command() {
const isChecking = useRef(false);

useEffect(() => {
if (environment.launchType === LaunchType.Background) {
if (environment.launchType === LaunchType.Background && !isLoading) {
startRefresh();
}
}, [environment.launchType, favoriteServices, otherServices, invalidServices]);
}, [environment.launchType, favoriteServices.length, otherServices.length, invalidServices.length]);

const startRefresh = async () => {
if (!isChecking.current) {
Expand Down
31 changes: 11 additions & 20 deletions extensions/connect-to-vpn/src/network-services.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useState, useEffect, useMemo } from "react";
import { exec } from "child_process";
import { Icon, LocalStorage, Toast, getPreferenceValues, showToast } from "@raycast/api";
import { execSync } from "node:child_process";

type Preferences = {
hideInvalidDevices: boolean;
Expand Down Expand Up @@ -70,6 +71,8 @@ export function useNetworkServices() {
...currentServices,
[service.id]: { ...service, status },
}));

return status;
} catch (err) {
console.error(`Error fetching service status for ${service.name}:`, err);
setError(err as Error);
Expand Down Expand Up @@ -338,27 +341,15 @@ const saveFavoriteOrder = async (order: Record<string, number>) => {

const execPromise = (command: string): Promise<string> =>
new Promise((resolve, reject) => {
const child = exec(command, (err, stdout, stderr) => {
if (err) {
console.error(`Error executing command: ${command}`, err);
reject(err);
} else if (stderr) {
console.warn(`Command stderr: ${stderr}`);
resolve(stdout.trim());
} else {
resolve(stdout.trim());
}
});

// Ensure the child process is cleaned up
child.on("exit", (code) => {
console.log(`Command exited with code: ${code}`);
});
try {
const child = execSync(command);
const result = child.toString();

child.on("error", (err) => {
console.error(`Failed to start command: ${command}`, err);
reject(err);
});
resolve(result.trim());
} catch (e) {
console.error(`Command ${command} thrown an error`, e);
reject(e);
}
});

const listNetworkServiceOrder = (): Promise<string> => execPromise("/usr/sbin/networksetup -listnetworkserviceorder");
Expand Down
Loading