diff --git a/.gitignore b/.gitignore index 37c7eac..7c4d301 100644 --- a/.gitignore +++ b/.gitignore @@ -23,9 +23,11 @@ dist-ssr *.sln *.sw? -# Executables +# Executables and manifests pytubepp-helper-msghost.exe pytubepp-helper-autostart.exe +pytubepp-helper-msghost.json +pytubepp-helper-msghost-moz.json # Certificate files certificate.pfx diff --git a/copyFiles.js b/copyFiles.js index 1a01a1e..043235b 100644 --- a/copyFiles.js +++ b/copyFiles.js @@ -5,11 +5,17 @@ import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); -const msghostsrc = path.join(__dirname, 'src-tauri', 'target', 'release', 'pytubepp-helper-msghost.exe'); -const msghostdest = path.join(__dirname, 'src-tauri', 'pytubepp-helper-msghost.exe'); -const autostartsrc = path.join(__dirname, 'src-tauri', 'target', 'release', 'pytubepp-helper-autostart.exe'); -const autostartdest = path.join(__dirname, 'src-tauri', 'pytubepp-helper-autostart.exe'); +const msghostSrc = path.join(__dirname, 'src-tauri', 'target', 'release', 'pytubepp-helper-msghost.exe'); +const msghostDest = path.join(__dirname, 'src-tauri', 'pytubepp-helper-msghost.exe'); +const autostartSrc = path.join(__dirname, 'src-tauri', 'target', 'release', 'pytubepp-helper-autostart.exe'); +const autostartDest = path.join(__dirname, 'src-tauri', 'pytubepp-helper-autostart.exe'); +const msghostManifestWinChromeSrc = path.join(__dirname, 'src-tauri', 'msghost-manifest', 'windows', 'chrome', 'com.neosubhamoy.pytubepp.helper.json'); +const msghostManifestWinChromeDest = path.join(__dirname, 'src-tauri', 'pytubepp-helper-msghost.json'); +const msghostManifestWinFirefoxSrc = path.join(__dirname, 'src-tauri', 'msghost-manifest', 'windows', 'firefox', 'com.neosubhamoy.pytubepp.helper.json'); +const msghostManifestWinFirefoxDest = path.join(__dirname, 'src-tauri', 'pytubepp-helper-msghost-moz.json'); -fs.copyFileSync(msghostsrc, msghostdest); -fs.copyFileSync(autostartsrc, autostartdest); +fs.copyFileSync(msghostSrc, msghostDest); +fs.copyFileSync(autostartSrc, autostartDest); +fs.copyFileSync(msghostManifestWinChromeSrc, msghostManifestWinChromeDest); +fs.copyFileSync(msghostManifestWinFirefoxSrc, msghostManifestWinFirefoxDest); console.log('Files copied successfully'); \ No newline at end of file diff --git a/signFiles.js b/signFiles.js deleted file mode 100644 index 88d917e..0000000 --- a/signFiles.js +++ /dev/null @@ -1,59 +0,0 @@ -import { exec } from 'child_process'; -import { promisify } from 'util'; -import dotenv from 'dotenv'; -import path from 'path'; - -dotenv.config(); - -const execPromise = promisify(exec); - -// Common configuration -const config = { - pfxPath: 'certificate.pfx', - pfxPassword: process.env.PFX_PASS, - companyName: 'Subhamoy Biswas', - companyUrl: 'https://neosubhamoy.com', - timestampServer: 'http://timestamp.sectigo.com', -}; - -// Array of files to sign with their individual configurations -const filesToSign = [ - { - path: 'src-tauri/target/release/pytubepp-helper-msghost.exe', - programName: 'PytubePP Helper Native Messaging Host', - }, - { - path: 'src-tauri/target/release/pytubepp-helper-autostart.exe', - programName: 'PytubePP Helper (Autostart)', - }, - // Add more files as needed -]; - -const signFile = async (fileConfig) => { - const { path: filePath, programName } = fileConfig; - - const command = `signtool sign /f "${config.pfxPath}" /p ${config.pfxPassword} /d "${programName}" /du "${config.companyUrl}" /n "${config.companyName}" /t ${config.timestampServer} /fd sha256 "${filePath}"`; - - try { - const { stdout, stderr } = await execPromise(command); - console.log(`Successfully signed ${path.basename(filePath)}`); - console.log(stdout); - } catch (error) { - console.error(`Failed to sign ${path.basename(filePath)}`); - console.error(error.message); - } -}; - -const signAllFiles = async () => { - if (!config.pfxPassword) { - console.error('PFX password not found in environment variables.'); - return; - } - - for (const file of filesToSign) { - await signFile(file); - } - console.log('All files processed.'); -}; - -signAllFiles(); \ No newline at end of file diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index b3061bb..8ec8b86 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -2085,6 +2085,17 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "os_info" +version = "3.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae99c7fa6dd38c7cafe1ec085e804f8f555a2f8659b0dbe03f1f9963a9b51092" +dependencies = [ + "log 0.4.22", + "serde", + "windows-sys 0.52.0", +] + [[package]] name = "os_pipe" version = "1.2.1" @@ -3232,6 +3243,19 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sys-locale" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8a11bd9c338fdba09f7881ab41551932ad42e405f61d01e8406baea71c07aee" +dependencies = [ + "js-sys", + "libc", + "wasm-bindgen", + "web-sys", + "windows-sys 0.45.0", +] + [[package]] name = "system-deps" version = "5.0.0" @@ -3359,6 +3383,7 @@ dependencies = [ "objc", "once_cell", "open", + "os_info", "os_pipe", "percent-encoding 2.3.1", "rand 0.8.5", @@ -3371,6 +3396,7 @@ dependencies = [ "serialize-to-javascript", "shared_child", "state", + "sys-locale", "tar", "tauri-macros", "tauri-runtime", @@ -4148,6 +4174,16 @@ version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "webkit2gtk" version = "0.18.2" @@ -4390,6 +4426,15 @@ dependencies = [ "windows_x86_64_msvc 0.42.2", ] +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.2", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -4417,6 +4462,21 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + [[package]] name = "windows-targets" version = "0.48.5" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index e99061d..950f47d 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -11,7 +11,7 @@ edition = "2021" tauri-build = { version = "1", features = [] } [dependencies] -tauri = { version = "1", features = [ "process-relaunch", "window-start-dragging", "window-close", "window-unmaximize", "process-exit", "window-show", "window-unminimize", "window-hide", "window-minimize", "window-maximize", "system-tray", "shell-all"] } +tauri = { version = "1", features = [ "os-all", "process-relaunch", "window-start-dragging", "window-close", "window-unmaximize", "process-exit", "window-show", "window-unminimize", "window-hide", "window-minimize", "window-maximize", "system-tray", "shell-all"] } serde = { version = "1", features = ["derive"] } serde_json = "1" tokio = { version = "1.39.2", features = ["full"] } diff --git a/src-tauri/autostart/src/main.rs b/src-tauri/autostart/src/main.rs index 5a25c53..e60f5aa 100644 --- a/src-tauri/autostart/src/main.rs +++ b/src-tauri/autostart/src/main.rs @@ -29,8 +29,6 @@ fn connect_with_retry(url: &str, max_attempts: u32) -> Result Result<(), Box> { // Launch the main application - let _ = Command::new("pytubepp-helper.exe") - .spawn(); let _ = Command::new("pytubepp-helper") .spawn(); diff --git a/src-tauri/msghost-manifest/linux/chrome/com.neosubhamoy.pytubepp.helper.json b/src-tauri/msghost-manifest/linux/chrome/com.neosubhamoy.pytubepp.helper.json new file mode 100644 index 0000000..5e95e54 --- /dev/null +++ b/src-tauri/msghost-manifest/linux/chrome/com.neosubhamoy.pytubepp.helper.json @@ -0,0 +1,7 @@ +{ + "name": "com.neosubhamoy.pytubepp.helper", + "description": "A helper app for pytubepp-extension to communicate with pytubepp-cli", + "path": "/usr/bin/pytubepp-helper-msghost", + "type": "stdio", + "allowed_origins": ["chrome-extension://adebedkaedobamilbbobbajepnnkkfcg/", "chrome-extension://mmhhbpdhkogpcieblpdilflfoimajepp/", "chrome-extension://ebneapoekcjelholncnlpdohjbjabhbi/", "chrome-extension://cohjehldppmnbfogjdjpbjknhlhmfhjj/"] +} \ No newline at end of file diff --git a/src-tauri/msghost-manifest/linux/firefox/com.neosubhamoy.pytubepp.helper.json b/src-tauri/msghost-manifest/linux/firefox/com.neosubhamoy.pytubepp.helper.json new file mode 100644 index 0000000..a0b3808 --- /dev/null +++ b/src-tauri/msghost-manifest/linux/firefox/com.neosubhamoy.pytubepp.helper.json @@ -0,0 +1,7 @@ +{ + "name": "com.neosubhamoy.pytubepp.helper", + "description": "A helper app for pytubepp-extention to communicate with pytubepp-cli", + "path": "/usr/bin/pytubepp-helper-msghost", + "type": "stdio", + "allowed_extensions": ["pytubepp-addon@neosubhamoy.com"] +} \ No newline at end of file diff --git a/src-tauri/pytubepp-helper-msghost.json b/src-tauri/msghost-manifest/windows/chrome/com.neosubhamoy.pytubepp.helper.json similarity index 100% rename from src-tauri/pytubepp-helper-msghost.json rename to src-tauri/msghost-manifest/windows/chrome/com.neosubhamoy.pytubepp.helper.json diff --git a/src-tauri/pytubepp-helper-msghost-moz.json b/src-tauri/msghost-manifest/windows/firefox/com.neosubhamoy.pytubepp.helper.json similarity index 100% rename from src-tauri/pytubepp-helper-msghost-moz.json rename to src-tauri/msghost-manifest/windows/firefox/com.neosubhamoy.pytubepp.helper.json diff --git a/src-tauri/tauri.linux.conf.json b/src-tauri/tauri.linux.conf.json index 1a33491..62b3779 100644 --- a/src-tauri/tauri.linux.conf.json +++ b/src-tauri/tauri.linux.conf.json @@ -8,6 +8,9 @@ "tauri": { "allowlist": { "all": false, + "os": { + "all": true + }, "shell": { "all": true, "execute": true, @@ -127,9 +130,9 @@ "deb": { "depends": ["python3-pip", "ffmpeg"], "files": { - "/etc/opt/chrome/native-messaging-hosts/com.neosubhamoy.pytubepp.helper.json": "./pytubepp-helper-msghost.json", - "/etc/chromium/native-messaging-hosts/com.neosubhamoy.pytubepp.helper.json": "./pytubepp-helper-msghost.json", - "/usr/lib/mozilla/native-messaging-hosts/com.neosubhamoy.pytubepp.helper.json": "./pytubepp-helper-msghost-moz.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", + "/usr/lib/mozilla/native-messaging-hosts/com.neosubhamoy.pytubepp.helper.json": "./msghost-manifest/linux/firefox/com.neosubhamoy.pytubepp.helper.json", "/usr/bin/pytubepp-helper-msghost": "./target/release/pytubepp-helper-msghost", "/usr/bin/pytubepp-helper-autostart": "./target/release/pytubepp-helper-autostart", "/etc/xdg/autostart/pytubepp-helper-autostart.desktop": "./autostart/pytubepp-helper-autostart.desktop" @@ -141,9 +144,9 @@ "license": "MIT", "depends": ["python3-pip", "ffmpeg-free"], "files": { - "/etc/opt/chrome/native-messaging-hosts/com.neosubhamoy.pytubepp.helper.json": "./pytubepp-helper-msghost.json", - "/etc/chromium/native-messaging-hosts/com.neosubhamoy.pytubepp.helper.json": "./pytubepp-helper-msghost.json", - "/usr/lib/mozilla/native-messaging-hosts/com.neosubhamoy.pytubepp.helper.json": "./pytubepp-helper-msghost-moz.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", + "/usr/lib/mozilla/native-messaging-hosts/com.neosubhamoy.pytubepp.helper.json": "./msghost-manifest/linux/firefox/com.neosubhamoy.pytubepp.helper.json", "/usr/bin/pytubepp-helper-msghost": "./target/release/pytubepp-helper-msghost", "/usr/bin/pytubepp-helper-autostart": "./target/release/pytubepp-helper-autostart", "/etc/xdg/autostart/pytubepp-helper-autostart.desktop": "./autostart/pytubepp-helper-autostart.desktop" diff --git a/src-tauri/tauri.macos.conf.json b/src-tauri/tauri.macos.conf.json index 440e0e3..e338da9 100644 --- a/src-tauri/tauri.macos.conf.json +++ b/src-tauri/tauri.macos.conf.json @@ -8,6 +8,9 @@ "tauri": { "allowlist": { "all": false, + "os": { + "all": true + }, "shell": { "all": true, "execute": true, diff --git a/src-tauri/tauri.windows.conf.json b/src-tauri/tauri.windows.conf.json index 626e371..aed4302 100644 --- a/src-tauri/tauri.windows.conf.json +++ b/src-tauri/tauri.windows.conf.json @@ -8,6 +8,9 @@ "tauri": { "allowlist": { "all": false, + "os": { + "all": true + }, "shell": { "all": true, "execute": true, diff --git a/src/App.tsx b/src/App.tsx index 21077f8..3e1389d 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -4,6 +4,7 @@ import "./index.css"; import { invoke } from "@tauri-apps/api/tauri"; import { listen } from '@tauri-apps/api/event'; import { appWindow } from '@tauri-apps/api/window'; +import { platform } from '@tauri-apps/api/os'; import { ThemeProvider } from "@/components/theme-provider"; import { Button } from "@/components/ui/button"; import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert" @@ -193,26 +194,40 @@ function App() { useEffect(() => { checkAllPrograms(); - detectWindows().then((result) => { - if(result) { - setIsWindows(true); - setWindowsVersion(extractVersion(result)); + const runPlatformSpecificChecks = async () => { + const currentPlatform = await platform(); + + switch (currentPlatform) { + case 'win32': + const windowsResult = await detectWindows(); + if (windowsResult) { + setIsWindows(true); + setWindowsVersion(extractVersion(windowsResult)); + } + break; + + case 'darwin': + const macResult = await detectMacOs(); + if (macResult) { + setIsMacOs(true); + setMacOsVersion(extractVersion(macResult)); + } + break; + + case 'linux': + const distroResult = await detectDistro(); + if (distroResult) { + setDistroId(extractDistroId(distroResult)); + setDistroBase(detectDistroBase(extractDistroId(distroResult))); + } + break; + + default: + console.log('Unsupported platform'); } - }) - detectMacOs().then((result) => { - if(result) { - setIsMacOs(true); - setMacOsVersion(extractVersion(result)); - } - }) - detectDistro().then((result) => { - if(result) { - setDistroId(extractDistroId(result)) - setDistroBase(detectDistroBase(extractDistroId(result))) - } - }) - } - , []); + }; + runPlatformSpecificChecks().catch(console.error); + }, []) return ( diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 1f164dc..5790f4b 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -85,18 +85,17 @@ export function extractDistroId(input: string): string | null { export function extractVersion(output: string): string | null { const versionPatterns = [ - /ffmpeg version (\d+\.\d+)/, // Pattern for ffmpeg - /Python (\d+\.\d+\.\d+)/, // Pattern for Python - /pytubefix (\d+\.\d+\.\d+)/, // Pattern for pytubefix - /pytubepp (\d+\.\d+\.\d+)/, // Pattern for pytubepp - /v(\d+\.\d+\.\d+)/, // Pattern for winget - /pip (\d+\.\d+)/, // Pattern for pip - /OS Version:.*Build (\d+)/, // Pattern for Windows build - /apt (\d+\.\d+\.\d+)/, // Pattern for apt - /(\d+\.\d+\.\d+)/, // Pattern for dnf - /ProductVersion:\s+(\d+\.\d+\.\d+)/, // Pattern for macOS version - /Homebrew (\d+\.\d+\.\d+)/, // Pattern for Homebrew - + /ffmpeg version (\d+\.\d+)/, // Pattern for ffmpeg + /Python (\d+\.\d+\.\d+)/, // Pattern for Python + /pytubefix (\d+\.\d+\.\d+)/, // Pattern for pytubefix + /pytubepp (\d+\.\d+\.\d+)/, // Pattern for pytubepp + /v(\d+\.\d+\.\d+)/, // Pattern for winget + /pip (\d+\.\d+)/, // Pattern for pip + /OS Version:.*Build (\d+)/, // Pattern for Windows build + /apt (\d+\.\d+\.\d+)/, // Pattern for apt + /(\d+\.\d+\.\d+)/, // Pattern for dnf + /ProductVersion:\s+(\d+\.\d+(\.\d+)?)/, // Pattern for macOS version + /Homebrew (\d+\.\d+\.\d+)/, // Pattern for Homebrew ]; for (const pattern of versionPatterns) { const match = output.match(pattern);