|
#!/bin/sh |
|
#/* |
|
# Electron Framework Version Detector |
|
# - macOS: uses mdfind + strings on Electron Framework or main binary |
|
# - Linux: scans standard, Flatpak, and AppImage locations |
|
# - Windows: PowerShell scans .exe files for embedded Electron version |
|
# */ |
|
|
|
# === COLOR SETUP (Shell) === |
|
if [ -t 1 ]; then |
|
GREEN='\033[0;32m' |
|
RED='\033[0;31m' |
|
BLUE='\033[0;34m' |
|
NC='\033[0m' |
|
else |
|
GREEN=''; RED=''; BLUE=''; NC='' |
|
fi |
|
|
|
# === EXTRACT ELECTRON VERSION FROM BINARY (Shell) === |
|
extract_version() { |
|
strings "$1" 2>/dev/null | grep -i "Chrome/" | grep -i "Electron/" | head -n1 | sed -E 's/.*Electron\/([0-9]+\.[0-9]+\.[0-9]+).*/\1/' |
|
} |
|
|
|
# === SHELL MODE: macOS / Linux === |
|
if [ -z "$RUNNING_IN_POWERSHELL" ]; then |
|
case $(uname -s 2>/dev/null) in |
|
Darwin) |
|
echo "${BLUE}Scanning for Electron apps (macOS)...${NC}" |
|
mdfind "kMDItemContentType == 'com.apple.application-bundle'" 2>/dev/null | while read -r app; do |
|
if [ -d "$app" ]; then |
|
BUNDLE_EXECUTABLE=$(defaults read "$app/Contents/Info.plist" CFBundleExecutable 2>/dev/null) |
|
MAIN_BIN="$app/Contents/MacOS/$BUNDLE_EXECUTABLE" |
|
FRAMEWORK_BIN="$app/Contents/Frameworks/Electron Framework.framework/Electron Framework" |
|
|
|
for bin in "$FRAMEWORK_BIN" "$MAIN_BIN"; do |
|
if [ -f "$bin" ]; then |
|
ver=$(extract_version "$bin") |
|
if [ -n "$ver" ]; then |
|
app_name=$(basename "$app") |
|
loc=$( [ "$bin" = "$MAIN_BIN" ] && echo "main executable" || echo "Electron Framework") |
|
echo "${GREEN}$app_name${NC}: Electron ${GREEN}$ver${NC} ($loc)" |
|
break |
|
fi |
|
fi |
|
done |
|
fi |
|
done |
|
;; |
|
Linux) |
|
echo "${BLUE}Scanning for Electron apps (Linux)...${NC}" |
|
|
|
# Standard system & user locations |
|
STANDARD_DIRS="/usr/share /usr/lib /opt $HOME/.local $HOME/.config" |
|
|
|
# Flatpak (user + system) |
|
FLATPAK_DIRS="$HOME/.local/share/flatpak/app /var/lib/flatpak/app" |
|
|
|
# Common AppImage locations |
|
APPIMAGE_DIRS="$HOME/Applications $HOME/bin" |
|
|
|
ALL_DIRS="$STANDARD_DIRS $FLATPAK_DIRS $APPIMAGE_DIRS" |
|
|
|
for dir in $ALL_DIRS; do |
|
if [ -d "$dir" ]; then |
|
find "$dir" -type f -executable 2>/dev/null | while read -r bin; do |
|
# Skip known non-app paths |
|
case "$bin" in |
|
*/bin/sh|*/bin/bash|*/bin/zsh|*/bin/dash|*/bin/python*|*/lib/*|*/share/*|*/node_modules/*|*/cache/*|*/\.cache/*) |
|
continue |
|
;; |
|
esac |
|
|
|
# Skip files smaller than 1MB (unlikely to be Electron app) |
|
size=$(stat -c%s "$bin" 2>/dev/null) |
|
if [ -z "$size" ] || [ "$size" -lt 1048576 ]; then |
|
continue |
|
fi |
|
|
|
ver=$(extract_version "$bin") |
|
if [ -n "$ver" ]; then |
|
# Determine app name |
|
if echo "$bin" | grep -q "/flatpak/app/"; then |
|
app_id=$(echo "$bin" | sed -E 's|.*/flatpak/app/([^/]+).*|\1|') |
|
app_name=$(echo "$app_id" | sed 's/\./ /g' | awk '{print $NF}') |
|
elif echo "$bin" | grep -q "\.AppImage$"; then |
|
app_name=$(basename "$bin" .AppImage) |
|
else |
|
parent=$(basename "$(dirname "$bin")") |
|
if [ "$parent" = "bin" ]; then |
|
app_name=$(basename "$(dirname "$(dirname "$bin")")") |
|
else |
|
app_name="$parent" |
|
fi |
|
# Fallback |
|
if [ "$app_name" = "." ] || [ "$app_name" = "bin" ] || [ "$app_name" = "lib" ]; then |
|
app_name=$(basename "$bin") |
|
fi |
|
fi |
|
|
|
echo "${GREEN}$app_name${NC}: Electron ${GREEN}$ver${NC} (binary: $(basename "$bin"))" |
|
fi |
|
done |
|
fi |
|
done |
|
;; |
|
*) |
|
echo "${RED}Unsupported OS${NC}" |
|
;; |
|
esac |
|
exit 0 |
|
fi |
|
|
|
#><# End of shell — PowerShell starts below |
|
# === POWERSHELL MODE (Windows) === |
|
$Host.UI.RawUI.ForegroundColor = "Blue" |
|
Write-Host "Scanning for Electron apps (Windows)..." |
|
$Host.UI.RawUI.ForegroundColor = "Gray" |
|
|
|
function Extract-Version($Path) { |
|
try { |
|
$bytes = [System.IO.File]::ReadAllBytes($Path) |
|
$str = [System.Text.Encoding]::UTF8.GetString($bytes) |
|
if ($str -match 'Chrome/[^"]*Electron/(\d+\.\d+\.\d+)') { |
|
return $matches[1] |
|
} |
|
} catch { } |
|
return $null |
|
} |
|
|
|
$AppDirs = @("${env:ProgramFiles}", "${env:ProgramFiles(x86)}", "${env:LOCALAPPDATA}") |
|
|
|
foreach ($dir in $AppDirs) { |
|
if (-not (Test-Path $dir)) { continue } |
|
Get-ChildItem -Path $dir -Recurse -Filter "*.exe" -File -ErrorAction SilentlyContinue | ForEach-Object { |
|
$ver = Extract-Version $_.FullName |
|
if ($ver) { |
|
$appName = $_.Directory.Name |
|
Write-Host "$appName" -ForegroundColor Green -NoNewline |
|
Write-Host ": Electron " -NoNewline |
|
Write-Host $ver -ForegroundColor Green -NoNewline |
|
Write-Host " (binary: $($_.Name))" |
|
} |
|
} |
|
} |
|
|
|
Write-Host "Scan complete." -ForegroundColor Blue |