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:
@@ -32,6 +32,11 @@
|
|||||||
"cmd": "grep",
|
"cmd": "grep",
|
||||||
"args": ["^ID=", "/etc/os-release"]
|
"args": ["^ID=", "/etc/os-release"]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "detect-pkgmngr",
|
||||||
|
"cmd": "sh",
|
||||||
|
"args": ["-c", "command -v apt || command -v dnf || command -v pacman"]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "is-apt-installed",
|
"name": "is-apt-installed",
|
||||||
"cmd": "apt",
|
"cmd": "apt",
|
||||||
@@ -128,7 +133,7 @@
|
|||||||
"icons/icon.ico"
|
"icons/icon.ico"
|
||||||
],
|
],
|
||||||
"deb": {
|
"deb": {
|
||||||
"depends": ["python3-pip", "ffmpeg"],
|
"depends": ["python3-pip", "ffmpeg", "gnome-terminal"],
|
||||||
"files": {
|
"files": {
|
||||||
"/etc/opt/chrome/native-messaging-hosts/com.neosubhamoy.pytubepp.helper.json": "./msghost-manifest/linux/chrome/com.neosubhamoy.pytubepp.helper.json",
|
"/etc/opt/chrome/native-messaging-hosts/com.neosubhamoy.pytubepp.helper.json": "./msghost-manifest/linux/chrome/com.neosubhamoy.pytubepp.helper.json",
|
||||||
"/etc/chromium/native-messaging-hosts/com.neosubhamoy.pytubepp.helper.json": "./msghost-manifest/linux/chrome/com.neosubhamoy.pytubepp.helper.json",
|
"/etc/chromium/native-messaging-hosts/com.neosubhamoy.pytubepp.helper.json": "./msghost-manifest/linux/chrome/com.neosubhamoy.pytubepp.helper.json",
|
||||||
@@ -141,7 +146,7 @@
|
|||||||
"epoch": 0,
|
"epoch": 0,
|
||||||
"release": "1",
|
"release": "1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"depends": ["python3-pip", "ffmpeg-free"],
|
"depends": ["python3-pip", "ffmpeg-free", "gnome-terminal"],
|
||||||
"files": {
|
"files": {
|
||||||
"/etc/opt/chrome/native-messaging-hosts/com.neosubhamoy.pytubepp.helper.json": "./msghost-manifest/linux/chrome/com.neosubhamoy.pytubepp.helper.json",
|
"/etc/opt/chrome/native-messaging-hosts/com.neosubhamoy.pytubepp.helper.json": "./msghost-manifest/linux/chrome/com.neosubhamoy.pytubepp.helper.json",
|
||||||
"/etc/chromium/native-messaging-hosts/com.neosubhamoy.pytubepp.helper.json": "./msghost-manifest/linux/chrome/com.neosubhamoy.pytubepp.helper.json",
|
"/etc/chromium/native-messaging-hosts/com.neosubhamoy.pytubepp.helper.json": "./msghost-manifest/linux/chrome/com.neosubhamoy.pytubepp.helper.json",
|
||||||
|
|||||||
@@ -32,6 +32,11 @@
|
|||||||
"cmd": "grep",
|
"cmd": "grep",
|
||||||
"args": ["^ID=", "/etc/os-release"]
|
"args": ["^ID=", "/etc/os-release"]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "detect-pkgmngr",
|
||||||
|
"cmd": "sh",
|
||||||
|
"args": ["-c", "command -v apt || command -v dnf || command -v pacman"]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "is-apt-installed",
|
"name": "is-apt-installed",
|
||||||
"cmd": "apt",
|
"cmd": "apt",
|
||||||
|
|||||||
@@ -32,6 +32,11 @@
|
|||||||
"cmd": "grep",
|
"cmd": "grep",
|
||||||
"args": ["^ID=", "/etc/os-release"]
|
"args": ["^ID=", "/etc/os-release"]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "detect-pkgmngr",
|
||||||
|
"cmd": "sh",
|
||||||
|
"args": ["-c", "command -v apt || command -v dnf || command -v pacman"]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "is-apt-installed",
|
"name": "is-apt-installed",
|
||||||
"cmd": "apt",
|
"cmd": "apt",
|
||||||
|
|||||||
13
src/App.tsx
13
src/App.tsx
@@ -9,7 +9,7 @@ import { ThemeProvider } from "@/components/theme-provider";
|
|||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
|
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
|
||||||
import { InstalledPrograms, WebSocketMessage, } from "./types";
|
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';
|
import { CircleCheck, TriangleAlert, CircleAlert } from 'lucide-react';
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
@@ -27,7 +27,7 @@ function App() {
|
|||||||
const [isMacOs, setIsMacOs] = useState<boolean>(false)
|
const [isMacOs, setIsMacOs] = useState<boolean>(false)
|
||||||
const [macOsVersion, setMacOsVersion] = useState<string | null>(null)
|
const [macOsVersion, setMacOsVersion] = useState<string | null>(null)
|
||||||
const [distroId, setDistroId] = 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>({
|
const [installedPrograms, setInstalledPrograms] = useState<InstalledPrograms>({
|
||||||
winget: {
|
winget: {
|
||||||
installed: false,
|
installed: false,
|
||||||
@@ -218,7 +218,10 @@ function App() {
|
|||||||
const distroResult = await detectDistro();
|
const distroResult = await detectDistro();
|
||||||
if (distroResult) {
|
if (distroResult) {
|
||||||
setDistroId(extractDistroId(distroResult));
|
setDistroId(extractDistroId(distroResult));
|
||||||
setDistroBase(detectDistroBase(extractDistroId(distroResult)));
|
const distroPkgMngrResult = await detectPackageManager();
|
||||||
|
if (distroPkgMngrResult) {
|
||||||
|
setDistroPkgMngr(extractPkgMngrName(distroPkgMngrResult));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -243,7 +246,7 @@ function App() {
|
|||||||
<Button className="ml-3" size="sm" onClick={checkAllPrograms}>Refresh</Button>
|
<Button className="ml-3" size="sm" onClick={checkAllPrograms}>Refresh</Button>
|
||||||
</div>
|
</div>
|
||||||
</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="programstats mt-5 mx-3">
|
||||||
<div className="programitem flex items-center justify-between">
|
<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>
|
<p><b>Python:</b> {installedPrograms.python3.installed ? 'installed' : 'not installed'} {installedPrograms.python3.version ? `(${installedPrograms.python3.version})` : ''}</p>
|
||||||
@@ -285,7 +288,7 @@ function App() {
|
|||||||
</Alert>
|
</Alert>
|
||||||
: null}
|
: null}
|
||||||
</div>
|
</div>
|
||||||
: distroId && distroBase && distroBase === 'rhel' ? /* Section for RHEL */
|
: distroId && distroPkgMngr && distroPkgMngr === 'dnf' ? /* Section for RHEL */
|
||||||
<div className="programstats mt-5 mx-3">
|
<div className="programstats mt-5 mx-3">
|
||||||
<div className="programitem flex items-center justify-between">
|
<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>
|
<p><b>Python:</b> {installedPrograms.python3.installed ? 'installed' : 'not installed'} {installedPrograms.python3.version ? `(${installedPrograms.python3.version})` : ''}</p>
|
||||||
|
|||||||
@@ -65,20 +65,27 @@ export async function detectDistro(): Promise<string | null> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function detectDistroBase(distro: string | null): string | null{
|
export async function detectPackageManager(): Promise<string | null> {
|
||||||
if(distro) {
|
try{
|
||||||
if(['debian', 'ubuntu', 'pop', 'kali'].includes(distro)) {
|
const output = await new Command('detect-pkgmngr', ['-c', 'command -v apt || command -v dnf || command -v pacman']).execute();
|
||||||
return 'debian';
|
if (output.code === 0) {
|
||||||
} else if (['rhel', 'fedora', 'centos', 'rocky'].includes(distro)) {
|
return output.stdout;
|
||||||
return 'rhel';
|
|
||||||
} else {
|
} else {
|
||||||
return 'other';
|
return output.stdout;
|
||||||
}
|
}
|
||||||
} else {
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
return null;
|
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 {
|
export function extractDistroId(input: string): string | null {
|
||||||
const regex = /ID=([a-zA-Z]+)/;
|
const regex = /ID=([a-zA-Z]+)/;
|
||||||
const match = input.match(regex);
|
const match = input.match(regex);
|
||||||
|
|||||||
Reference in New Issue
Block a user