1
1
mirror of https://github.com/neosubhamoy/pytubepp-helper.git synced 2026-02-04 11:22:22 +05:30

(refactor): added gnome-terminal as deb, rpm dependency and introduced package manager based linux distro detection

This commit is contained in:
2024-12-30 23:38:56 +05:30
Verified
parent bac65b9832
commit abd6088ca9
5 changed files with 40 additions and 15 deletions

View File

@@ -9,7 +9,7 @@ import { ThemeProvider } from "@/components/theme-provider";
import { Button } from "@/components/ui/button";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
import { InstalledPrograms, WebSocketMessage, } from "./types";
import { compareVersions, extractVersion, isInstalled, sendStreamInfo, detectWindows, detectDistro, extractDistroId, detectDistroBase, detectMacOs, registerMacFiles } from "./lib/utils";
import { compareVersions, extractVersion, isInstalled, sendStreamInfo, detectWindows, detectDistro, extractDistroId, detectMacOs, registerMacFiles, detectPackageManager, extractPkgMngrName } from "./lib/utils";
import { CircleCheck, TriangleAlert, CircleAlert } from 'lucide-react';
function App() {
@@ -27,7 +27,7 @@ function App() {
const [isMacOs, setIsMacOs] = useState<boolean>(false)
const [macOsVersion, setMacOsVersion] = useState<string | null>(null)
const [distroId, setDistroId] = useState<string | null>(null)
const [distroBase, setDistroBase] = useState<string | null>(null)
const [distroPkgMngr, setDistroPkgMngr] = useState<string | null>(null)
const [installedPrograms, setInstalledPrograms] = useState<InstalledPrograms>({
winget: {
installed: false,
@@ -218,7 +218,10 @@ function App() {
const distroResult = await detectDistro();
if (distroResult) {
setDistroId(extractDistroId(distroResult));
setDistroBase(detectDistroBase(extractDistroId(distroResult)));
const distroPkgMngrResult = await detectPackageManager();
if (distroPkgMngrResult) {
setDistroPkgMngr(extractPkgMngrName(distroPkgMngrResult));
}
}
break;
@@ -243,7 +246,7 @@ function App() {
<Button className="ml-3" size="sm" onClick={checkAllPrograms}>Refresh</Button>
</div>
</div>
{ distroId && distroBase && distroBase === 'debian' ? /* Section for Debian */
{ distroId && distroPkgMngr && distroPkgMngr === 'apt' ? /* Section for Debian */
<div className="programstats mt-5 mx-3">
<div className="programitem flex items-center justify-between">
<p><b>Python:</b> {installedPrograms.python3.installed ? 'installed' : 'not installed'} {installedPrograms.python3.version ? `(${installedPrograms.python3.version})` : ''}</p>
@@ -285,7 +288,7 @@ function App() {
</Alert>
: null}
</div>
: distroId && distroBase && distroBase === 'rhel' ? /* Section for RHEL */
: distroId && distroPkgMngr && distroPkgMngr === 'dnf' ? /* Section for RHEL */
<div className="programstats mt-5 mx-3">
<div className="programitem flex items-center justify-between">
<p><b>Python:</b> {installedPrograms.python3.installed ? 'installed' : 'not installed'} {installedPrograms.python3.version ? `(${installedPrograms.python3.version})` : ''}</p>

View File

@@ -65,20 +65,27 @@ export async function detectDistro(): Promise<string | null> {
}
}
export function detectDistroBase(distro: string | null): string | null{
if(distro) {
if(['debian', 'ubuntu', 'pop', 'kali'].includes(distro)) {
return 'debian';
} else if (['rhel', 'fedora', 'centos', 'rocky'].includes(distro)) {
return 'rhel';
export async function detectPackageManager(): Promise<string | null> {
try{
const output = await new Command('detect-pkgmngr', ['-c', 'command -v apt || command -v dnf || command -v pacman']).execute();
if (output.code === 0) {
return output.stdout;
} else {
return 'other';
return output.stdout;
}
} else {
} catch (error) {
console.error(error);
return null;
}
}
export function extractPkgMngrName(path: string): string | null {
const pattern = /^\s*(.*\/)?([^\/\s]+)\s*$/;
const match = path.trim().match(pattern);
if (!match) return null;
return match[2];
}
export function extractDistroId(input: string): string | null {
const regex = /ID=([a-zA-Z]+)/;
const match = input.match(regex);